API Reference
Classes:
class Grammar(rules, semantics)
Creates a grammar from the
dict
ofGrammarRules
supplied with therules
parameter, optionally with the semanticssemantics
method __call__(text: str)
Tests the argument
string
against the grammar and returns an AST or an undefined object if there are semantics for thestart
rule definedParameters: * [
str
]text
: an input to parse using the grammarReturns: *
list
or the return value of the semantic action defined forstart
e.g.Grammar(...).semantics.start()
class GrammarRule(*tokens)
Defines a Grammar Rule that matches
*tokens
. Only used in therules
parameter of theGrammar
class. Also usable through the tokenRule
Tokens:
Tokens will be compared to TatSu
tokens
token String(string)
Matches the
string
parameter
Returns: [str
] The matched string e.g. thestring
parameter
(TatSu
equivalent:"..."
)
token Regex(pattern, *flags)
Matches the regex
pattern
, optionally compiled with*flags
Returns: [_sre.SRE_Match
] There
match object
(TatSu
equivalent:/.../
)
token Rule(name)
Matches the
GrammarRule
class defined before
Returns: Whatever the Rulename
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 iflen(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:{...}+
)