Add multiple rules at once using rest parameters. Provides better TypeScript type inference than calling addRule in a loop, but avoid passing too many rules at once as this can cause TypeScript compilation slowdowns. TypeScript errors if any rule name conflicts with an existing one.
Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.
Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.
Construct a self-sufficient parser from the registered rules and token vocabulary. Building a parser is expensive (Chevrotain performs grammar recording), so the result should be reused across parse calls.
An object with a method for each registered rule name.
Delete multiple rules by name in a single call.
Names of the rules to delete.
Delete a grammar rule by its name.
Retrieve a grammar rule definition by its name. Useful for inspecting or wrapping existing rules when extending a parser.
The name of the rule, type-checked against the builder's known rule names.
Merge this grammar builder with another. It is best to merge the bigger grammar with the smaller one. If the two builders both have a grammar rule with the same name, no error will be thrown case they map to the same ruledef object. If they map to a different object, an error will be thrown. To fix this problem, the overridingRules array should contain a rule with the same conflicting name, this rule implementation will be used.
Change the implementation of an existing grammar rule.
Update the type signatures (return types and/or parameter types) of existing rules without changing their implementations. Use this when a patched rule changes the types flowing through downstream rules that don't need new implementations. This is a zero-cost type-level operation.
Narrow the builder's context type parameter to a more specific subtype. This is a zero-cost type-level operation — the builder instance is returned as-is but with updated type parameters.
StaticcreateCreate a builder from some initial grammar rules or an existing builder. If a builder is provided, a new copy will be created.
The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework). Using the builder you can create a grammar + AST creator. At any point in time, a parser can be constructed from the added rules. Constructing a parser will cause a validation which will validate the correctness of the grammar.