diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 591517ee15..c06e26e9a5 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -270,8 +270,7 @@ codegen_language_macros::compile!(Language( Separated( name = ImportDeconstructionFields, separated = ImportDeconstructionField, - separator = Comma, - allow_empty = true + separator = Comma ), Struct( name = ImportDeconstructionField, @@ -335,8 +334,7 @@ codegen_language_macros::compile!(Language( name = UsingDeconstructionFields, separated = UsingDeconstructionField, separator = Comma, - enabled = From("0.8.13"), - allow_empty = true + enabled = From("0.8.13") ), Struct( name = UsingDeconstructionField, @@ -2377,14 +2375,20 @@ codegen_language_macros::compile!(Language( ), Struct( name = OverrideSpecifier, + fields = ( + override_keyword = Required(Terminal([OverrideKeyword])), + overridden = Optional(kind = NonTerminal(OverridePathsDeclaration)) + ) + ), + Struct( + name = OverridePathsDeclaration, error_recovery = FieldsErrorRecovery( delimiters = FieldDelimiters(open = open_paren, close = close_paren) ), fields = ( - override_keyword = Required(Terminal([OverrideKeyword])), open_paren = Required(Terminal([OpenParen])), - overridden = Optional(kind = NonTerminal(OverridePaths)), + paths = Required(NonTerminal(OverridePaths)), close_paren = Required(Terminal([CloseParen])) ) ), @@ -2904,8 +2908,7 @@ codegen_language_macros::compile!(Language( Separated( name = TupleMembersDeconstruction, separated = TupleMemberDeconstruction, - separator = Comma, - allow_empty = true + separator = Comma ), Struct( name = TupleMemberDeconstruction, diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/FunctionDefinition.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/FunctionDefinition.rs index dbc7bea631..1d787aba16 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/FunctionDefinition.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/FunctionDefinition.rs @@ -12,3 +12,8 @@ fn constant_state_mutability() -> Result<()> { fn from_contextual_keyword() -> Result<()> { return run("FunctionDefinition", "from_contextual_keyword"); } + +#[test] +fn overridden() -> Result<()> { + return run("FunctionDefinition", "overridden"); +} diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/ImportDirective.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/ImportDirective.rs index 3f9120185b..4386544ba0 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/ImportDirective.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/ImportDirective.rs @@ -3,6 +3,11 @@ use crate::cst_output::runner::run; use anyhow::Result; +#[test] +fn destructure_import_empty() -> Result<()> { + return run("ImportDirective", "destructure_import_empty"); +} + #[test] fn destructure_import_multiple() -> Result<()> { return run("ImportDirective", "destructure_import_multiple"); diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/TupleDeconstructionStatement.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/TupleDeconstructionStatement.rs index 19200872a6..1f69153b8c 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/TupleDeconstructionStatement.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/TupleDeconstructionStatement.rs @@ -13,6 +13,11 @@ fn abi_decode_singleton_type() -> Result<()> { return run("TupleDeconstructionStatement", "abi_decode_singleton_type"); } +#[test] +fn empty() -> Result<()> { + return run("TupleDeconstructionStatement", "empty"); +} + #[test] fn ignored_members() -> Result<()> { return run("TupleDeconstructionStatement", "ignored_members"); diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UsingDirective.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UsingDirective.rs index 6401e7931a..fcb067f8b8 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UsingDirective.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UsingDirective.rs @@ -3,6 +3,11 @@ use crate::cst_output::runner::run; use anyhow::Result; +#[test] +fn destructure_empty() -> Result<()> { + return run("UsingDirective", "destructure_empty"); +} + #[test] fn destructure_multiple() -> Result<()> { return run("UsingDirective", "destructure_multiple"); diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.4.11-success.yml new file mode 100644 index 0000000000..a33d2168ca --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.4.11-success.yml @@ -0,0 +1,43 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function some() public virtual override returns (uint256) { │ 0..59 + 2 │ return 1; │ 60..70 + 3 │ } │ 71..72 + +Errors: [] + +Tree: + - FunctionDefinition (Rule): # 0..73 "function some() public virtual override returns (u..." + - FunctionKeyword (Token): "function" # 0..8 + - Identifier (Token): "some" # 9..13 + - ParametersDeclaration (Rule): # 13..15 "()" + - OpenParen (Token): "(" # 13..14 + - CloseParen (Token): ")" # 14..15 + - FunctionAttributes (Rule): # 15..39 " public virtual override" + - PublicKeyword (Token): "public" # 16..22 + - ModifierInvocation (Rule): # 22..30 " virtual" + - IdentifierPath (Rule): # 22..30 " virtual" + - Identifier (Token): "virtual" # 23..30 + - ModifierInvocation (Rule): # 30..39 " override" + - IdentifierPath (Rule): # 30..39 " override" + - Identifier (Token): "override" # 31..39 + - ReturnsDeclaration (Rule): # 39..57 " returns (uint256)" + - ReturnsKeyword (Token): "returns" # 40..47 + - ParametersDeclaration (Rule): # 47..57 " (uint256)" + - OpenParen (Token): "(" # 48..49 + - Parameters (Rule): # 49..56 "uint256" + - Parameter (Rule): # 49..56 "uint256" + - TypeName (Rule): # 49..56 "uint256" + - UintKeyword (Token): "uint256" # 49..56 + - CloseParen (Token): ")" # 56..57 + - Block (Rule): # 57..73 " {\n\treturn 1;\n}\n" + - OpenBrace (Token): "{" # 58..59 + - Statements (Rule): # 60..71 "\treturn 1;\n" + - ReturnStatement (Rule): # 60..71 "\treturn 1;\n" + - ReturnKeyword (Token): "return" # 61..67 + - Expression (Rule): # 67..69 " 1" + - DecimalNumberExpression (Rule): # 67..69 " 1" + - DecimalLiteral (Token): "1" # 68..69 + - Semicolon (Token): ";" # 69..70 + - CloseBrace (Token): "}" # 71..72 diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.5.0-success.yml b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.5.0-success.yml new file mode 100644 index 0000000000..5251653a74 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.5.0-success.yml @@ -0,0 +1,42 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function some() public virtual override returns (uint256) { │ 0..59 + 2 │ return 1; │ 60..70 + 3 │ } │ 71..72 + +Errors: [] + +Tree: + - FunctionDefinition (Rule): # 0..73 "function some() public virtual override returns (u..." + - FunctionKeyword (Token): "function" # 0..8 + - Identifier (Token): "some" # 9..13 + - ParametersDeclaration (Rule): # 13..15 "()" + - OpenParen (Token): "(" # 13..14 + - CloseParen (Token): ")" # 14..15 + - FunctionAttributes (Rule): # 15..39 " public virtual override" + - PublicKeyword (Token): "public" # 16..22 + - ModifierInvocation (Rule): # 22..30 " virtual" + - IdentifierPath (Rule): # 22..30 " virtual" + - Identifier (Token): "virtual" # 23..30 + - OverrideSpecifier (Rule): # 30..39 " override" + - OverrideKeyword (Token): "override" # 31..39 + - ReturnsDeclaration (Rule): # 39..57 " returns (uint256)" + - ReturnsKeyword (Token): "returns" # 40..47 + - ParametersDeclaration (Rule): # 47..57 " (uint256)" + - OpenParen (Token): "(" # 48..49 + - Parameters (Rule): # 49..56 "uint256" + - Parameter (Rule): # 49..56 "uint256" + - TypeName (Rule): # 49..56 "uint256" + - UintKeyword (Token): "uint256" # 49..56 + - CloseParen (Token): ")" # 56..57 + - Block (Rule): # 57..73 " {\n\treturn 1;\n}\n" + - OpenBrace (Token): "{" # 58..59 + - Statements (Rule): # 60..71 "\treturn 1;\n" + - ReturnStatement (Rule): # 60..71 "\treturn 1;\n" + - ReturnKeyword (Token): "return" # 61..67 + - Expression (Rule): # 67..69 " 1" + - DecimalNumberExpression (Rule): # 67..69 " 1" + - DecimalLiteral (Token): "1" # 68..69 + - Semicolon (Token): ";" # 69..70 + - CloseBrace (Token): "}" # 71..72 diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.6.0-success.yml b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.6.0-success.yml new file mode 100644 index 0000000000..af203a42ed --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/generated/0.6.0-success.yml @@ -0,0 +1,40 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function some() public virtual override returns (uint256) { │ 0..59 + 2 │ return 1; │ 60..70 + 3 │ } │ 71..72 + +Errors: [] + +Tree: + - FunctionDefinition (Rule): # 0..73 "function some() public virtual override returns (u..." + - FunctionKeyword (Token): "function" # 0..8 + - Identifier (Token): "some" # 9..13 + - ParametersDeclaration (Rule): # 13..15 "()" + - OpenParen (Token): "(" # 13..14 + - CloseParen (Token): ")" # 14..15 + - FunctionAttributes (Rule): # 15..39 " public virtual override" + - PublicKeyword (Token): "public" # 16..22 + - VirtualKeyword (Token): "virtual" # 23..30 + - OverrideSpecifier (Rule): # 30..39 " override" + - OverrideKeyword (Token): "override" # 31..39 + - ReturnsDeclaration (Rule): # 39..57 " returns (uint256)" + - ReturnsKeyword (Token): "returns" # 40..47 + - ParametersDeclaration (Rule): # 47..57 " (uint256)" + - OpenParen (Token): "(" # 48..49 + - Parameters (Rule): # 49..56 "uint256" + - Parameter (Rule): # 49..56 "uint256" + - TypeName (Rule): # 49..56 "uint256" + - UintKeyword (Token): "uint256" # 49..56 + - CloseParen (Token): ")" # 56..57 + - Block (Rule): # 57..73 " {\n\treturn 1;\n}\n" + - OpenBrace (Token): "{" # 58..59 + - Statements (Rule): # 60..71 "\treturn 1;\n" + - ReturnStatement (Rule): # 60..71 "\treturn 1;\n" + - ReturnKeyword (Token): "return" # 61..67 + - Expression (Rule): # 67..69 " 1" + - DecimalNumberExpression (Rule): # 67..69 " 1" + - DecimalLiteral (Token): "1" # 68..69 + - Semicolon (Token): ";" # 69..70 + - CloseBrace (Token): "}" # 71..72 diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/input.sol b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/input.sol new file mode 100644 index 0000000000..a19a35d522 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/overridden/input.sol @@ -0,0 +1,3 @@ +function some() public virtual override returns (uint256) { + return 1; +} diff --git a/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/generated/0.4.11-failure.yml new file mode 100644 index 0000000000..e23efb2ed3 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/generated/0.4.11-failure.yml @@ -0,0 +1,28 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Empty imports are not valid │ 0..30 + 2 │ import {} from "foo"; │ 31..52 + +Errors: # 1 total + - > + Error: Expected Identifier. + ╭─[crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/input.sol:2:9] + │ + 2 │ import {} from "foo"; + │ │ + │ ╰─ Error occurred here. + ───╯ + +Tree: + - ImportDirective (Rule): # 0..53 '// Empty imports are not valid\nimport {} from "foo...' + - LeadingTrivia (Rule): # 0..31 "// Empty imports are not valid\n" + - SingleLineComment (Trivia): "// Empty imports are not valid" # 0..30 + - ImportKeyword (Token): "import" # 31..37 + - DeconstructionImport (Rule): # 37..51 ' {} from "foo"' + - OpenBrace (Token): "{" # 38..39 + - SKIPPED (Token): "" # 39..39 + - CloseBrace (Token): "}" # 39..40 + - FromKeyword (Token): "from" # 41..45 + - AsciiStringLiteral (Token): '"foo"' # 46..51 + - Semicolon (Token): ";" # 51..52 diff --git a/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/input.sol b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/input.sol new file mode 100644 index 0000000000..141a62bfc7 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_empty/input.sol @@ -0,0 +1,2 @@ +// Empty imports are not valid +import {} from "foo"; diff --git a/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/empty/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/empty/generated/0.4.11-success.yml new file mode 100644 index 0000000000..c0a51fad70 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/empty/generated/0.4.11-success.yml @@ -0,0 +1,23 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // TODO(#671): Tuple expressions can't be empty │ 0..47 + 2 │ () = (); │ 48..56 + +Errors: [] + +Tree: + - TupleDeconstructionStatement (Rule): # 0..57 "// TODO(#671): Tuple expressions can't be empty\n()..." + - LeadingTrivia (Rule): # 0..48 "// TODO(#671): Tuple expressions can't be empty\n" + - SingleLineComment (Trivia): "// TODO(#671): Tuple expressions can't be empty" # 0..47 + - OpenParen (Token): "(" # 48..49 + - TupleMembers (Rule): # 49..49 + - TupleMember (Rule): [] # 49..49 + - CloseParen (Token): ")" # 49..50 + - Equal (Token): "=" # 51..52 + - Expression (Rule): # 52..55 " ()" + - TupleExpression (Rule): # 52..55 " ()" + - OpenParen (Token): "(" # 53..54 + - TupleValues (Rule): [] # 54..54 + - CloseParen (Token): ")" # 54..55 + - Semicolon (Token): ";" # 55..56 diff --git a/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/empty/input.sol b/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/empty/input.sol new file mode 100644 index 0000000000..289f15d3d2 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/TupleDeconstructionStatement/empty/input.sol @@ -0,0 +1,2 @@ +// TODO(#671): Tuple expressions can't be empty +() = (); diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/generated/0.4.11-failure.yml new file mode 100644 index 0000000000..248eb68b5c --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/generated/0.4.11-failure.yml @@ -0,0 +1,23 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Empty using symbols list is not valid │ 0..40 + 2 │ using {} for *; │ 41..56 + +Errors: # 1 total + - > + Error: Expected Identifier. + ╭─[crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol:2:7] + │ + 2 │ using {} for *; + │ ────┬─── + │ ╰───── Error occurred here. + ───╯ + +Tree: + - UsingDirective (Rule): # 0..57 "// Empty using symbols list is not valid\nusing {} ..." + - LeadingTrivia (Rule): # 0..41 "// Empty using symbols list is not valid\n" + - SingleLineComment (Trivia): "// Empty using symbols list is not valid" # 0..40 + - UsingKeyword (Token): "using" # 41..46 + - SKIPPED (Token): "{} for *" # 47..55 + - Semicolon (Token): ";" # 55..56 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/generated/0.8.13-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/generated/0.8.13-failure.yml new file mode 100644 index 0000000000..7e7fb01220 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/generated/0.8.13-failure.yml @@ -0,0 +1,28 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Empty using symbols list is not valid │ 0..40 + 2 │ using {} for *; │ 41..56 + +Errors: # 1 total + - > + Error: Expected Identifier. + ╭─[crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol:2:8] + │ + 2 │ using {} for *; + │ │ + │ ╰─ Error occurred here. + ───╯ + +Tree: + - UsingDirective (Rule): # 0..57 "// Empty using symbols list is not valid\nusing {} ..." + - LeadingTrivia (Rule): # 0..41 "// Empty using symbols list is not valid\n" + - SingleLineComment (Trivia): "// Empty using symbols list is not valid" # 0..40 + - UsingKeyword (Token): "using" # 41..46 + - UsingDirectiveDeconstruction (Rule): # 46..49 " {}" + - OpenBrace (Token): "{" # 47..48 + - SKIPPED (Token): "" # 48..48 + - CloseBrace (Token): "}" # 48..49 + - ForKeyword (Token): "for" # 50..53 + - Asterisk (Token): "*" # 54..55 + - Semicolon (Token): ";" # 55..56 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol new file mode 100644 index 0000000000..2a5856c942 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_empty/input.sol @@ -0,0 +1,2 @@ +// Empty using symbols list is not valid +using {} for *; diff --git a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs b/crates/solidity/testing/utils/src/cst_snapshots/mod.rs index 041f3550f5..756d6a3753 100644 --- a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs +++ b/crates/solidity/testing/utils/src/cst_snapshots/mod.rs @@ -126,6 +126,7 @@ fn write_node( let (node_value, node_comment) = if range.is_empty() { let preview = match node { + cst::Node::Rule(_) if !node.children().is_empty() => "", cst::Node::Rule(_) => " []", cst::Node::Token(_) => " \"\"", };