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
Grammardescribes the syntax of the language to be parsed. Parsing is based on the concept of parameterized local lexing.A
Grammarconsists of a list of rules, a lexer, a selector, and a specification of how to construct the result of a successful parse.- The
Rules 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
Lexercomponent 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
Selectorcomponent 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
ConstructResultcomponent is a specification of how to construct theGrammar.Resultof a successful parse.
Given a list of
rules, alexer, aselectorand result construction specificationconstructResult, you create agrammarvialet 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 moreSwith input parameterparamfrom the beginning of the input sourceinputof typeInput. Note thatScan 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
Classes Reference