Skip to main content

NativeRealtimeCell

Struct NativeRealtimeCell 

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

One independently retained cell in a NativeRealtimeParser.

Spans inside the token and typed representations are local to the exact source returned by Self::source. Self::document_range locates that immutable cell source in the current document. This separation permits an unchanged cell to survive edits above it without rewriting every leaf span.

Implementations§

Source§

impl NativeRealtimeCell

Source

pub fn source(&self) -> &str

Returns this cell’s exact source spelling.

§Panics

Panics if the internally retained source span cannot resolve its text.

Source

pub fn document_range(&self) -> Range<usize> ⓘ

Returns this cell’s half-open byte range in the current document.

Source

pub fn tokens(&self) -> &TokenStream

Returns the tokenized cell, including inferred adjacency punctuation.

Examples found in repository?
examples/live_parser.rs (line 81)
43fn render(parser: &NativeRealtimeParser, clear: bool) -> String {
44    let mut output = String::new();
45    if clear {
46        output.push_str("\u{1b}[2J\u{1b}[H");
47    }
48    output.push_str("m2-syn live parser  (Ctrl-C/Ctrl-D exit, Backspace edits)\n\n");
49    output.push_str("SOURCE\n");
50    output.push_str(parser.source());
51    if !parser.source().ends_with('\n') {
52        output.push('\n');
53    }
54
55    let diagnostic_count = parser
56        .cells()
57        .iter()
58        .map(|cell| cell.lexer_diagnostics().len())
59        .sum::<usize>();
60    output.push_str(&format!(
61        "\nSTATE\n{:?}; {} cell(s); {} reparsed; {} lexer diagnostic(s)\n",
62        parser.state(),
63        parser.cells().len(),
64        parser.reparsed_cells().len(),
65        diagnostic_count,
66    ));
67    for cell in parser.cells() {
68        for diagnostic in cell.lexer_diagnostics() {
69            write_diagnostic(&mut output, diagnostic);
70        }
71    }
72
73    output.push_str("\nTOKENS\n");
74    for (index, cell) in parser.cells().iter().enumerate() {
75        output.push_str(&format!(
76            "cell {} · {:?} · {:?}\n",
77            index + 1,
78            cell.boundary(),
79            cell.state()
80        ));
81        output.push_str(&format_pretty_tokens(cell.tokens()));
82    }
83
84    output.push_str("\nSYNTAX\n");
85    for (index, cell) in parser.cells().iter().enumerate() {
86        output.push_str(&format!("cell {}\n", index + 1));
87        if let Some(syntax) = cell.syntax() {
88            output.push_str(&format_pretty_tree(syntax));
89        }
90        if let Some(error) = cell.parse_error() {
91            output.push_str(&format!("{error}\n"));
92        }
93    }
94    output
95}
Source

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

Returns recovered typed syntax when the native parser could construct it.

Examples found in repository?
examples/live_parser.rs (line 87)
43fn render(parser: &NativeRealtimeParser, clear: bool) -> String {
44    let mut output = String::new();
45    if clear {
46        output.push_str("\u{1b}[2J\u{1b}[H");
47    }
48    output.push_str("m2-syn live parser  (Ctrl-C/Ctrl-D exit, Backspace edits)\n\n");
49    output.push_str("SOURCE\n");
50    output.push_str(parser.source());
51    if !parser.source().ends_with('\n') {
52        output.push('\n');
53    }
54
55    let diagnostic_count = parser
56        .cells()
57        .iter()
58        .map(|cell| cell.lexer_diagnostics().len())
59        .sum::<usize>();
60    output.push_str(&format!(
61        "\nSTATE\n{:?}; {} cell(s); {} reparsed; {} lexer diagnostic(s)\n",
62        parser.state(),
63        parser.cells().len(),
64        parser.reparsed_cells().len(),
65        diagnostic_count,
66    ));
67    for cell in parser.cells() {
68        for diagnostic in cell.lexer_diagnostics() {
69            write_diagnostic(&mut output, diagnostic);
70        }
71    }
72
73    output.push_str("\nTOKENS\n");
74    for (index, cell) in parser.cells().iter().enumerate() {
75        output.push_str(&format!(
76            "cell {} · {:?} · {:?}\n",
77            index + 1,
78            cell.boundary(),
79            cell.state()
80        ));
81        output.push_str(&format_pretty_tokens(cell.tokens()));
82    }
83
84    output.push_str("\nSYNTAX\n");
85    for (index, cell) in parser.cells().iter().enumerate() {
86        output.push_str(&format!("cell {}\n", index + 1));
87        if let Some(syntax) = cell.syntax() {
88            output.push_str(&format_pretty_tree(syntax));
89        }
90        if let Some(error) = cell.parse_error() {
91            output.push_str(&format!("{error}\n"));
92        }
93    }
94    output
95}
Source

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

