AbstractSyntaxTreeConstructor

public class AbstractSyntaxTreeConstructor

AbstractSyntaxTreeConstructor is an IntermediateRepresentation responsible for briding between the parsing results and an AbstractSyntaxTree. It encapsulates a parsing strategy that creates it’s own lightweight homogenous representation of the parsed data. It can build into any AbstractSyntaxTree, utilizing the HomogenousTree by default. In addition it can parse into a heterogenous abstract syntax tree represented by any Swift Type by utlizing the Swift Decoder framework to decode the intermediate representation into a decodable container structure.

  • Errors that can occur during AST creation

    Declaration

    Swift

    @available(*, deprecated, message: "Use ProcessingError instead")
    public typealias ConstructionError = ProcessingError
  • An entry in the tree.

    See more

    Declaration

    Swift

    public struct IntermediateRepresentationNode : Node
  • The errors generated during parsing

    Declaration

    Swift

    public var errors: [Error] { get }
  • Creates a new instance, preparing to parse the supplied source

    Declaration

    Swift

    public required init()
  • Used for testing, creates a new blank instance for manipulation

    Declaration

    Swift

    public init(with source: String)
  • Constructs a heterogenous AST by first constructing the specified DecodableAbstractSyntaxTree (meeting the requirements of the ParsingDecoder class). You typically do not need to use this method (where you are specifying your own AST to use) and you should consider build<T:Decodable>(_ heterogenousType:T.Type, from source: String, using language: Grammar) which will create a HomegenousTree which is very easy to use to decode into a concrete type.

    Declaration

    Swift

    public func build<T, AST>(_ heterogenousType: T.Type, using astType: AST.Type, from source: String, using language: Grammar) throws -> T where T : Decodable, AST : DecodeableAbstractSyntaxTree

    Parameters

    heterogenousType

    The Decodable Swift Type being constructed

    using

    The language to use to parse the source

    from

    The text to parse and build the tree from

    using

    The language to use to parse the source

    Return Value

    An instance of a decodable type

  • Creates a new empty cache. By default a cache is not used, but this can speed up processing of nodes where there can be a series of failures of evaluating a previous set of tokens before failing.

    Declaration

    Swift

    public func initializeCache(depth: Int, breadth: Int)
  • Constructs a heterogenous AST by first constructing a HomogenousAbstractSyntaxTree which is then passed to the ParsingDecoder to leverage Swift’s Decoder framework to create the heterogenous AST.

    Declaration

    Swift

    public func build<T>(_ heterogenousType: T.Type, from source: String, using language: Grammar) throws -> T where T : Decodable

    Parameters

    heterogenousType

    The Decodable Swift Type being constructed

    from

    The text to parse and build the tree from

    using

    The language to use to parse the source

    Return Value

    An instance of a decodable type

  • Constructs a homogenous AST from the supplied source and language. You typically do not need to use this method (where you are specifying your own AST to use) and you should consider build(from source: String, using language: Grammar) which creates a HomegenousTree which is very easy to work with.

    Declaration

    Swift

    public func build<AST>(_ astType: AST.Type, from source: String, using language: Grammar) throws -> AST where AST : AbstractSyntaxTree

    Parameters

    using

    The language to use to parse the source

    from

    The text to parse and build the tree from

    using

    The language to use to parse the source

    Return Value

    The AbstractSyntaxTree

  • Constructs a homogenous AST from the supplied source and language.

    Declaration

    Swift

    public func build(_ source: String, using language: Grammar) throws -> HomogenousTree

    Parameters

    from

    The text to parse and build the tree from

    language

    The language to use to parse the source

    Return Value

    A HomogenousAbstractSyntaxTree

  • Constructs a homogenous AST from the supplied language.

    Declaration

    Swift

    public func build(using language: Grammar) throws -> HomogenousTree

    Parameters

    language

    The language to use to parse the source

    Return Value

    A HomogenousAbstractSyntaxTree