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 Char.

    See more

    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 Rules basically describe a context-free grammar whose nonterminals and terminals are parameterized by an input and an output parameter, each of type Grammar.Param. The computation of these parameters is guided via evaluation functions of type EvalFunc. 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 the Grammar.Result of a successful parse.

    Given a list of rules, a lexer, a selector and result construction specification constructResult, you create a grammar via

    let 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 S with input parameter param from the beginning of the input source input of type Input. Note that S can be either a nonterminal or a terminal.

    See more

    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