Protocols

The following protocols are available globally.

  • This protocol identifies as set of additional requirements for Nodes in order for them to be used for decoding. Some elements of the implementation are provided through an extension.

    See more

    Declaration

    Swift

    public protocol DecodeableAbstractSyntaxTree : AbstractSyntaxTree
  • An error type that captures not just a current error, but the hierarchy of errors that caused it.

    See more

    Declaration

    Swift

    public protocol CausalErrorType : CustomDebugStringConvertible, CustomStringConvertible, Error
  • The job of an implementation of this protocol is two fold

    • Manage the state of the Scanner to provide n lookahead capability to the surrounding rules
    • To provide a layer of abstraction between consumers of scanning behaviour and the scanner itself. This allows the scanner to be as simple as possible

    It used heavily during Rule evaluation. Typically a rule will start by mark()ing it’s possition (remembering the positiong of the Scanner at the start of rule evaluation. During Rule evaluation rules will result (eventually) in calls to the various scan methods which will advance the Scanner. Finally, the rule will either be satisfied and proceed()->LexicalContext will be called, or fail and rewind() will be called returning the Scanner to its state before mark() was called.

    See more

    Declaration

    Swift

    public protocol LexicalAnalyzer : AnyObject
  • A lexical context summarises the of a String being scanned by a LexicalAnalyzer between two marks. It is generated when the LexicalAnalyzer is advanced confirming that the last rule was essentially matched.

    See more

    Declaration

    Swift

    public protocol LexicalContext
  • A language stores a set of grammar rules that can be used to parse Strings. Extensions provide additional methods (such as parsing) that operate on these rules.

    See more

    Declaration

    Swift

    public protocol Grammar
  • Abstract Syntax Trees are responsible to for taking an IntermediateRepresentation and building a data structure suitable for semantic analysis

    See more

    Declaration

    Swift

    public protocol AbstractSyntaxTree
  • Nodes are the basic elements of IntermediateRepresentations. They record a TokenType, the range of the String‘s UnicodeScalarView the match occured in as well as any annotations that were made on the token.

    See more

    Declaration

    Swift

    public protocol Node : CustomStringConvertible
  • 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
    See more

    Declaration

    Swift

    public protocol IntermediateRepresentation : AnyObject
  • TokenTypes are generated when rules are matched (usually, sometime a rule just advances the scan-head). Tokens with a rawValue of -1 are considered transient, meaning that they should not be included in any construction of an AST. However, they may provide context to the AST.

    See more

    Declaration

    Swift

    public protocol TokenType
  • Behavioural rule is both an extension to and ultimately a replacement for current Rule. It bakes in the logic for repeating, negation, lookahead, as well as transient and void rules both flattening the evaluation hierarchy and making it easier to extend (previously implementations would have to add any of this logic themselves, and it’s easy to get wrong.

    See more

    Declaration

    Swift

    public protocol Rule : CustomStringConvertible