Skip to main content

LarkOptions

Struct LarkOptions 

pub struct LarkOptions {
Show 20 fields pub parser: Option<ParserKind>, pub lexer: LexerSpec, pub ambiguity: Ambiguity, pub priority: Option<PriorityLiteral>, pub propagate_positions: bool, pub maybe_placeholders: Option<bool>, pub keep_all_tokens: bool, pub start: Vec<String>, pub g_regex_flags: Option<u32>, pub translate_python_regex: bool, pub optimize_terminals: bool, pub ordered_sets: bool, pub use_bytes: bool, pub import_paths: Vec<Box<dyn GrammarLoader>>, pub source_path: Option<String>, pub postlex: Option<Box<dyn Postlex>>, pub lexer_callbacks: HashMap<String, TokenCallback>, pub edit_terminals: Option<EditTerminals>, pub scanner_engine: Option<ScannerEngine>, pub collect_used_files: bool,
}
Expand description

Construction options — Lark’s Lark(grammar, **options) kwargs as a flat Default-able struct (no fluent builder in core; a builder is binding sugar). Field-init the ones you need over Default::default.

Fields group by the stage they act in: compile-time (start, keep_all_tokens, maybe_placeholders, priority, import_paths, edit_terminals) feed the compiler; lexer-build (g_regex_flags, translate_python_regex, lexer_callbacks, postlex) shape the conf; parse-time (propagate_positions, ambiguity) drive the engine. lexer/parser select the frontend.

Fields§

§parser: Option<ParserKind>

parser= — Earley or LALR. None (the default) builds Earley from a grammar, as Lark does, and the saved parser from a save.

§lexer: LexerSpec

lexer= — auto (default) resolves per parser through resolve_lexer.

§ambiguity: Ambiguity

ambiguity= — Earley-only; Resolve (default) or Explicit.

§priority: Option<PriorityLiteral>

priority= — see PriorityLiteral; default Some(Auto) (Lark’s 'auto').

§propagate_positions: bool

propagate_positions= — attach per-node Meta (default off).

§maybe_placeholders: Option<bool>

maybe_placeholders= — insert None holes for [...] optionals. None (the default) means unspecified, which compiles as true from source and KEEPS the serialized value on the load path; Some(v) is an explicit choice and wins on both. It shapes the rules the loader builds, so losing a save’s value silently reshaped every reloaded tree — while forcing the file to win would equally silently ignore a deliberate maybe_placeholders= at load. Only the tri-state serves both.

§keep_all_tokens: bool

keep_all_tokens= — retain filtered/punctuation terminals in trees (default off).

§start: Vec<String>

start= — declared start symbols (default ["start"]).

§g_regex_flags: Option<u32>

g_regex_flags= — grammar-wide regex flag bitmask. None (the default) means unspecified, which compiles as 0 from source and KEEPS the serialized value on the load path; Some(v) is an explicit choice and wins on both. The tri-state is required because 0 is itself a valid mask, so a plain u32 could not tell “caller wants no flags” from “caller said nothing” — and the latter must not wipe a save’s flags. Lark lists g_regex_flags in _LOAD_ALLOWED_OPTIONS, so an explicit value overriding the file is the advertised behavior.

§translate_python_regex: bool

Rewrite the mechanical Python-re→Rust-engine construct set ([crate::py_regex]); default off, and experimental. (Not a Lark kwarg — a hyperlark engine-parity knob.)

§optimize_terminals: bool

optimize_terminals= — rewrite terminals with a verified lookaround-free equivalent to keep them on the regex-automata fast path. Default on.

KNOWN GAP, deliberately left as-is: a bool cannot distinguish “caller passed true” from “caller took the default”, so the dormant [Self::check_optimize_compat] guard — which is supposed to reject only an EXPLICIT optimize_terminals=true alongside compat=true — would reject every compat=true build. Whoever wires up compat must make this an Option<bool> at the same time; doing it now would be a source-breaking change to a public field for a feature that does not exist yet, which is not a trade worth making on its own.

§ordered_sets: bool

ordered_sets= — accepted and inert: hyperlark’s sets are already insertion-ordered, so both True/False behave as Lark’s True (documented no-op).

§use_bytes: bool

use_bytes= — deferred: constructing with it true is a LarkBuildError::Unsupported rather than silently mis-parsing text. Deferral was re-examined and confirmed (no-go): byte lexing has no path that avoids the off-limits scanner, fancy-regex has no &[u8] lookaround engine, and byte offsets fork the code-point position contract.

§import_paths: Vec<Box<dyn GrammarLoader>>

import_paths= — %import sources consulted before the embedded stdlib (first hit wins). Boxed loaders so the options own them.

§source_path: Option<String>

source_path= — the origin the entry grammar is compiled under (a file path, or a package resource path for open_from_package). None ⇒ the "<string>" origin. When set, a relative (%import .x) import IN THE ENTRY grammar resolves its base against dirname(source_path) instead of being treated as a library import (mirrors lark’s source_path).

§postlex: Option<Box<dyn Postlex>>

postlex= — a boxed Postlex (e.g. an crate::postlex::Indenter).

§lexer_callbacks: HashMap<String, TokenCallback>

lexer_callbacks= — per-terminal token callbacks by terminal NAME. Forbidden under a dynamic lexer (GrammarError).

§edit_terminals: Option<EditTerminals>

edit_terminals= — a hook run over every compiled TerminalDef between compile and the priority transform.

§scanner_engine: Option<ScannerEngine>

scanner_engine= — which regex-automata engine drives the fast (look-around-free) scanner partition. Not a Lark kwarg; a hyperlark performance knob, tier Provisional. None (default) selects [ScannerEngine::Lazy] — 8-25 % faster warm than Meta with neutral-to-lower resident memory, and robust even on cache-adversarial grammars. [ScannerEngine::Meta] is the opt-in fallback (optimizer-picked, WASM-friendly incumbent); [ScannerEngine::Dense] trades cold-parse + resident memory for the same warm win on small-alphabet grammars. All three tokenize identically; a pattern only meta’s own limits reject (\w{300}) builds on the other two.

§collect_used_files: bool

Record every %imported file THIS build loads, with the text its loader served, for Lark::take_used_files — the cache= invalidation side-data. Not a Lark kwarg. Off by default: an ordinary build collects nothing and allocates nothing. Source path only; a build from serialized JSON loads no grammar and records nothing.

Trait Implementations§

§

impl Default for LarkOptions

§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.