pub enum ParserAst {
Show 17 variants
Atomic {
kind: AtomicKind,
span: Span,
},
Template {
parts: Vec<TemplatePart>,
span: Span,
},
Lines {
child: Box<ParserAst>,
span: Span,
},
Sections {
child: Box<ParserAst>,
span: Span,
},
SectionsNamed {
fields: Vec<SectionItem>,
repeated_tail: Option<(String, Box<ParserAst>)>,
span: Span,
},
Csv {
child: Box<ParserAst>,
span: Span,
},
Ws {
child: Box<ParserAst>,
span: Span,
},
Sep {
separator: Separator,
child: Box<ParserAst>,
span: Span,
},
Grid {
child: Box<ParserAst>,
span: Span,
},
Block {
items: Vec<BlockItem>,
span: Span,
},
Choice {
cases: Vec<(String, ParserAst)>,
span: Span,
},
Optional {
child: Box<ParserAst>,
span: Span,
},
Scan {
child: Box<ParserAst>,
span: Span,
},
OneOf {
chars: String,
span: Span,
},
Characters {
child: Box<ParserAst>,
skip: SkipPolicy,
span: Span,
},
Matrix {
child: Box<ParserAst>,
span: Span,
},
GridRagged {
child: Box<ParserAst>,
fill: String,
span: Span,
},
}Expand description
A parser expression (§7.9 ParserExpr).
Variants§
Atomic
An atomic parser: int, char, etc.
Template
A backtick template: `{x:int},{y:int}`.
Lines
lines(P) → Vec[result(P)].
Sections
sections(P) → Vec[result(P)] (homogeneous; the named form is
SectionsNamed).
SectionsNamed
Named heterogeneous sections(name: P, ..., tail: repeated(P)) (§7.5).
Result is an anonymous record with one field per named argument, in
source order.
A named argument takes one of three forms, and the split between
fields and repeated_tail is what keeps the third one’s rule
structural rather than remembered:
name: P— one section, one field ofresult(P)(SectionItem::One);name: repeated(P, N)— exactlyNconsecutive sections, one field ofVec[result(P)](SectionItem::Counted). It is bounded, so it may sit anywhere among the named arguments and other fields may follow it;name: repeated(P)— every section that is left, one field ofVec[result(P)]. It is greedy, so nothing can follow it: there is at most one and it is last, which isrepeated_tailbeing a singleOptionoutside the list rather than a variant inside it.
Fields
fields: Vec<SectionItem>The named arguments other than the unbounded tail, in source order.
Each contributes exactly one record field and consumes
SectionItem::sections_wanted sections.
Csv
csv(P) → Vec[result(P)].
Ws
ws(P) → Vec[result(P)] (whitespace-separated).
Sep
sep(separator, P) → Vec[result(P)]. The separator is a
Separator, which cannot be empty.
Grid
grid(P) → Grid[result(P)].
Block
block(item, ...) (§7.5): apply sequential parsers within one
region. A positional item that is a named-capture template flattens
its captures into the block’s record; a positional scalar must be
named (else rejected). A named item contributes one field. Result is a
flattened anonymous record.
Choice
choice(Name: P, Name: P, ...) (§7.5): parse one of several
alternatives, generating an anonymous enum. Each case’s parser produces
the payload (a record for a named-capture template, a scalar otherwise).
The first alternative that matches wins (source order).
Optional
optional(P) (§7.5): parse P if it matches, else consume nothing
and return None. Result is Option[result(P)]. Failure consumes no
input (parser-level optionality, not exception recovery).
Scan
scan(P) (§7.5): find repeated P matches inside otherwise
irrelevant text (e.g. corrupted AoC input). Returns matches in source
order as Vec[result(P)], ignoring unmatched text.
OneOf
one_of("LR") (§7.5): match one character from a literal character
set. Result is Char.
Characters
chars(P, skip:) (§7.5): apply a char-parser repeatedly. Result is
Vec[result(P)] — not Vec[Char] whatever P is, since the
runtime stores what P produced: chars(int, skip: none) is a
Vec[Int], and chars(one_of("LR")) is a Vec[Char] because one_of
is Char. The skip policy trims between matches; see SkipPolicy,
and note that newlines is the broader of the two non-none
policies.
Matrix
matrix(P) (§7.5, ADR-030): parse lines of whitespace-separated
tokens into a rectangular Grid[result(P)]. Same result type as grid
but tokenizes on whitespace rather than per-character.
GridRagged
Ragged grid(P, ragged, fill:) (§7.5): permit uneven rows and pad
to the maximum width with fill. The plain grid(P) keeps its own arm.
Implementations§
Source§impl ParserAst
impl ParserAst
Sourcepub fn span(&self) -> Span
pub fn span(&self) -> Span
The source span of this parser node (§7.10: every node carries one).
Sourcepub fn shift_spans(&mut self, delta: u32)
pub fn shift_spans(&mut self, delta: u32)
Shift every span in this subtree by delta bytes.
The template scanner works in interior-relative offsets: it is given the text between the backticks and knows nothing about where the token sits in the file. The HIR bridge, which does know, rebases the tree by the token’s start + 1 (the opening backtick). Without this a capture body’s diagnostic caret would land near the top of the file.