Struct Pattern
pub struct Pattern {
pub kind: PatternKind,
pub value: String,
pub flags: Vec<char>,
pub raw: Option<String>,
pub serialized_width: Option<(u64, u64)>,
}Expand description
A terminal’s pattern: raw value + per-terminal flags (chars: i m s x l u,
as Lark serializes its frozenset) + the optional raw grammar-source form.
Fields§
§kind: PatternKind§value: StringThe literal text (Str) or the regex source (RE) — unwrapped: the
four-part sort key measures len(value) on this raw form.
flags: Vec<char>Per-terminal flags, applied one at a time by Self::to_regexp as
(?f:…) groups. Only the legal re letters (imsxaLu) are meaningful;
the letter SET is not validated here — an out-of-set flag is rejected
(loudly, with location) at scanner build when the wrapped regex fails to
compile, not at model construction.
raw: Option<String>The grammar-source form (serialized raw); round-trip only, never matched.
serialized_width: Option<(u64, u64)>Lark’s own serialized _width (code points), present only on the
JSON-load path (PatternRE carries it; PatternStr doesn’t). Used as a
test oracle against width::regexp_width — never by the sort itself,
which recomputes so the (.lark) path shares one width route.
Implementations§
§impl Pattern
impl Pattern
pub fn to_regexp(&self) -> String
pub fn to_regexp(&self) -> String
Lark’s to_regexp(): the final engine-facing regex string.
Str:re_escapethe value.RE: the value as-is.- Then wrap each per-terminal flag individually, innermost-first, as
(?f:…)— nesting like(?i:(?s:…)).
Grammar-wide g_regex_flags must NEVER appear in this string — they
apply at engine-compile time only (grammar-wide flags).
newline_types and the width sort-key are computed from this output.