pub fn emit_antlr(
grammar: &Grammar,
) -> Result<(String, EmitReport), GrammarEmitError>Expand description
Emits a combined ANTLR v4 grammar.
Normal rules become parser rules (lower-case first letter), token and
atomic rules become lexer rules (upper-case first letter) and silent rules
become fragment lexer rules. Rule names are adjusted deterministically to
ANTLR’s case conventions and reserved words; every rename is recorded in
EmitReport::lossy as ANTLR renamed rule "a" to "b".
Ordered choice is written as ANTLR alternation, negative lookahead as the
~ complement (a lookahead over a set followed by any character becomes a
complemented set), case-insensitive literals as per-letter sets, counted
repetition as copies with nested optionals, and captures as label=
element labels. Positive lookahead and anonymous captures have no ANTLR
form and are dropped. Every lowering and drop is recorded in the report,
so import_antlr of the output reproduces the grammar modulo the recorded
notes, and emitting the re-imported grammar reproduces the same text.
Rule documentation is written as comments above each rule; a trailing
-> command documentation part of a lexer rule, as produced by
import_antlr, is written back as the lexer command.
§Errors
Returns GrammarEmitError::Unsupported for empty non-negated character
classes, descending character ranges, repetitions whose maximum is below
their minimum, and counted repetitions that would expand to more than 256
copies of their operand.