Skip to main content

NativeCellParser

Struct NativeCellParser 

Source
pub struct NativeCellParser { /* private fields */ }
Expand description

A retained native parser for line-oriented shell input.

Each call to Self::push_line appends one submitted physical line. Cells completed by a top-level newline or semicolon are removed from the active buffer and never parsed again. Only the unfinished tail is lexed and parsed on later submissions.

Missing delimiter closers and parser requirements at end of input are classified as NativeCellState::Incomplete. A recoverable typed cell is available through Self::active_syntax when synthetic delimiter closers were enough to parse its contents.

use m2_syn::{Lex, NativeCellParser, NativeCellState};

let mut parser = NativeCellParser::new();
assert_eq!(parser.push_line("f = x -> ("), NativeCellState::Incomplete);
assert!(parser.active_syntax().is_some());
assert_eq!(parser.push_line("x + 1"), NativeCellState::Incomplete);
assert_eq!(parser.push_line(")"), NativeCellState::Complete);

let cells = parser.take_completed();
assert_eq!(cells[0].syntax().to_m2(), "f = x -> (\nx + 1\n)");

Implementations§

Source§

impl NativeCellParser

Source

pub fn new() -> Self

Creates an empty native shell parser.

Source

pub fn push_line(&mut self, line: &str) -> NativeCellState

Appends one submitted physical line and refreshes the active cell.

A line feed is appended when line does not already end in one. This is the submission boundary: a syntactically complete final expression may become a completed cell, while an operator, required clause, or open delimiter keeps the cell active.

Source

pub fn state(&self) -> NativeCellState

Returns the current completion classification.

Source

pub fn active_source(&self) -> &str

Returns the exact source still belonging to the unfinished cell.

Source

pub fn active_tokens(&self) -> &TokenStream

Returns recovered tokens for the unfinished cell.

Source

pub fn active_syntax(&self) -> Option<&Cell>

Returns recovered typed syntax for the unfinished cell when available.

Source

pub fn lexer_diagnostics(&self) -> &[LexError]

Returns lexer diagnostics for the active cell.

Source

pub fn parse_error(&self) -> Option<&NativeParseError>

Returns the parser failure for an incomplete or invalid active cell.

Source

pub fn completed(&self) -> &[CompletedNativeCell]

Returns completed evaluation units that have not yet been taken.

Source

pub fn take_completed(&mut self) -> Vec<CompletedNativeCell>

Takes every completed evaluation unit without disturbing an active cell.

Source

pub fn reset_active(&mut self)

Discards the unfinished cell and its diagnostics.

Trait Implementations§

Source§

impl Debug for NativeCellParser

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for NativeCellParser

Source§

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