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.

@@comments :: <regexp>

Specifies a regular expression to identify and exclude inline (bracketed) comments before the text is scanned by the parser. For (* ... *) comments:

@@comments :: /\(\*((?:.|\n)*?)\*\)/

@@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]*?)$/

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

@@namechars :: <string>

A list of (non-alfanumeric) 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 alfarnumeric 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:

  • rule the rule name that parsed the node

  • pos the initial position for the node in the input

  • endpos the final position for the node in the input

  • line the initial input line number for the element

  • endline the 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