Returns recoverable lexer diagnostics associated with this cell.

Examples found in repository?
examples/live_parser.rs (line 58)
43fn render(parser: &NativeRealtimeParser, clear: bool) -> String {
44    let mut output = String::new();
45    if clear {
46        output.push_str("\u{1b}[2J\u{1b}[H");
47    }
48    output.push_str("m2-syn live parser  (Ctrl-C/Ctrl-D exit, Backspace edits)\n\n");
49    output.push_str("SOURCE\n");
50    output.push_str(parser.source());
51    if !parser.source().ends_with('\n') {
52        output.push('\n');
53    }
54
55    let diagnostic_count = parser
56        .cells()
57        .iter()
58        .map(|cell| cell.lexer_diagnostics().len())
59        .sum::<usize>();
60    output.push_str(&format!(
61        "\nSTATE\n{:?}; {} cell(s); {} reparsed; {} lexer diagnostic(s)\n",
62        parser.state(),
63        parser.cells().len(),
64        parser.reparsed_cells().len(),
65        diagnostic_count,
66    ));
67    for cell in parser.cells() {
68        for diagnostic in cell.lexer_diagnostics() {
69            write_diagnostic(&mut output, diagnostic);
70        }
71    }
72
73    output.push_str("\nTOKENS\n");
74    for (index, cell) in parser.cells().iter().enumerate() {
75        output.push_str(&format!(
76            "cell {} · {:?} · {:?}\n",
77            index + 1,
78            cell.boundary(),
79            cell.state()
80        ));
81        output.push_str(&format_pretty_tokens(cell.tokens()));
82    }
83
84    output.push_str("\nSYNTAX\n");
85    for (index, cell) in parser.cells().iter().enumerate() {
86        output.push_str(&format!("cell {}\n", index + 1));
87        if let Some(syntax) = cell.syntax() {
88            output.push_str(&format_pretty_tree(syntax));
89        }
90        if let Some(error) = cell.parse_error() {
91            output.push_str(&format!("{error}\n"));
92        }
93    }
94    output
95}
Source

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

Returns the native parser failure associated with this cell.

Examples found in repository?
examples/live_parser.rs (line 90)
43fn render(parser: &NativeRealtimeParser, clear: bool) -> String {
44    let mut output = String::new();
45    if clear {
46        output.push_str("\u{1b}[2J\u{1b}[H");
47    }
48    output.push_str("m2-syn live parser  (Ctrl-C/Ctrl-D exit, Backspace edits)\n\n");
49    output.push_str("SOURCE\n");
50    output.push_str(parser.source());
51    if !parser.source().ends_with('\n') {
52        output.push('\n');
53    }
54
55    let diagnostic_count = parser
56        .cells()
57        .iter()
58        .map(|cell| cell.lexer_diagnostics().len())
59        .sum::<usize>();
60    output.push_str(&format!(
61        "\nSTATE\n{:?}; {} cell(s); {} reparsed; {} lexer diagnostic(s)\n",
62        parser.state(),
63        parser.cells().len(),
64        parser.reparsed_cells().len(),
65        diagnostic_count,
66    ));
67    for cell in parser.cells() {
68        for diagnostic in cell.lexer_diagnostics() {
69            write_diagnostic(&mut output, diagnostic);
70        }
71    }
72
73    output.push_str("\nTOKENS\n");
74    for (index, cell) in parser.cells().iter().enumerate() {
75        output.push_str(&format!(
76            "cell {} · {:?} · {:?}\n",
77            index + 1,
78            cell.boundary(),
79            cell.state()
80        ));
81        output.push_str(&format_pretty_tokens(cell.tokens()));
82    }
83
84    output.push_str("\nSYNTAX\n");
85    for (index, cell) in parser.cells().iter().enumerate() {
86        output.push_str(&format!("cell {}\n", index + 1));
87        if let Some(syntax) = cell.syntax() {
88            output.push_str(&format_pretty_tree(syntax));
89        }
90        if let Some(error) = cell.parse_error() {
91            output.push_str(&format!("{error}\n"));
92        }
93    }
94    output
95}
Source

pub fn state(&self) -> NativeCellState

Returns whether this cell is complete, incomplete, or invalid.

