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 generator from the registered rules.
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 generator rule definition by its name. Useful for inspecting or wrapping existing rules when extending a generator.
The name of the rule, type-checked against the builder's known rule names.
Merge this grammar GeneratorBuilder 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 generator 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 GeneratorBuilder from some initial grammar rules or an existing GeneratorBuilder. If a GeneratorBuilder is provided, a new copy will be created.
Create a GeneratorBuilder from some initial grammar rules or an existing GeneratorBuilder. If a GeneratorBuilder is provided, a new copy will be created.
Builder for composing modular code generators from rule definitions. Mirrors the ParserBuilder API but targets code generation (AST → string) instead of parsing (string → AST).
Builders mutate internal state and return
this. Always start by copying an existing builder withGeneratorBuilder.create(existingBuilder).