Skip to main content

ParserAst

Enum ParserAst 

Source
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.

Fields

§span: Span
§

Template

A backtick template: `{x:int},{y:int}`.

Fields

§span: Span
§

Lines

lines(P)Vec[result(P)].

Fields

§span: Span
§

Sections

sections(P)Vec[result(P)] (homogeneous; the named form is SectionsNamed).

Fields

§span: Span
§

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 of result(P) (SectionItem::One);
  • name: repeated(P, N) — exactly N consecutive sections, one field of Vec[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 of Vec[result(P)]. It is greedy, so nothing can follow it: there is at most one and it is last, which is repeated_tail being a single Option outside 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.

§repeated_tail: Option<(String, Box<ParserAst>)>

The unbounded repeated(P) tail, if present. The name (e.g. "boards") becomes the record’s last field; the parser consumes every remaining section into a Vec[result(P)].

§span: Span
§

Csv

csv(P)Vec[result(P)].

Fields

§span: Span
§

Ws

ws(P)Vec[result(P)] (whitespace-separated).

Fields

§span: Span
§

Sep

sep(separator, P)Vec[result(P)]. The separator is a Separator, which cannot be empty.

Fields

§separator: Separator
§span: Span
§

Grid

grid(P)Grid[result(P)].

Fields

§span: Span
§

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.

Fields

§span: Span
§

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).

Fields

§span: Span
§

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).

Fields

§span: Span
§

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.

Fields

§span: Span
§

OneOf

one_of("LR") (§7.5): match one character from a literal character set. Result is Char.

Fields

§chars: String
§span: Span
§

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.

Fields

§span: Span
§

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.

Fields

§span: Span
§

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.

Fields

§fill: String

The fill character/value, as the literal text from source (parsed by the cell parser at runtime).

§span: Span

Implementations§

Source§

impl ParserAst

Source

pub fn span(&self) -> Span

The source span of this parser node (§7.10: every node carries one).

Source

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.

Trait Implementations§

Source§

impl Clone for ParserAst

Source§

fn clone(&self) -> ParserAst

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParserAst

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.