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
impl NativeRealtimeCell
Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
Returns this cell’s exact source spelling.
§Panics
Panics if the internally retained source span cannot resolve its text.
Sourcepub fn document_range(&self) -> Range<usize> ⓘ
pub fn document_range(&self) -> Range<usize> ⓘ
Returns this cell’s half-open byte range in the current document.
Sourcepub fn tokens(&self) -> &TokenStream
pub fn tokens(&self) -> &TokenStream
Returns the tokenized cell, including inferred adjacency punctuation.
Examples found in repository?
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}Sourcepub fn syntax(&self) -> Option<&Cell>
pub fn syntax(&self) -> Option<&Cell>
Returns recovered typed syntax when the native parser could construct it.
Examples found in repository?
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}Sourcepub fn lexer_diagnostics(&self) -> &[LexError]
pub fn lexer_diagnostics(&self) -> &[LexError]
Returns recoverable lexer diagnostics associated with this cell.
Examples found in repository?
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}Sourcepub fn parse_error(&self) -> Option<&NativeParseError>
pub fn parse_error(&self) -> Option<&NativeParseError>
Returns the native parser failure associated with this cell.
Examples found in repository?
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}Sourcepub fn state(&self) -> NativeCellState
pub fn state(&self) -> NativeCellState
Returns whether this cell is complete, incomplete, or invalid.
Examples found in repository?
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}Sourcepub fn boundary(&self) -> NativeCellBoundary
pub fn boundary(&self) -> NativeCellBoundary
Returns the structural boundary currently following this cell.
Examples found in repository?
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}