Classes
The following classes are available globally.
-
Abstracts the input source which is being parsed, and presents itself as a random access vector of characters of type
See moreChar
.Declaration
Swift
open class Input<Char>
-
A
Grammar
describes the syntax of the language to be parsed. Parsing is based on the concept of parameterized local lexing.A
Grammar
consists of a list of rules, a lexer, a selector, and a specification of how to construct the result of a successful parse.- The
Rule
s basically describe a context-free grammar whose nonterminals and terminals are parameterized by an input and an output parameter, each of typeGrammar.Param
. The computation of these parameters is guided via evaluation functions of typeEvalFunc
. Note that although context-free grammars require the symbol on the left hand side of a rule to be a nonterminal, here we also allow it to be a terminal instead. This enables a form of scannerless parsing. - The
Lexer
component makes it possible to associate a terminal with a custom parser. Note that the syntax of terminals can not only be described via this lexer, but can also be described via rules. - The
Selector
component makes it possible to resolve undesired ambiguities arising between terminals starting at the same position, while also allowing to keep desired or unproblematic ambiguities. - The
ConstructResult
component is a specification of how to construct theGrammar.Result
of a successful parse.
Given a list of
rules
, alexer
, aselector
and result construction specificationconstructResult
, you create agrammar
vialet grammar = Grammar(rules: rules, lexer: lexer, selector: selector, constructResult: constructResult)
You can then use it for parsing:
let parseResult = grammar.parse(input: input, position: 0, symbol: S, inputParam: param)
Here we parse the symbol
See moreS
with input parameterparam
from the beginning of the input sourceinput
of typeInput
. Note thatS
can be either a nonterminal or a terminal.Declaration
Swift
public final class Grammar<L, S, C> : GrammarComponent where L : Lexer, S : Selector, C : ConstructResult, L.Char == C.Char, L.Param == S.Param, L.Result == S.Result, S.Param == C.Param, S.Result == C.Result
- The