From ed1cd9eb3aefc3df46e7415eb4af02201cf508c2 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Sat, 10 Aug 2024 01:47:01 -0700 Subject: [PATCH] dedupe expected tokens in `ParseError` --- .../language/parser_support/recovery.rs | 5 +- .../parser_support/separated_helper.rs | 9 +- .../cargo/src/runtime/parse_error/mod.rs | 35 ++++---- .../language/parser_support/recovery.rs | 5 +- .../parser_support/separated_helper.rs | 9 +- .../src/generated/parse_error/mod.rs | 41 ++++----- .../generated/0.8.10-failure.yml | 84 ------------------- .../generated/0.8.10-failure.yml | 45 ---------- .../generated/0.8.10-failure.yml | 17 ---- .../generated/0.8.10-failure.yml | 17 ---- .../language/parser_support/recovery.rs | 5 +- .../parser_support/separated_helper.rs | 9 +- .../src/generated/parse_error/mod.rs | 41 ++++----- 13 files changed, 75 insertions(+), 247 deletions(-) delete mode 100644 crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.8.10-failure.yml delete mode 100644 crates/solidity/testing/snapshots/cst_output/YulBlock/multiple_stack_assignments/generated/0.8.10-failure.yml delete mode 100644 crates/solidity/testing/snapshots/cst_output/YulExpression/decimal_trailing_ident_start/generated/0.8.10-failure.yml delete mode 100644 crates/solidity/testing/snapshots/cst_output/YulExpression/hex_trailing_ident_start/generated/0.8.10-failure.yml diff --git a/crates/codegen/runtime/cargo/src/runtime/language/parser_support/recovery.rs b/crates/codegen/runtime/cargo/src/runtime/language/parser_support/recovery.rs index f28a2e5e08..5e6f19f423 100644 --- a/crates/codegen/runtime/cargo/src/runtime/language/parser_support/recovery.rs +++ b/crates/codegen/runtime/cargo/src/runtime/language/parser_support/recovery.rs @@ -90,10 +90,7 @@ impl ParserResult { let skipped = input.content(skipped_range.utf8()); - input.emit(ParseError { - text_range: skipped_range, - terminals_that_would_have_allowed_more_progress: expected_terminals.clone(), - }); + input.emit(ParseError::new(skipped_range, expected_terminals.clone())); ParserResult::SkippedUntil(SkippedUntil { nodes, diff --git a/crates/codegen/runtime/cargo/src/runtime/language/parser_support/separated_helper.rs b/crates/codegen/runtime/cargo/src/runtime/language/parser_support/separated_helper.rs index c4c0462057..0bd0801131 100644 --- a/crates/codegen/runtime/cargo/src/runtime/language/parser_support/separated_helper.rs +++ b/crates/codegen/runtime/cargo/src/runtime/language/parser_support/separated_helper.rs @@ -62,11 +62,10 @@ impl SeparatedHelper { kind, input.content(skipped_range.utf8()), ))); - input.emit(ParseError { - text_range: skipped_range, - terminals_that_would_have_allowed_more_progress: incomplete - .expected_terminals, - }); + input.emit(ParseError::new( + skipped_range, + incomplete.expected_terminals, + )); match lexer.parse_terminal_with_trivia::(input, separator) { ParserResult::Match(r#match) => { diff --git a/crates/codegen/runtime/cargo/src/runtime/parse_error/mod.rs b/crates/codegen/runtime/cargo/src/runtime/parse_error/mod.rs index e30d8a0495..041db8e620 100644 --- a/crates/codegen/runtime/cargo/src/runtime/parse_error/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/parse_error/mod.rs @@ -1,4 +1,3 @@ -use std::collections::BTreeSet; use std::fmt; use crate::diagnostic::{self, Diagnostic}; @@ -10,8 +9,8 @@ use crate::text_index::TextRange; /// This could have been caused by a syntax error, or by reaching the end of the file when more tokens were expected. #[derive(Debug, PartialEq, Eq, Clone)] pub struct ParseError { - pub(crate) text_range: TextRange, - pub(crate) terminals_that_would_have_allowed_more_progress: Vec, + text_range: TextRange, + terminals_that_would_have_allowed_more_progress: Vec, } impl ParseError { @@ -29,8 +28,11 @@ impl ParseError { impl ParseError { pub(crate) fn new( text_range: TextRange, - terminals_that_would_have_allowed_more_progress: Vec, + mut terminals_that_would_have_allowed_more_progress: Vec, ) -> Self { + terminals_that_would_have_allowed_more_progress.sort_unstable(); + terminals_that_would_have_allowed_more_progress.dedup(); + Self { text_range, terminals_that_would_have_allowed_more_progress, @@ -44,23 +46,22 @@ impl fmt::Display for ParseError { .terminals_that_would_have_allowed_more_progress .is_empty() { - write!(f, "Expected end of file.") - } else { - let deduped = self - .terminals_that_would_have_allowed_more_progress - .iter() - .collect::>(); + return write!(f, "Expected end of file."); + } - write!(f, "Expected ")?; + let mut expected = self.terminals_that_would_have_allowed_more_progress.iter(); - for kind in deduped.iter().take(deduped.len() - 1) { - write!(f, "{kind} or ")?; - } - let last = deduped.last().expect("we just checked that it's not empty"); - write!(f, "{last}.")?; + let first = expected + .next() + .expect("we just checked that it's not empty"); - Ok(()) + write!(f, "Expected {first}")?; + + for kind in expected { + write!(f, " or {kind}")?; } + + write!(f, ".") } } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/recovery.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/recovery.rs index 37c2c0a7e5..0de6aa3f92 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/recovery.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/recovery.rs @@ -92,10 +92,7 @@ impl ParserResult { let skipped = input.content(skipped_range.utf8()); - input.emit(ParseError { - text_range: skipped_range, - terminals_that_would_have_allowed_more_progress: expected_terminals.clone(), - }); + input.emit(ParseError::new(skipped_range, expected_terminals.clone())); ParserResult::SkippedUntil(SkippedUntil { nodes, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/separated_helper.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/separated_helper.rs index 0c4cb9d860..4897755a85 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/separated_helper.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/parser_support/separated_helper.rs @@ -64,11 +64,10 @@ impl SeparatedHelper { kind, input.content(skipped_range.utf8()), ))); - input.emit(ParseError { - text_range: skipped_range, - terminals_that_would_have_allowed_more_progress: incomplete - .expected_terminals, - }); + input.emit(ParseError::new( + skipped_range, + incomplete.expected_terminals, + )); match lexer.parse_terminal_with_trivia::(input, separator) { ParserResult::Match(r#match) => { diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parse_error/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parse_error/mod.rs index 5518734d2d..3683450568 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/parse_error/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/parse_error/mod.rs @@ -1,6 +1,5 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use std::collections::BTreeSet; use std::fmt; use crate::diagnostic::{self, Diagnostic}; @@ -12,8 +11,8 @@ use crate::text_index::TextRange; /// This could have been caused by a syntax error, or by reaching the end of the file when more tokens were expected. #[derive(Debug, PartialEq, Eq, Clone)] pub struct ParseError { - pub(crate) text_range: TextRange, - pub(crate) terminals_that_would_have_allowed_more_progress: Vec, + text_range: TextRange, + terminals_that_would_have_allowed_more_progress: Vec, } impl ParseError { @@ -31,8 +30,11 @@ impl ParseError { impl ParseError { pub(crate) fn new( text_range: TextRange, - terminals_that_would_have_allowed_more_progress: Vec, + mut terminals_that_would_have_allowed_more_progress: Vec, ) -> Self { + terminals_that_would_have_allowed_more_progress.sort_unstable(); + terminals_that_would_have_allowed_more_progress.dedup(); + Self { text_range, terminals_that_would_have_allowed_more_progress, @@ -46,23 +48,22 @@ impl fmt::Display for ParseError { .terminals_that_would_have_allowed_more_progress .is_empty() { - write!(f, "Expected end of file.") - } else { - let deduped = self - .terminals_that_would_have_allowed_more_progress - .iter() - .collect::>(); - - write!(f, "Expected ")?; - - for kind in deduped.iter().take(deduped.len() - 1) { - write!(f, "{kind} or ")?; - } - let last = deduped.last().expect("we just checked that it's not empty"); - write!(f, "{last}.")?; - - Ok(()) + return write!(f, "Expected end of file."); } + + let mut expected = self.terminals_that_would_have_allowed_more_progress.iter(); + + let first = expected + .next() + .expect("we just checked that it's not empty"); + + write!(f, "Expected {first}")?; + + for kind in expected { + write!(f, " or {kind}")?; + } + + write!(f, ".") } } diff --git a/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.8.10-failure.yml b/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.8.10-failure.yml deleted file mode 100644 index 43f766b12c..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.8.10-failure.yml +++ /dev/null @@ -1,84 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ { │ 0..1 - 2 │ function mult(a, b) -> result { │ 2..34 - 3 │ result := mul(a, b) │ 35..56 - 4 │ result := [mul(a, b) │ 57..79 - 5 │ } │ 80..82 - 6 │ } │ 83..84 - -Errors: # 1 total - - > - Error: Expected CloseBrace or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or OpenBrace or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or YulAddKeyword or YulAddModKeyword or YulAddressKeyword or YulAndKeyword or YulBalanceKeyword or YulBaseFeeKeyword or YulBlockHashKeyword or YulBreakKeyword or YulByteKeyword or YulCallCodeKeyword or YulCallDataCopyKeyword or YulCallDataLoadKeyword or YulCallDataSizeKeyword or YulCallKeyword or YulCallValueKeyword or YulCallerKeyword or YulChainIdKeyword or YulCoinBaseKeyword or YulContinueKeyword or YulCreate2Keyword or YulCreateKeyword or YulDecimalLiteral or YulDelegateCallKeyword or YulDifficultyKeyword or YulDivKeyword or YulEqKeyword or YulExpKeyword or YulExtCodeCopyKeyword or YulExtCodeHashKeyword or YulExtCodeSizeKeyword or YulFalseKeyword or YulForKeyword or YulFunctionKeyword or YulGasKeyword or YulGasLimitKeyword or YulGasPriceKeyword or YulGtKeyword or YulHexLiteral or YulIdentifier or YulIfKeyword or YulInvalidKeyword or YulIsZeroKeyword or YulKeccak256Keyword or YulLeaveKeyword or YulLetKeyword or YulLog0Keyword or YulLog1Keyword or YulLog2Keyword or YulLog3Keyword or YulLog4Keyword or YulLtKeyword or YulMLoadKeyword or YulMSizeKeyword or YulMStore8Keyword or YulMStoreKeyword or YulModKeyword or YulMulKeyword or YulMulModKeyword or YulNotKeyword or YulNumberKeyword or YulOrKeyword or YulOriginKeyword or YulPopKeyword or YulReturnDataCopyKeyword or YulReturnDataSizeKeyword or YulReturnKeyword or YulRevertKeyword or YulSDivKeyword or YulSLoadKeyword or YulSModKeyword or YulSStoreKeyword or YulSarKeyword or YulSelfBalanceKeyword or YulSelfDestructKeyword or YulSgtKeyword or YulShlKeyword or YulShrKeyword or YulSignExtendKeyword or YulSltKeyword or YulStaticCallKeyword or YulStopKeyword or YulSubKeyword or YulSwitchKeyword or YulTimestampKeyword or YulTrueKeyword or YulXorKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/input.sol:4:10] - │ - 4 │ ╭─▶ result := [mul(a, b) - 5 │ ├─▶ } - │ │ - │ ╰─────────── Error occurred here. - ───╯ - -Tree: - - (YulBlock): # "{\n\tfunction mult(a, b) -> result {\n\t\tresult := mul..." (0..85) - - (open_brace꞉ OpenBrace): "{" # (0..1) - - (trailing_trivia꞉ EndOfLine): "\n" # (1..2) - - (statements꞉ YulStatements): # "\tfunction mult(a, b) -> result {\n\t\tresult := mul(a..." (2..83) - - (item꞉ YulStatement) ► (variant꞉ YulFunctionDefinition): # "\tfunction mult(a, b) -> result {\n\t\tresult := mul(a..." (2..83) - - (leading_trivia꞉ Whitespace): "\t" # (2..3) - - (function_keyword꞉ YulFunctionKeyword): "function" # (3..11) - - (leading_trivia꞉ Whitespace): " " # (11..12) - - (name꞉ YulIdentifier): "mult" # (12..16) - - (parameters꞉ YulParametersDeclaration): # "(a, b)" (16..22) - - (open_paren꞉ OpenParen): "(" # (16..17) - - (parameters꞉ YulParameters): # "a, b" (17..21) - - (item꞉ YulIdentifier): "a" # (17..18) - - (separator꞉ Comma): "," # (18..19) - - (leading_trivia꞉ Whitespace): " " # (19..20) - - (item꞉ YulIdentifier): "b" # (20..21) - - (close_paren꞉ CloseParen): ")" # (21..22) - - (returns꞉ YulReturnsDeclaration): # " -> result" (22..32) - - (leading_trivia꞉ Whitespace): " " # (22..23) - - (minus_greater_than꞉ MinusGreaterThan): "->" # (23..25) - - (variables꞉ YulVariableNames): # " result" (25..32) - - (leading_trivia꞉ Whitespace): " " # (25..26) - - (item꞉ YulIdentifier): "result" # (26..32) - - (body꞉ YulBlock): # " {\n\t\tresult := mul(a, b)\n\t\tresult := [mul(a, b)\n\t}..." (32..83) - - (leading_trivia꞉ Whitespace): " " # (32..33) - - (open_brace꞉ OpenBrace): "{" # (33..34) - - (trailing_trivia꞉ EndOfLine): "\n" # (34..35) - - (statements꞉ YulStatements): # "\t\tresult := mul(a, b)\n\t\tresult" (35..65) - - (item꞉ YulStatement) ► (variant꞉ YulVariableAssignmentStatement): # "\t\tresult := mul(a, b)\n" (35..57) - - (variables꞉ YulPaths): # "\t\tresult" (35..43) - - (item꞉ YulPath): # "\t\tresult" (35..43) - - (item꞉ YulPathComponent): # "\t\tresult" (35..43) - - (leading_trivia꞉ Whitespace): "\t\t" # (35..37) - - (variant꞉ YulIdentifier): "result" # (37..43) - - (assignment꞉ YulAssignmentOperator): # " :=" (43..46) - - (leading_trivia꞉ Whitespace): " " # (43..44) - - (variant꞉ ColonEqual): ":=" # (44..46) - - (expression꞉ YulExpression) ► (variant꞉ YulFunctionCallExpression): # " mul(a, b)\n" (46..57) - - (operand꞉ YulExpression) ► (variant꞉ YulBuiltInFunction): # " mul" (46..50) - - (leading_trivia꞉ Whitespace): " " # (46..47) - - (variant꞉ YulMulKeyword): "mul" # (47..50) - - (open_paren꞉ OpenParen): "(" # (50..51) - - (arguments꞉ YulArguments): # "a, b" (51..55) - - (item꞉ YulExpression) ► (variant꞉ YulPath): # "a" (51..52) - - (item꞉ YulPathComponent) ► (variant꞉ YulIdentifier): "a" # (51..52) - - (separator꞉ Comma): "," # (52..53) - - (item꞉ YulExpression) ► (variant꞉ YulPath): # " b" (53..55) - - (item꞉ YulPathComponent): # " b" (53..55) - - (leading_trivia꞉ Whitespace): " " # (53..54) - - (variant꞉ YulIdentifier): "b" # (54..55) - - (close_paren꞉ CloseParen): ")" # (55..56) - - (trailing_trivia꞉ EndOfLine): "\n" # (56..57) - - (item꞉ YulStatement) ► (variant꞉ YulExpression) ► (variant꞉ YulPath): # "\t\tresult" (57..65) - - (item꞉ YulPathComponent): # "\t\tresult" (57..65) - - (leading_trivia꞉ Whitespace): "\t\t" # (57..59) - - (variant꞉ YulIdentifier): "result" # (59..65) - - (leading_trivia꞉ Whitespace): " " # (65..66) - - (UNRECOGNIZED): ":= [mul(a, b)\n\t" # (66..81) - - (close_brace꞉ CloseBrace): "}" # (81..82) - - (trailing_trivia꞉ EndOfLine): "\n" # (82..83) - - (close_brace꞉ CloseBrace): "}" # (83..84) - - (trailing_trivia꞉ EndOfLine): "\n" # (84..85) diff --git a/crates/solidity/testing/snapshots/cst_output/YulBlock/multiple_stack_assignments/generated/0.8.10-failure.yml b/crates/solidity/testing/snapshots/cst_output/YulBlock/multiple_stack_assignments/generated/0.8.10-failure.yml deleted file mode 100644 index 1e429c2819..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/YulBlock/multiple_stack_assignments/generated/0.8.10-failure.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ { │ 0..1 - 2 │ 1 │ 2..5 - 3 │ 2 │ 6..9 - 4 │ 3 │ 10..13 - 5 │ =: success │ 14..26 - 6 │ =: success │ 27..39 - 7 │ =: success │ 40..52 - 8 │ } │ 53..54 - -Errors: # 1 total - - > - Error: Expected CloseBrace or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or OpenBrace or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or YulAddKeyword or YulAddModKeyword or YulAddressKeyword or YulAndKeyword or YulBalanceKeyword or YulBaseFeeKeyword or YulBlockHashKeyword or YulBreakKeyword or YulByteKeyword or YulCallCodeKeyword or YulCallDataCopyKeyword or YulCallDataLoadKeyword or YulCallDataSizeKeyword or YulCallKeyword or YulCallValueKeyword or YulCallerKeyword or YulChainIdKeyword or YulCoinBaseKeyword or YulContinueKeyword or YulCreate2Keyword or YulCreateKeyword or YulDecimalLiteral or YulDelegateCallKeyword or YulDifficultyKeyword or YulDivKeyword or YulEqKeyword or YulExpKeyword or YulExtCodeCopyKeyword or YulExtCodeHashKeyword or YulExtCodeSizeKeyword or YulFalseKeyword or YulForKeyword or YulFunctionKeyword or YulGasKeyword or YulGasLimitKeyword or YulGasPriceKeyword or YulGtKeyword or YulHexLiteral or YulIdentifier or YulIfKeyword or YulInvalidKeyword or YulIsZeroKeyword or YulKeccak256Keyword or YulLeaveKeyword or YulLetKeyword or YulLog0Keyword or YulLog1Keyword or YulLog2Keyword or YulLog3Keyword or YulLog4Keyword or YulLtKeyword or YulMLoadKeyword or YulMSizeKeyword or YulMStore8Keyword or YulMStoreKeyword or YulModKeyword or YulMulKeyword or YulMulModKeyword or YulNotKeyword or YulNumberKeyword or YulOrKeyword or YulOriginKeyword or YulPopKeyword or YulReturnDataCopyKeyword or YulReturnDataSizeKeyword or YulReturnKeyword or YulRevertKeyword or YulSDivKeyword or YulSLoadKeyword or YulSModKeyword or YulSStoreKeyword or YulSarKeyword or YulSelfBalanceKeyword or YulSelfDestructKeyword or YulSgtKeyword or YulShlKeyword or YulShrKeyword or YulSignExtendKeyword or YulSltKeyword or YulStaticCallKeyword or YulStopKeyword or YulSubKeyword or YulSwitchKeyword or YulTimestampKeyword or YulTrueKeyword or YulXorKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/YulBlock/multiple_stack_assignments/input.sol:5:3] - │ - 5 │ ╭─▶ =: success - ┆ ┆ - 7 │ ├─▶ =: success - │ │ - │ ╰────────────────── Error occurred here. - ───╯ - -Tree: - - (YulBlock): # "{\n 1\n 2\n 3\n =: success\n =: success\n =: succe..." (0..55) - - (open_brace꞉ OpenBrace): "{" # (0..1) - - (trailing_trivia꞉ EndOfLine): "\n" # (1..2) - - (statements꞉ YulStatements): # " 1\n 2\n 3\n" (2..14) - - (item꞉ YulStatement) ► (variant꞉ YulExpression) ► (variant꞉ YulLiteral): # " 1\n" (2..6) - - (leading_trivia꞉ Whitespace): " " # (2..4) - - (variant꞉ YulDecimalLiteral): "1" # (4..5) - - (trailing_trivia꞉ EndOfLine): "\n" # (5..6) - - (item꞉ YulStatement) ► (variant꞉ YulExpression) ► (variant꞉ YulLiteral): # " 2\n" (6..10) - - (leading_trivia꞉ Whitespace): " " # (6..8) - - (variant꞉ YulDecimalLiteral): "2" # (8..9) - - (trailing_trivia꞉ EndOfLine): "\n" # (9..10) - - (item꞉ YulStatement) ► (variant꞉ YulExpression) ► (variant꞉ YulLiteral): # " 3\n" (10..14) - - (leading_trivia꞉ Whitespace): " " # (10..12) - - (variant꞉ YulDecimalLiteral): "3" # (12..13) - - (trailing_trivia꞉ EndOfLine): "\n" # (13..14) - - (leading_trivia꞉ Whitespace): " " # (14..16) - - (UNRECOGNIZED): "=: success\n =: success\n =: success\n" # (16..53) - - (close_brace꞉ CloseBrace): "}" # (53..54) - - (trailing_trivia꞉ EndOfLine): "\n" # (54..55) diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/decimal_trailing_ident_start/generated/0.8.10-failure.yml b/crates/solidity/testing/snapshots/cst_output/YulExpression/decimal_trailing_ident_start/generated/0.8.10-failure.yml deleted file mode 100644 index 4a20fefc34..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/YulExpression/decimal_trailing_ident_start/generated/0.8.10-failure.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ 1a │ 0..2 - -Errors: # 1 total - - > - Error: Expected DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or YulAddKeyword or YulAddModKeyword or YulAddressKeyword or YulAndKeyword or YulBalanceKeyword or YulBaseFeeKeyword or YulBlockHashKeyword or YulByteKeyword or YulCallCodeKeyword or YulCallDataCopyKeyword or YulCallDataLoadKeyword or YulCallDataSizeKeyword or YulCallKeyword or YulCallValueKeyword or YulCallerKeyword or YulChainIdKeyword or YulCoinBaseKeyword or YulCreate2Keyword or YulCreateKeyword or YulDecimalLiteral or YulDelegateCallKeyword or YulDifficultyKeyword or YulDivKeyword or YulEqKeyword or YulExpKeyword or YulExtCodeCopyKeyword or YulExtCodeHashKeyword or YulExtCodeSizeKeyword or YulFalseKeyword or YulGasKeyword or YulGasLimitKeyword or YulGasPriceKeyword or YulGtKeyword or YulHexLiteral or YulIdentifier or YulInvalidKeyword or YulIsZeroKeyword or YulKeccak256Keyword or YulLog0Keyword or YulLog1Keyword or YulLog2Keyword or YulLog3Keyword or YulLog4Keyword or YulLtKeyword or YulMLoadKeyword or YulMSizeKeyword or YulMStore8Keyword or YulMStoreKeyword or YulModKeyword or YulMulKeyword or YulMulModKeyword or YulNotKeyword or YulNumberKeyword or YulOrKeyword or YulOriginKeyword or YulPopKeyword or YulReturnDataCopyKeyword or YulReturnDataSizeKeyword or YulReturnKeyword or YulRevertKeyword or YulSDivKeyword or YulSLoadKeyword or YulSModKeyword or YulSStoreKeyword or YulSarKeyword or YulSelfBalanceKeyword or YulSelfDestructKeyword or YulSgtKeyword or YulShlKeyword or YulShrKeyword or YulSignExtendKeyword or YulSltKeyword or YulStaticCallKeyword or YulStopKeyword or YulSubKeyword or YulTimestampKeyword or YulTrueKeyword or YulXorKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/YulExpression/decimal_trailing_ident_start/input.sol:1:1] - │ - 1 │ 1a - │ ─┬─ - │ ╰─── Error occurred here. - ───╯ - -Tree: - - (UNRECOGNIZED): "1a\n" # (0..3) diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/hex_trailing_ident_start/generated/0.8.10-failure.yml b/crates/solidity/testing/snapshots/cst_output/YulExpression/hex_trailing_ident_start/generated/0.8.10-failure.yml deleted file mode 100644 index 66cc443373..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/YulExpression/hex_trailing_ident_start/generated/0.8.10-failure.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ 0x1$ │ 0..4 - -Errors: # 1 total - - > - Error: Expected DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or YulAddKeyword or YulAddModKeyword or YulAddressKeyword or YulAndKeyword or YulBalanceKeyword or YulBaseFeeKeyword or YulBlockHashKeyword or YulByteKeyword or YulCallCodeKeyword or YulCallDataCopyKeyword or YulCallDataLoadKeyword or YulCallDataSizeKeyword or YulCallKeyword or YulCallValueKeyword or YulCallerKeyword or YulChainIdKeyword or YulCoinBaseKeyword or YulCreate2Keyword or YulCreateKeyword or YulDecimalLiteral or YulDelegateCallKeyword or YulDifficultyKeyword or YulDivKeyword or YulEqKeyword or YulExpKeyword or YulExtCodeCopyKeyword or YulExtCodeHashKeyword or YulExtCodeSizeKeyword or YulFalseKeyword or YulGasKeyword or YulGasLimitKeyword or YulGasPriceKeyword or YulGtKeyword or YulHexLiteral or YulIdentifier or YulInvalidKeyword or YulIsZeroKeyword or YulKeccak256Keyword or YulLog0Keyword or YulLog1Keyword or YulLog2Keyword or YulLog3Keyword or YulLog4Keyword or YulLtKeyword or YulMLoadKeyword or YulMSizeKeyword or YulMStore8Keyword or YulMStoreKeyword or YulModKeyword or YulMulKeyword or YulMulModKeyword or YulNotKeyword or YulNumberKeyword or YulOrKeyword or YulOriginKeyword or YulPopKeyword or YulReturnDataCopyKeyword or YulReturnDataSizeKeyword or YulReturnKeyword or YulRevertKeyword or YulSDivKeyword or YulSLoadKeyword or YulSModKeyword or YulSStoreKeyword or YulSarKeyword or YulSelfBalanceKeyword or YulSelfDestructKeyword or YulSgtKeyword or YulShlKeyword or YulShrKeyword or YulSignExtendKeyword or YulSltKeyword or YulStaticCallKeyword or YulStopKeyword or YulSubKeyword or YulTimestampKeyword or YulTrueKeyword or YulXorKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/YulExpression/hex_trailing_ident_start/input.sol:1:1] - │ - 1 │ 0x1$ - │ ──┬── - │ ╰──── Error occurred here. - ───╯ - -Tree: - - (UNRECOGNIZED): "0x1$\n" # (0..5) diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/recovery.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/recovery.rs index 37c2c0a7e5..0de6aa3f92 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/recovery.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/recovery.rs @@ -92,10 +92,7 @@ impl ParserResult { let skipped = input.content(skipped_range.utf8()); - input.emit(ParseError { - text_range: skipped_range, - terminals_that_would_have_allowed_more_progress: expected_terminals.clone(), - }); + input.emit(ParseError::new(skipped_range, expected_terminals.clone())); ParserResult::SkippedUntil(SkippedUntil { nodes, diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/separated_helper.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/separated_helper.rs index 0c4cb9d860..4897755a85 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/separated_helper.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/language/parser_support/separated_helper.rs @@ -64,11 +64,10 @@ impl SeparatedHelper { kind, input.content(skipped_range.utf8()), ))); - input.emit(ParseError { - text_range: skipped_range, - terminals_that_would_have_allowed_more_progress: incomplete - .expected_terminals, - }); + input.emit(ParseError::new( + skipped_range, + incomplete.expected_terminals, + )); match lexer.parse_terminal_with_trivia::(input, separator) { ParserResult::Match(r#match) => { diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parse_error/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parse_error/mod.rs index 5518734d2d..3683450568 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/parse_error/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/parse_error/mod.rs @@ -1,6 +1,5 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use std::collections::BTreeSet; use std::fmt; use crate::diagnostic::{self, Diagnostic}; @@ -12,8 +11,8 @@ use crate::text_index::TextRange; /// This could have been caused by a syntax error, or by reaching the end of the file when more tokens were expected. #[derive(Debug, PartialEq, Eq, Clone)] pub struct ParseError { - pub(crate) text_range: TextRange, - pub(crate) terminals_that_would_have_allowed_more_progress: Vec, + text_range: TextRange, + terminals_that_would_have_allowed_more_progress: Vec, } impl ParseError { @@ -31,8 +30,11 @@ impl ParseError { impl ParseError { pub(crate) fn new( text_range: TextRange, - terminals_that_would_have_allowed_more_progress: Vec, + mut terminals_that_would_have_allowed_more_progress: Vec, ) -> Self { + terminals_that_would_have_allowed_more_progress.sort_unstable(); + terminals_that_would_have_allowed_more_progress.dedup(); + Self { text_range, terminals_that_would_have_allowed_more_progress, @@ -46,23 +48,22 @@ impl fmt::Display for ParseError { .terminals_that_would_have_allowed_more_progress .is_empty() { - write!(f, "Expected end of file.") - } else { - let deduped = self - .terminals_that_would_have_allowed_more_progress - .iter() - .collect::>(); - - write!(f, "Expected ")?; - - for kind in deduped.iter().take(deduped.len() - 1) { - write!(f, "{kind} or ")?; - } - let last = deduped.last().expect("we just checked that it's not empty"); - write!(f, "{last}.")?; - - Ok(()) + return write!(f, "Expected end of file."); } + + let mut expected = self.terminals_that_would_have_allowed_more_progress.iter(); + + let first = expected + .next() + .expect("we just checked that it's not empty"); + + write!(f, "Expected {first}")?; + + for kind in expected { + write!(f, " or {kind}")?; + } + + write!(f, ".") } }