Grammar
LBNF
Lux uses LBNF (BNF variant) to describe the grammar.
Defining rules
To define rule simply do this:
Rule name must only contain letters, digits, hyphens and underscores:
Root rule
To define root rule (rule that will be used to match the whole input) use !:
Rule name can be only defined once!
Patterns
Basic rule for LBNF is pattern. Pattern must be surrounded by quotes:
Don’t use whitespaces and line breaks in patterns: use inline and multiline indent instead!
Includes
You can include rules by name and use them in other rules:
Groups
You can group rules by using parentheses:
Chains
Chains are rule sets that can be used to define a rule sequence or a rule variants.
Modifiers
Rule modifiers describe how many times the rule can be repeated:
You can specify repeation count:
Advanced usage
You can create rules manually using Grammar._or, Grammar._and, Grammar.repeation, Grammar.optional, Grammar.pattern, Grammar.include and Grammar.custom.
Custom rules
You can define custom rules using Grammar.custom: