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
impl NativeCellParser
Sourcepub fn push_line(&mut self, line: &str) -> NativeCellState
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.
Sourcepub fn state(&self) -> NativeCellState
pub fn state(&self) -> NativeCellState
Returns the current completion classification.
Sourcepub fn active_source(&self) -> &str
pub fn active_source(&self) -> &str
Returns the exact source still belonging to the unfinished cell.
Sourcepub fn active_tokens(&self) -> &TokenStream
pub fn active_tokens(&self) -> &TokenStream
Returns recovered tokens for the unfinished cell.
Sourcepub fn active_syntax(&self) -> Option<&Cell>
pub fn active_syntax(&self) -> Option<&Cell>
Returns recovered typed syntax for the unfinished cell when available.
Sourcepub fn lexer_diagnostics(&self) -> &[LexError]
pub fn lexer_diagnostics(&self) -> &[LexError]
Returns lexer diagnostics for the active cell.
Sourcepub fn parse_error(&self) -> Option<&NativeParseError>
pub fn parse_error(&self) -> Option<&NativeParseError>
Returns the parser failure for an incomplete or invalid active cell.
Sourcepub fn completed(&self) -> &[CompletedNativeCell]
pub fn completed(&self) -> &[CompletedNativeCell]
Returns completed evaluation units that have not yet been taken.
Sourcepub fn take_completed(&mut self) -> Vec<CompletedNativeCell>
pub fn take_completed(&mut self) -> Vec<CompletedNativeCell>
Takes every completed evaluation unit without disturbing an active cell.
Sourcepub fn reset_active(&mut self)
pub fn reset_active(&mut self)
Discards the unfinished cell and its diagnostics.