christianparpart/klex

support referencing rules

Closed this issue · 0 comments

just like in flex, where you can create some helper REs for later reference, so that the actual pattern looks cleaner and is more maintainable.

proposal:

  • Rule-option (ref) denotes a rule that can be referenced, and thus, will not itself be part of the resulting rule set nor will it consume a tag number.
  • Rules (including those wich itself are ref-rules) may reference rules by naming them with curly braces surrounded, such as {helper}.
# using the option notation and pass "ref". Such rules are only visible to the rule parser
DIGIT(ref) ::= [0-9]

# this ref uses another ref
RNUM ::= {DIGIT}{0,2}(_{DIGIT}{3})*

# final rule, making use of both refs above.
Number ::= {DIGIT}+|{RNUM}