Examples found in repository?
examples/live_parser.rs (line 79)
43fn render(parser: &NativeRealtimeParser, clear: bool) -> String {
44    let mut output = String::new();
45    if clear {
46        output.push_str("\u{1b}[2J\u{1b}[H");
47    }
48    output.push_str("m2-syn live parser  (Ctrl-C/Ctrl-D exit, Backspace edits)\n\n");
49    output.push_str("SOURCE\n");
50    output.push_str(parser.source());
51    if !parser.source().ends_with('\n') {
52        output.push('\n');
53    }
54
55    let diagnostic_count = parser
56        .cells()
57        .iter()
58        .map(|cell| cell.lexer_diagnostics().len())
59        .sum::<usize>();
60    output.push_str(&format!(
61        "\nSTATE\n{:?}; {} cell(s); {} reparsed; {} lexer diagnostic(s)\n",
62        parser.state(),
63        parser.cells().len(),
64        parser.reparsed_cells().len(),
65        diagnostic_count,
66    ));
67    for cell in parser.cells() {
68        for diagnostic in cell.lexer_diagnostics() {
69            write_diagnostic(&mut output, diagnostic);
70        }
71    }
72
73    output.push_str("\nTOKENS\n");
74    for (index, cell) in parser.cells().iter().enumerate() {
75        output.push_str(&format!(
76            "cell {} · {:?} · {:?}\n",
77            index + 1,
78            cell.boundary(),
79            cell.state()
80        ));
81        output.push_str(&format_pretty_tokens(cell.tokens()));
82    }
83
84    output.push_str("\nSYNTAX\n");
85    for (index, cell) in parser.cells().iter().enumerate() {
86        output.push_str(&format!("cell {}\n", index + 1));
87        if let Some(syntax) = cell.syntax() {
88            output.push_str(&format_pretty_tree(syntax));
89        }
90        if let Some(error) = cell.parse_error() {
91            output.push_str(&format!("{error}\n"));
92        }
93    }
94    output
95}
Source

pub fn boundary(&self) -> NativeCellBoundary

Returns the structural boundary currently following this cell.

Examples found in repository?
examples/live_parser.rs (line 78)
43fn render(parser: &NativeRealtimeParser, clear: bool) -> String {
44    let mut output = String::new();
45    if clear {
46        output.push_str("\u{1b}[2J\u{1b}[H");
47    }
48    output.push_str("m2-syn live parser  (Ctrl-C/Ctrl-D exit, Backspace edits)\n\n");
49    output.push_str("SOURCE\n");
50    output.push_str(parser.source());
51    if !parser.source().ends_with('\n') {
52        output.push('\n');
53    }
54
55    let diagnostic_count = parser
56        .cells()
57        .iter()
58        .map(|cell| cell.lexer_diagnostics().len())
59        .sum::<usize>();
60    output.push_str(&format!(
61        "\nSTATE\n{:?}; {} cell(s); {} reparsed; {} lexer diagnostic(s)\n",
62        parser.state(),
63        parser.cells().len(),
64        parser.reparsed_cells().len(),
65        diagnostic_count,
66    ));
67    for cell in parser.cells() {
68        for diagnostic in cell.lexer_diagnostics() {
69            write_diagnostic(&mut output, diagnostic);
70        }
71    }
72
73    output.push_str("\nTOKENS\n");
74    for (index, cell) in parser.cells().iter().enumerate() {
75        output.push_str(&format!(
76            "cell {} · {:?} · {:?}\n",
77            index + 1,
78            cell.boundary(),
79            cell.state()
80        ));
81        output.push_str(&format_pretty_tokens(cell.tokens()));
82    }
83
84    output.push_str("\nSYNTAX\n");
85    for (index, cell) in parser.cells().iter().enumerate() {
86        output.push_str(&format!("cell {}\n", index + 1));
87        if let Some(syntax) = cell.syntax() {
88            output.push_str(&format_pretty_tree(syntax));
89        }
90        if let Some(error) = cell.parse_error() {
91            output.push_str(&format!("{error}\n"));
92        }
93    }
94    output
95}

Trait Implementations§

Source§

impl Debug for NativeRealtimeCell

Source§

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

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

impl Spanned for NativeRealtimeCell

Source§

fn try_span(&self) -> Option<Span>

Returns the smallest span covering this value, when its constituents share one source snapshot.
Source§

fn span(&self) -> Span

Returns the smallest span covering this value. Read more
Source§

fn expect_span(&self) -> Span

Returns this value’s span when one source snapshot covers it. 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.