HomogenousTree
public struct HomogenousTree : AbstractSyntaxTree, CustomStringConvertible
HomogenousTree is used as the default form of AbstractSyntaxTree. Each node in the tree captures its TokenType
, the String
it mtached, and any children.
-
Creates a new instance using the supplied intermediate representation and source
Declaration
Swift
public init(with node: AbstractSyntaxTreeConstructor.IntermediateRepresentationNode, from source: String) throws
-
Creates a new instance of the node using the supplied parameters. You do not normally need to call this as nodes will be created by an
AbstractSyntaxTreeConstructor
. However if you wish to manually alter a generated tree creating nodes via this method may be appropriate.Declaration
Swift
public init(with token:TokenType, matching:String, children:[HomogenousTree], annotations:[RuleAnnotation:RuleAnnotationValue] = [:])
Parameters
token
The
TokenType
for the nodematchedString
The string that was matched
children
The child nodes
annotations
The annotations on the node
-
The captured
Token
Declaration
Swift
public let token: TokenType
-
The
String
that was matched to satisfy the rules for thetoken
.Declaration
Swift
public let matchedString: String
-
Any sub-nodes in the tree
Declaration
Swift
public let children: [HomogenousTree]
-
Any associated annotations made on the node
Declaration
Swift
public let annotations: [RuleAnnotation : RuleAnnotationValue]
-
Access a child based on the name of the token of the child
Declaration
Swift
public subscript(tokenName: String) -> HomogenousTree? { get }
-
Access a child based on the index of the child
Declaration
Swift
public subscript(index: Int) -> HomogenousTree { get }
-
A well formatted description of this branch of the tree
Declaration
Swift
public var description: String { get }
-
The string that was captured by this node
Declaration
Swift
public var stringValue: String { get }
-
The
CodingKey
for this node. This is normally generated using the name of the token.Declaration
Swift
public var key: CodingKey { get }
-
The children of this node
Declaration
Swift
public var contents: [DecodeableAbstractSyntaxTree] { get }