Skip to content

Commit

Permalink
fix: Naively recover the Pratt matches when recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Jul 11, 2024
1 parent 8ab7484 commit e790003
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,17 @@ impl SequenceHelper {
}));
}

(ParserResult::PrattOperatorMatch(_), ParserResult::SkippedUntil(_)) =>
unreachable!("Error recovery happens outside precedence parsing"),
(ParserResult::PrattOperatorMatch(running), ParserResult::SkippedUntil(skipped)) => {
let nodes: Vec<_> = std::mem::take(&mut running.elements)
.into_iter()
.flat_map(PrattElement::into_nodes)
.collect();

self.result = State::Running(ParserResult::SkippedUntil(SkippedUntil {
nodes,
..skipped
}));
}

// Try to recover until we hit an expected boundary terminal.
// If the sequence is unwinding, then a subsequent non-empty match must mean that
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
@@ -0,0 +1,57 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ contract A { │ 0..12
2 │ function a() { │ 13..28
3 │ 2 + ( │ 29..36
4 │ } │ 37..39
5 │ } │ 40..41
Errors: # 1 total
- >
Error: Expected CloseParen or Comma.
╭─[crates/solidity/testing/snapshots/cst_output/SourceUnit/pratt_precedence_recovery/input.sol:4:2]
4 │ }
│ │
│ ╰─ Error occurred here.
───╯
Tree:
- (SourceUnit) ► (members꞉ SourceUnitMembers): # "contract A {\n\tfunction a() {\n\t\t2 + (\n\t" (0..38)
- (item꞉ SourceUnitMember) ► (variant꞉ ContractDefinition): # "contract A {\n\tfunction a() {\n\t\t2 + (\n\t" (0..38)
- (contract_keyword꞉ ContractKeyword): "contract" # (0..8)
- (leading_trivia꞉ Whitespace): " " # (8..9)
- (name꞉ Identifier): "A" # (9..10)
- (leading_trivia꞉ Whitespace): " " # (10..11)
- (open_brace꞉ OpenBrace): "{" # (11..12)
- (trailing_trivia꞉ EndOfLine): "\n" # (12..13)
- (members꞉ ContractMembers): # "\tfunction a() {\n\t\t2 + (" (13..36)
- (item꞉ ContractMember) ► (variant꞉ FunctionDefinition): # "\tfunction a() {\n\t\t2 + (" (13..36)
- (leading_trivia꞉ Whitespace): "\t" # (13..14)
- (function_keyword꞉ FunctionKeyword): "function" # (14..22)
- (name꞉ FunctionName): # " a" (22..24)
- (leading_trivia꞉ Whitespace): " " # (22..23)
- (variant꞉ Identifier): "a" # (23..24)
- (parameters꞉ ParametersDeclaration): # "()" (24..26)
- (open_paren꞉ OpenParen): "(" # (24..25)
- (parameters꞉ Parameters): [] # (25..25)
- (close_paren꞉ CloseParen): ")" # (25..26)
- (attributes꞉ FunctionAttributes): [] # (26..26)
- (body꞉ FunctionBody) ► (variant꞉ Block): # " {\n\t\t2 + (" (26..36)
- (leading_trivia꞉ Whitespace): " " # (26..27)
- (open_brace꞉ OpenBrace): "{" # (27..28)
- (trailing_trivia꞉ EndOfLine): "\n" # (28..29)
- (statements꞉ Statements): # "\t\t2 +" (29..34)
- (item꞉ Statement) ► (variant꞉ ExpressionStatement) ► (expression꞉ Expression): # "\t\t2 +" (29..34)
- (variant꞉ DecimalNumberExpression): # "\t\t2" (29..32)
- (leading_trivia꞉ Whitespace): "\t\t" # (29..31)
- (literal꞉ DecimalLiteral): "2" # (31..32)
- (AdditiveExpression): # " +" (32..34)
- (leading_trivia꞉ Whitespace): " " # (32..33)
- (operator꞉ Plus): "+" # (33..34)
- (MISSING): "" # (34..34)
- (close_brace꞉ CloseBrace): " " # (34..35)
- (trailing_trivia꞉ EndOfLine): "(" # (35..36)
- (close_brace꞉ CloseBrace): "\n" # (36..37)
- (trailing_trivia꞉ EndOfLine): "\t" # (37..38)

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

0 comments on commit e790003

Please sign in to comment.