syntax RegexRule = RuleAttributes "regex" Name "=" RegexExpression RegexRuleBody;

These are named rules that parse regular grammar (regular expressions). They don’t support recursion of any kind, however the (*and+) loops are supported.


regex Digits   = ['0'..'9']+;
regex Integer  = '0' | ['1'..'9'] ['0'..'9']*;
regex Exponent = ("E" | "e") ("-" | "+")? Digits;
regex Fraction = "." Digits ;
regex Number = "-"? Integer Fraction? Exponent?;

Such rules do not produce AST. Instead, a text span is calculated for them. NSpan type values correspond to them in materialized AST.

During error recovery, no internal recovery of RegexRule is performed, since they are considered solid values.

Do not apply these rules for defining complicated tokens, such as strings and comments. This will result in incorrect auto-recovery from detected errors. Describe strings and comments as token rules which content can be described with regex rules.

RegexRuleBody may contain nested token rules:

regex EscChar = '\\' | '/' | 'b' | 'f' | 'n' | 'r'| 't'
              | 'u' HexDigit HexDigit HexDigit HexDigit
  regex HexDigit = ['0'..'9', 'a'..'f', 'A'..'F'];

See also

token vs. regex