- orphan:
Grammar Directives#
竜 TatSu allows directives in the grammar that control the behavior of the generated parsers. All directives are of the form @@name :: <value>. For example:
@@ignorecase :: True
The directives supported by 竜 TatSu are described below.
@@grammar :: <word>#
Specifies the name of the grammar, and provides the base name for the classes in parser source-code generation.
@@eol_comments :: <regexp>#
Specifies a regular expression to identify and exclude end-of-line comments before the text is scanned by the parser. For # ... comments:
@@eol_comments :: /#([^\n]*?)$/
Note
In previous versions of 竜 TatSu, the re.MULTILINE
option was enabled by default. This is no longer the case. Use (?m) at the start of your
regular expressions to make them multi-line.
@@ignorecase :: <bool>#
If set to True makes 竜 TatSu not consider case when parsing tokens. Defaults to False:
@@ignorecase :: True
@@keyword :: {<word>|<string>}+#
Specifies the list of strings or words that the grammar should consider as “keywords”. May appear more than once. See the Reserved Words and Keywords section for an explanation.
@@left_recursion :: <bool>#
Enables left-recursive rules in the grammar. See the Left Recursion sections for an explanation.
Left recursion is enabled by default. Yo may obtain faster parsing by disabling it when it’s not needed.
@@memoize :: <boolean>#
Enables or disables memoization during parser. Setting it fo False disables left recursion.
@@namechars :: <string>#
A list of (non-alphanumeric) characters that should be considered part of names when using the @@nameguard feature:
@@namechars :: '-_$'
@@nameguard :: <bool>#
When set to True, avoids matching tokens when the next character in the input sequence is alphanumeric or a @@namechar. Defaults to True. See the ‘text’ expression for an explanation.
@@nameguard :: False
@@parseinfo :: <bool>#
When True, the parser will add parse information to every AST and Node generated by the parse under a parseinfo field. The information will include:
rulethe rule name that parsed the nodeposthe initial position for the node in the inputendposthe final position for the node in the inputlinethe initial input line number for the elementendlinethe final line number for the element
Enabling @@parseinfo will allow precise reporting over the input source-code while performing semantic actions.
@@whitespace :: <regexp>#
Provides a regular expression for the whitespace to be ignored by the parser. If no definition is
provided, then r'(?m)\s+' will be used as default:
@@whitespace :: /[\t ]+/
To disable any parsing of whitespace, use None for the definition:
@@whitespace :: None
Note
In previous versions of 竜 TatSu, the re.MULTILINE
option was enabled by default. This is no longer the case. Use (?m) at the start of your
regular expressions to make them multi-line.
@@comments :: <regexp>#
Specifies a regular expression to identify and exclude inline (bracketed) comments before the text is scanned by the parser. For
(* ... *)comments:Note
In previous versions of 竜 TatSu, the re.MULTILINE option was enabled by default. This is no longer the case. Use
(?m)at the start of your regular expressions to make them multi-line.