IntermediateRepresentation
public protocol IntermediateRepresentation : AnyObject
An IntermediateRepresentation
is responsible for building this structure, typically some kind of Abstract Syntax Tree (AST).
There are some other examples of this such as DebuggingDelegate
or ForkedIR
. It does this by observing the state changes in the
matcher (such as start and end of evaluation of a rule). See below for standard implementations of this protocol that you can use.
See also
HomogenousAST
, HeterogeneousAST
, DebuggingIR
, ForwardingIR
-
Undocumented
Declaration
Swift
init()
-
Called when the parser is about to evaluate a structural rule. This is an oppertunity to prepare any appropriate data structures.
Declaration
Swift
func evaluating(_ token: TokenType)
Parameters
token
The token that will be created if the rule is matched
-
Called after the
TokenType
has been successfully matched (or an ignorable failure for a pinned token)Declaration
Swift
func succeeded(token: TokenType, annotations: RuleAnnotations, range: Range<String.Index>)
Parameters
token
The
TokenType
that has been evaluatedannotations
Any annotations required for the resultant node
range
The range of the match
-
Called when a token being evaluated failed to be matched
Declaration
Swift
func failed()
-
Called when the parser starts evaluation providing an oppertunity for the AST to prepare it’s internal state.
Declaration
Swift
func willBuildFrom(source: String, with: Grammar)
-
Called when parsing of the source is complete.
Declaration
Swift
func didBuild()
-
Called if the state of parsing should be completely reset
Declaration
Swift
func resetState()