Protocols
The following protocols are available globally.
-
This protocol identifies as set of additional requirements for
See moreNode
s in order for them to be used for decoding. Some elements of the implementation are provided through an extension.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 moreDeclaration
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
See moreRule
evaluation. Typically a rule will start bymark()
ing it’s possition (remembering the positiong of theScanner
at the start of rule evaluation. DuringRule
evaluation rules will result (eventually) in calls to the variousscan
methods which will advance the Scanner. Finally, the rule will either be satisfied andproceed()->LexicalContext
will be called, or fail andrewind()
will be called returning theScanner
to its state beforemark()
was called.Declaration
Swift
public protocol LexicalAnalyzer : AnyObject
- Manage the state of the
-
A lexical context summarises the of a
See moreString
being scanned by aLexicalAnalyzer
between two marks. It is generated when theLexicalAnalyzer
is advanced confirming that the last rule was essentially matched.Declaration
Swift
public protocol LexicalContext
-
A language stores a set of grammar rules that can be used to parse
See moreString
s. Extensions provide additional methods (such as parsing) that operate on these rules.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 moreDeclaration
Swift
public protocol AbstractSyntaxTree
-
Nodes are the basic elements of
See moreIntermediateRepresentation
s. They record aTokenType
, the range of theString
‘sUnicodeScalarView
the match occured in as well as any annotations that were made on the token.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 asDebuggingDelegate
orForkedIR
. 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
Declaration
Swift
public protocol IntermediateRepresentation : AnyObject
-
See moreTokenType
s are generated when rules are matched (usually, sometime a rule just advances the scan-head). Tokens with arawValue
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.Declaration
Swift
public protocol TokenType
-
Behavioural rule is both an extension to and ultimately a replacement for current
See moreRule
. 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.Declaration
Swift
public protocol Rule : CustomStringConvertible