Skip to content

Commit

Permalink
Add an Unrecognized label for Unrecognized nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjoerussell committed Jan 3, 2025
1 parent 4b5c352 commit 819da29
Show file tree
Hide file tree
Showing 230 changed files with 405 additions and 301 deletions.
1 change: 1 addition & 0 deletions crates/codegen/language/definition/src/model/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub struct Topic {
#[strum(serialize_all = "snake_case")]
pub enum PredefinedLabel {
Root,
Unrecognized,
Item,
Variant,
Separator,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::rc::Rc;

use crate::cst::{Edge, Node, TerminalKind, TerminalKindExtensions, TextIndex};
use crate::cst::{Edge, EdgeLabel, Node, TerminalKind, TerminalKindExtensions, TextIndex};
use crate::parser::lexer::Lexer;
use crate::parser::parser_support::context::ParserContext;
use crate::parser::parser_support::parser_result::{
Expand Down Expand Up @@ -84,11 +84,18 @@ where
} else {
TerminalKind::UNRECOGNIZED
};

let label = if kind == TerminalKind::UNRECOGNIZED {
EdgeLabel::Unrecognized
} else {
EdgeLabel::default()
};

let node = Node::terminal(kind, input.to_string());
let tree = if no_match.kind.is_none() || start.utf8 == 0 {
node
} else {
trivia_nodes.push(Edge::root(node));
trivia_nodes.push(Edge { label, node });
Node::nonterminal(no_match.kind.unwrap(), trivia_nodes)
};
ParseOutput {
Expand Down Expand Up @@ -144,9 +151,19 @@ where
} else {
TerminalKind::UNRECOGNIZED
};

let label = if kind == TerminalKind::UNRECOGNIZED {
EdgeLabel::Unrecognized
} else {
EdgeLabel::default()
};

let skipped_node = Node::terminal(kind, input[start..].to_string());
let mut new_children = topmost_node.children.clone();
new_children.push(Edge::root(skipped_node));
new_children.push(Edge {
label,
node: skipped_node,
});

let start_index = stream.text_index_at(start);
let mut errors = stream.into_errors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ impl SeparatedHelper {
} else {
TerminalKind::UNRECOGNIZED
};
accum.push(Edge::root(Node::terminal(
kind,
input.content(skipped_range.utf8()),
)));

let label = if kind == TerminalKind::UNRECOGNIZED {
EdgeLabel::Unrecognized
} else {
EdgeLabel::default()
};

accum.push(Edge {
label,
node: Node::terminal(kind, input.content(skipped_range.utf8())),
});
input.emit(ParseError::new(
skipped_range,
incomplete.expected_terminals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ impl SequenceHelper {
} else {
TerminalKind::UNRECOGNIZED
};
running.nodes.push(Edge::root(Node::terminal(

let label = if kind == TerminalKind::UNRECOGNIZED {
EdgeLabel::Unrecognized
} else {
EdgeLabel::default()
};

running.nodes.push(Edge{label, node: Node::terminal(
kind,
std::mem::take(&mut running.skipped),
)));
)});
running.nodes.extend(next.nodes);

self.result = State::Running(ParserResult::Match(Match {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Tree:
- (item꞉ Identifier): "a" # (101..102)
- (separator꞉ Period): "." # (102..103)
- (item꞉ Identifier): "b" # (103..104)
- (root꞉ UNRECOGNIZED): "('\n }')" # (104..118)
- (unrecognized꞉ UNRECOGNIZED): "('\n }')" # (104..118)
- (semicolon꞉ Semicolon): ";" # (118..119)
- (trailing_trivia꞉ EndOfLine): "\n" # (119..120)
- (close_brace꞉ CloseBrace): "}" # (120..121)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Tree:
- (item꞉ Identifier): "a" # (101..102)
- (separator꞉ Period): "." # (102..103)
- (item꞉ Identifier): "b" # (103..104)
- (root꞉ UNRECOGNIZED): "('\n }')" # (104..118)
- (unrecognized꞉ UNRECOGNIZED): "('\n }')" # (104..118)
- (semicolon꞉ Semicolon): ";" # (118..119)
- (trailing_trivia꞉ EndOfLine): "\n" # (119..120)
- (close_brace꞉ CloseBrace): "}" # (120..121)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Tree:
- (leading_trivia꞉ Whitespace): " " # (1..2)
- (item꞉ Identifier): "unchecked" # (2..11)
- (leading_trivia꞉ Whitespace): " " # (11..12)
- (root꞉ UNRECOGNIZED): "{ x = 1; } " # (12..23)
- (unrecognized꞉ UNRECOGNIZED): "{ x = 1; } " # (12..23)
- (close_brace꞉ CloseBrace): "}" # (23..24)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Tree:
- (open_brace꞉ OpenBrace): "{" # (0..1)
- (statements꞉ Statements): [] # (1..1)
- (leading_trivia꞉ Whitespace): " " # (1..2)
- (root꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (unrecognized꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (close_brace꞉ CloseBrace): "}" # (23..24)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Tree:
- (open_brace꞉ OpenBrace): "{" # (0..1)
- (statements꞉ Statements): [] # (1..1)
- (leading_trivia꞉ Whitespace): " " # (1..2)
- (root꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (unrecognized꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (close_brace꞉ CloseBrace): "}" # (23..24)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Tree:
- (open_brace꞉ OpenBrace): "{" # (0..1)
- (statements꞉ Statements): [] # (1..1)
- (leading_trivia꞉ Whitespace): " " # (1..2)
- (root꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (unrecognized꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (close_brace꞉ CloseBrace): "}" # (23..24)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Tree:
- (open_brace꞉ OpenBrace): "{" # (0..1)
- (statements꞉ Statements): [] # (1..1)
- (leading_trivia꞉ Whitespace): " " # (1..2)
- (root꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (unrecognized꞉ UNRECOGNIZED): "unchecked { x = 1; } " # (2..23)
- (close_brace꞉ CloseBrace): "}" # (23..24)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Tree:
- (root꞉ BreakStatement): # "break invalid ;\n" (0..16)
- (break_keyword꞉ BreakKeyword): "break" # (0..5)
- (leading_trivia꞉ Whitespace): " " # (5..6)
- (root꞉ UNRECOGNIZED): "invalid " # (6..14)
- (unrecognized꞉ UNRECOGNIZED): "invalid " # (6..14)
- (semicolon꞉ Semicolon): ";" # (14..15)
- (trailing_trivia꞉ EndOfLine): "\n" # (15..16)
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Tree:
- (parameters꞉ Parameters): [] # (13..13)
- (close_paren꞉ CloseParen): ")" # (13..14)
- (attributes꞉ ConstructorAttributes): [] # (14..14)
- (root꞉ UNRECOGNIZED): " override {}\n" # (14..27)
- (unrecognized꞉ UNRECOGNIZED): " override {}\n" # (14..27)
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Tree:
- (parameters꞉ Parameters): [] # (13..13)
- (close_paren꞉ CloseParen): ")" # (13..14)
- (attributes꞉ ConstructorAttributes): [] # (14..14)
- (root꞉ UNRECOGNIZED): " override {}\n" # (14..27)
- (unrecognized꞉ UNRECOGNIZED): " override {}\n" # (14..27)
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Tree:
- (parameters꞉ Parameters): [] # (13..13)
- (close_paren꞉ CloseParen): ")" # (13..14)
- (attributes꞉ ConstructorAttributes): [] # (14..14)
- (root꞉ UNRECOGNIZED): " virtual {}\n" # (14..26)
- (unrecognized꞉ UNRECOGNIZED): " virtual {}\n" # (14..26)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ Tree:
- (leading_trivia꞉ Whitespace): "\t" # (113..114)
- (item꞉ Identifier): "constructor" # (114..125)
- (attributes꞉ StateVariableAttributes): [] # (125..125)
- (root꞉ UNRECOGNIZED): "() {}\n function func() public {\n\t\tuint256 const..." # (125..189)
- (unrecognized꞉ UNRECOGNIZED): "() {}\n function func() public {\n\t\tuint256 const..." # (125..189)
- (close_brace꞉ CloseBrace): "}" # (189..190)
- (trailing_trivia꞉ EndOfLine): "\n" # (190..191)
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Tree:
- (leading_trivia꞉ Whitespace): "\t\t" # (160..162)
- (variant꞉ UintKeyword): "uint256" # (162..169)
- (leading_trivia꞉ Whitespace): " " # (169..170)
- (root꞉ UNRECOGNIZED): "constructor" # (170..181)
- (unrecognized꞉ UNRECOGNIZED): "constructor" # (170..181)
- (semicolon꞉ Semicolon): ";" # (181..182)
- (trailing_trivia꞉ EndOfLine): "\n" # (182..183)
- (leading_trivia꞉ Whitespace): " " # (183..187)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Tree:
- (item꞉ Identifier): "emit" # (219..223)
- (leading_trivia꞉ Whitespace): " " # (223..224)
- (name꞉ Identifier): "Deposit" # (224..231)
- (root꞉ UNRECOGNIZED): "()" # (231..233)
- (unrecognized꞉ UNRECOGNIZED): "()" # (231..233)
- (semicolon꞉ Semicolon): ";" # (233..234)
- (trailing_trivia꞉ EndOfLine): "\n" # (234..235)
- (leading_trivia꞉ Whitespace): " " # (235..239)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Tree:
- (leading_trivia꞉ Whitespace): " " # (189..197)
- (variant꞉ UintKeyword): "uint256" # (197..204)
- (leading_trivia꞉ Whitespace): " " # (204..205)
- (root꞉ UNRECOGNIZED): "emit" # (205..209)
- (unrecognized꞉ UNRECOGNIZED): "emit" # (205..209)
- (semicolon꞉ Semicolon): ";" # (209..210)
- (trailing_trivia꞉ EndOfLine): "\n" # (210..211)
- (item꞉ Statement) ► (variant꞉ EmitStatement): # " emit Deposit();\n" (211..235)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Tree:
- (variant꞉ Identifier): "recipient" # (225..234)
- (period꞉ Period): "." # (234..235)
- (member꞉ Identifier): "call" # (235..239)
- (root꞉ UNRECOGNIZED): '{ value: amount }("")' # (239..260)
- (unrecognized꞉ UNRECOGNIZED): '{ value: amount }("")' # (239..260)
- (semicolon꞉ Semicolon): ";" # (260..261)
- (trailing_trivia꞉ EndOfLine): "\n" # (261..262)
- (item꞉ Statement) ► (variant꞉ ExpressionStatement): # ' require(success, "Address: unable to send valu...' (262..346)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Tree:
- (variant꞉ Identifier): "recipient" # (225..234)
- (period꞉ Period): "." # (234..235)
- (member꞉ Identifier): "call" # (235..239)
- (root꞉ UNRECOGNIZED): '{ value: amount }("")' # (239..260)
- (unrecognized꞉ UNRECOGNIZED): '{ value: amount }("")' # (239..260)
- (semicolon꞉ Semicolon): ";" # (260..261)
- (trailing_trivia꞉ EndOfLine): "\n" # (261..262)
- (item꞉ Statement) ► (variant꞉ ExpressionStatement): # ' require(success, "Address: unable to send valu...' (262..346)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Tree:
- (leading_trivia꞉ Whitespace): " " # (18..20)
- (item꞉ Identifier): "constructor" # (20..31)
- (attributes꞉ StateVariableAttributes): [] # (31..31)
- (root꞉ UNRECOGNIZED): "() public {\n }\n" # (31..47)
- (unrecognized꞉ UNRECOGNIZED): "() public {\n }\n" # (31..47)
- (close_brace꞉ CloseBrace): "}" # (47..48)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Tree:
- (attributes꞉ StateVariableAttributes): [] # (25..25)
- (leading_trivia꞉ Whitespace): " " # (25..26)
- (name꞉ Identifier): "Error1" # (26..32)
- (root꞉ UNRECOGNIZED): "()" # (32..34)
- (unrecognized꞉ UNRECOGNIZED): "()" # (32..34)
- (semicolon꞉ Semicolon): ";" # (34..35)
- (trailing_trivia꞉ EndOfLine): "\n" # (35..36)
- (close_brace꞉ CloseBrace): "}" # (36..37)
Loading

0 comments on commit 819da29

Please sign in to comment.