pub fn emit_lark(
grammar: &Grammar,
) -> Result<(String, EmitReport), GrammarEmitError>Expand description
Emits a Lark grammar.
Normal rules become lower-case Lark rules, silent rules become inlined
?rules, and token and atomic rules become upper-case terminals. Rule
names are adjusted deterministically to Lark’s case conventions; every
rename is recorded in EmitReport::lossy as
Lark renamed rule "a" to "b". Silent rules documented exactly as
%ignore, which is how import_lark represents %ignore directives, are
written back as %ignore directives; no other %ignore is emitted.
Character classes, ranges and any-character are written as regex
terminals, case-insensitive literals as (?i:...) regexes, counted
repetition as ~ n..m, and captures labelled regex over a literal as
the regex they were imported from. Ordered choice is written as Lark
alternation; lookahead and other captures have no Lark form and are
dropped, except that a negative lookahead over a character set followed by
any character becomes a complemented character class. Every lowering and
drop is recorded in the report, so import_lark 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; trailing
inline and priority N documentation parts, as produced by
import_lark, are written back as the ? prefix and .N priority.
§Errors
Returns GrammarEmitError::Unsupported for empty non-negated character
classes, descending character ranges, repetitions whose maximum is below
their minimum, and regexes that Lark cannot delimit.