RecursiveRule
public final class RecursiveRule : Rule, CustomStringConvertible
When a rule definition calls itself whilst evaluating itself (left hand recursion) you cannot create the rule directly as it will become caught in an infinite look (creating instances of itself, which create instances of itself etc until the stack is empty). To avoid this a rule can use this wrapper to manage lazy initialization of itself. The recursive rule enables a reference to be added on the RHS, but the actual rule will not be initiialized until later, and this wrapper will then call that lazily initalized rule.
-
Creates a new instance of a rule. If you use this initializer then you should subsequently (when possible) set
surrogateRule
Declaration
Swift
public init(stubFor behaviour: Behaviour, with annotations: RuleAnnotations)
Parameters
token
The token the rule will create.
-
The rule, which can be assigned at any point before actual parsing, to be used. When a new value is assigned to the rule a new instance is created (calling “instance(token, annotations)) with the token and annotations assigned at construction
Declaration
Swift
public var surrogateRule: Rule? { get set }
-
Declaration
Swift
public var description: String { get }
-
An abreviated description of the rule
Declaration
Swift
public var shortDescription: String { get }
-
Delegated to the the surrogate rule
Declaration
Swift
public func test(with lexer: LexicalAnalyzer, for ir: IntermediateRepresentation) throws
-
Declaration
Swift
public func match(with lexer: LexicalAnalyzer, for ir: IntermediateRepresentation) throws
-
Delegated to the the surrogate rule
Declaration
Swift
public var behaviour: Behaviour { get }
-
Delegated to the the surrogate rule
Declaration
Swift
public var annotations: RuleAnnotations { get }
-
Creates a new instance of itself
Declaration
Swift
public func rule(with behaviour: Behaviour?, annotations: RuleAnnotations?) -> Rule