API Reference
Classes:
class Grammar(rules, semantics)
Creates a grammar from the
dictofGrammarRulessupplied with therulesparameter, optionally with the semanticssemanticsmethod __call__(text: str)
Tests the argument
stringagainst the grammar and returns an AST or an undefined object if there are semantics for thestartrule definedParameters: * [
str]text: an input to parse using the grammarReturns: *
listor the return value of the semantic action defined forstarte.g.Grammar(...).semantics.start()
class GrammarRule(*tokens)
Defines a Grammar Rule that matches
*tokens. Only used in therulesparameter of theGrammarclass. Also usable through the tokenRule
Tokens:
Tokens will be compared to TatSu tokens
token String(string)
Matches the
stringparameter
Returns: [str] The matched string e.g. thestringparameter
(TatSuequivalent:"...")
token Regex(pattern, *flags)
Matches the regex
pattern, optionally compiled with*flags
Returns: [_sre.SRE_Match] Therematch object
(TatSuequivalent:/.../)
token Rule(name)
Matches the
GrammarRuleclass defined before
Returns: Whatever the Rulenamematched
(TatSuequivalent:name)
token End()
Matches if nothing comes after it
Returns:None
(TatSuequivalent:$)
token Optional(*tokens)
Matches either
*tokensor nothing
Returns: Either a list of return values returned from*tokensor one return value iflen(tokens) >= 2
(TatSuequivalent:[...])
token Group(*tokens)
Matches all
*tokens
Returns: [list] Return values of*tokens
(TatSuequivalent:(...))
token Or(*tokens)
Matches the first matching member of
*tokens
Returns: The return value of the first match
(TatSuequivalent:(...|...))
token ZeroOrMore(*tokens)
Matches the
*tokensZero or more times
Returns: [list] List of*tokensmatches
(TatSuequivalent:{...}*)
token OneOrMore(*tokens)
Matches the
*tokensOne or more times
Returns: [list] List of*tokensmatches
(TatSuequivalent:{...}+)