API Reference

Classes:

class Grammar(rules, semantics)

Creates a grammar from the dict of GrammarRules supplied with the rules parameter, optionally with the semantics semantics

method __call__(text: str)

Tests the argument string against the grammar and returns an AST or an undefined object if there are semantics for the start rule defined

Parameters: * [str] text: an input to parse using the grammar

Returns: * list or the return value of the semantic action defined for start e.g. Grammar(...).semantics.start()

class GrammarRule(*tokens)

Defines a Grammar Rule that matches *tokens. Only used in the rules parameter of the Grammar class. Also usable through the token Rule

Tokens:

Tokens will be compared to TatSu tokens

token String(string)

Matches the string parameter
Returns: [str] The matched string e.g. the string parameter
(TatSu equivalent: "...")

token Regex(pattern, *flags)

Matches the regex pattern, optionally compiled with *flags
Returns: [_sre.SRE_Match] The re match object
(TatSu equivalent: /.../)

token Rule(name)

Matches the GrammarRule class defined before
Returns: Whatever the Rule name matched
(TatSu equivalent: name)

token End()

Matches if nothing comes after it
Returns: None
(TatSu equivalent: $)

token Optional(*tokens)

Matches either *tokens or nothing
Returns: Either a list of return values returned from *tokens or one return value if len(tokens) >= 2
(TatSu equivalent: [...])

token Group(*tokens)

Matches all *tokens
Returns: [list] Return values of *tokens
(TatSu equivalent: (...))

token Or(*tokens)

Matches the first matching member of *tokens
Returns: The return value of the first match
(TatSu equivalent: (...|...))

token ZeroOrMore(*tokens)

Matches the *tokens Zero or more times
Returns: [list] List of *tokens matches
(TatSu equivalent: {...}*)

token OneOrMore(*tokens)

Matches the *tokens One or more times
Returns: [list] List of *tokens matches
(TatSu equivalent: {...}+)