diff --git a/.changeset/cool-numbers-sneeze.md b/.changeset/cool-numbers-sneeze.md new file mode 100644 index 0000000000..a1ab93a7bd --- /dev/null +++ b/.changeset/cool-numbers-sneeze.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": patch +--- + +support dots in yul identifiers from `0.5.8` till `0.7.0` diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 16948a4bf8..5ec4a389e7 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -3946,14 +3946,12 @@ codegen_language_macros::compile!(Language( ), Token( name = Identifier, - definitions = [TokenDefinition(scanner = Fragment(RawIdentifier))] - ), - Fragment( - name = RawIdentifier, - scanner = Sequence([ - Fragment(IdentifierStart), - ZeroOrMore(Fragment(IdentifierPart)) - ]) + definitions = [TokenDefinition( + scanner = Sequence([ + Fragment(IdentifierStart), + ZeroOrMore(Fragment(IdentifierPart)) + ]) + )] ), Fragment( name = IdentifierStart, @@ -4199,7 +4197,23 @@ codegen_language_macros::compile!(Language( ), Token( name = YulIdentifier, - definitions = [TokenDefinition(scanner = Fragment(RawIdentifier))] + definitions = [ + // Dots were allowed specifically between these versions: + TokenDefinition( + enabled = Range(from = "0.5.8", till = "0.7.0"), + scanner = Sequence([ + Fragment(IdentifierStart), + ZeroOrMore(Choice([Fragment(IdentifierPart), Atom(".")])) + ]) + ), + // Otherwise, parse as a regular identifier: + TokenDefinition( + scanner = Sequence([ + Fragment(IdentifierStart), + ZeroOrMore(Fragment(IdentifierPart)) + ]) + ) + ] ), Enum( name = YulBuiltInFunction, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs index 63764597af..bce9f3fe93 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -38,6 +38,7 @@ pub struct Language { pub(crate) version_is_at_least_0_5_0: bool, pub(crate) version_is_at_least_0_5_3: bool, pub(crate) version_is_at_least_0_5_5: bool, + pub(crate) version_is_at_least_0_5_8: bool, pub(crate) version_is_at_least_0_5_10: bool, pub(crate) version_is_at_least_0_5_12: bool, pub(crate) version_is_at_least_0_5_14: bool, @@ -168,6 +169,7 @@ impl Language { version_is_at_least_0_5_0: Version::new(0, 5, 0) <= version, version_is_at_least_0_5_3: Version::new(0, 5, 3) <= version, version_is_at_least_0_5_5: Version::new(0, 5, 5) <= version, + version_is_at_least_0_5_8: Version::new(0, 5, 8) <= version, version_is_at_least_0_5_10: Version::new(0, 5, 10) <= version, version_is_at_least_0_5_12: Version::new(0, 5, 12) <= version, version_is_at_least_0_5_14: Version::new(0, 5, 14) <= version, @@ -7122,7 +7124,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn identifier(&self, input: &mut ParserContext<'_>) -> bool { - self.raw_identifier(input) + scan_sequence!( + self.identifier_start(input), + scan_zero_or_more!(input, self.identifier_part(input)) + ) } #[allow(unused_assignments, unused_parens)] @@ -7185,14 +7190,6 @@ impl Language { ) } - #[allow(unused_assignments, unused_parens)] - fn raw_identifier(&self, input: &mut ParserContext<'_>) -> bool { - scan_sequence!( - self.identifier_start(input), - scan_zero_or_more!(input, self.identifier_part(input)) - ) - } - #[allow(unused_assignments, unused_parens)] fn single_line_comment(&self, input: &mut ParserContext<'_>) -> bool { scan_sequence!( @@ -7352,7 +7349,24 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_identifier(&self, input: &mut ParserContext<'_>) -> bool { - self.raw_identifier(input) + scan_choice!( + input, + if self.version_is_at_least_0_5_8 && !self.version_is_at_least_0_7_0 { + scan_sequence!( + self.identifier_start(input), + scan_zero_or_more!( + input, + scan_choice!(input, scan_chars!(input, '.'), self.identifier_part(input)) + ) + ) + } else { + false + }, + scan_sequence!( + self.identifier_start(input), + scan_zero_or_more!(input, self.identifier_part(input)) + ) + ) } // Keyword scanners diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs index aec65ad181..7d9522ffec 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs @@ -55,7 +55,7 @@ mod yul_label; mod yul_leave_statement; mod yul_variable_declaration_statement; -pub const VERSION_BREAKS: [Version; 28] = [ +pub const VERSION_BREAKS: [Version; 29] = [ Version::new(0, 4, 11), Version::new(0, 4, 12), Version::new(0, 4, 14), @@ -64,6 +64,7 @@ pub const VERSION_BREAKS: [Version; 28] = [ Version::new(0, 5, 0), Version::new(0, 5, 3), Version::new(0, 5, 5), + Version::new(0, 5, 8), Version::new(0, 5, 10), Version::new(0, 5, 12), Version::new(0, 5, 14), diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/yul_expression.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/yul_expression.rs index 231d74fa1d..0489e436a7 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/yul_expression.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/yul_expression.rs @@ -33,3 +33,8 @@ fn hex_trailing_ident_start() -> Result<()> { fn identifier_path() -> Result<()> { run("YulExpression", "identifier_path") } + +#[test] +fn identifier_with_dot() -> Result<()> { + run("YulExpression", "identifier_with_dot") +} diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index 74b35963ba..37cb476e91 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -1302,9 +1302,7 @@ DOUBLE_QUOTED_UNICODE_STRING_LITERAL = 'unicode"' («ESCAPE_SEQUENCE» | !('"' " IdentifierPath = IDENTIFIER (PERIOD IDENTIFIER)*; -IDENTIFIER = «RAW_IDENTIFIER»; - -«RAW_IDENTIFIER» = «IDENTIFIER_START» «IDENTIFIER_PART»*; +IDENTIFIER = «IDENTIFIER_START» «IDENTIFIER_PART»*; «IDENTIFIER_START» = "_" | "$" | ("a"…"z") | ("A"…"Z"); @@ -1420,7 +1418,10 @@ YulIdentifierPaths = YulIdentifierPath (COMMA YulIdentifierPath)*; YulIdentifierPath = YUL_IDENTIFIER (PERIOD YUL_IDENTIFIER)*; -YUL_IDENTIFIER = «RAW_IDENTIFIER»; +(* Introduced in 0.5.8 and deprecated in 0.7.0. *) +YUL_IDENTIFIER = «IDENTIFIER_START» («IDENTIFIER_PART» | ".")*; + +YUL_IDENTIFIER = «IDENTIFIER_START» «IDENTIFIER_PART»*; YulBuiltInFunction = YUL_ADD_KEYWORD | YUL_ADD_MOD_KEYWORD diff --git a/crates/solidity/outputs/spec/generated/public/05-expressions/06-identifiers.md b/crates/solidity/outputs/spec/generated/public/05-expressions/06-identifiers.md index bcc6f6dbf0..50316aa50e 100644 --- a/crates/solidity/outputs/spec/generated/public/05-expressions/06-identifiers.md +++ b/crates/solidity/outputs/spec/generated/public/05-expressions/06-identifiers.md @@ -14,13 +14,7 @@ ``` -
IDENTIFIER = «RAW_IDENTIFIER»;
- -```{ .ebnf #RawIdentifier } - -``` - -
«RAW_IDENTIFIER» = «IDENTIFIER_START» «IDENTIFIER_PART»*;
+
IDENTIFIER = «IDENTIFIER_START» «IDENTIFIER_PART»*;
```{ .ebnf #IdentifierStart } diff --git a/crates/solidity/outputs/spec/generated/public/06-yul/02-yul-expressions.md b/crates/solidity/outputs/spec/generated/public/06-yul/02-yul-expressions.md index 5b9c5d75e6..ac4db35c34 100644 --- a/crates/solidity/outputs/spec/generated/public/06-yul/02-yul-expressions.md +++ b/crates/solidity/outputs/spec/generated/public/06-yul/02-yul-expressions.md @@ -32,7 +32,7 @@ ``` -
YUL_IDENTIFIER = «RAW_IDENTIFIER»;
+
(* Introduced in 0.5.8 and deprecated in 0.7.0. *)
YUL_IDENTIFIER = «IDENTIFIER_START» («IDENTIFIER_PART» | ".")*;

YUL_IDENTIFIER = «IDENTIFIER_START» «IDENTIFIER_PART»*;
```{ .ebnf #YulBuiltInFunction } diff --git a/crates/solidity/outputs/spec/generated/public/supported-versions.md b/crates/solidity/outputs/spec/generated/public/supported-versions.md index a65dcbc9b5..705a500bda 100644 --- a/crates/solidity/outputs/spec/generated/public/supported-versions.md +++ b/crates/solidity/outputs/spec/generated/public/supported-versions.md @@ -4,6 +4,6 @@ This specification compiles information from 77 publicly released versions of So `0.4.11` `0.4.12` `0.4.13` `0.4.14` `0.4.15` `0.4.16` `0.4.17` `0.4.18` `0.4.19` `0.4.20` `0.4.21` `0.4.22` `0.4.23` `0.4.24` `0.4.25` `0.4.26` `0.5.0` `0.5.1` `0.5.2` `0.5.3` `0.5.4` `0.5.5` `0.5.6` `0.5.7` `0.5.8` `0.5.9` `0.5.10` `0.5.11` `0.5.12` `0.5.13` `0.5.14` `0.5.15` `0.5.16` `0.5.17` `0.6.0` `0.6.1` `0.6.2` `0.6.3` `0.6.4` `0.6.5` `0.6.6` `0.6.7` `0.6.8` `0.6.9` `0.6.10` `0.6.11` `0.6.12` `0.7.0` `0.7.1` `0.7.2` `0.7.3` `0.7.4` `0.7.5` `0.7.6` `0.8.0` `0.8.1` `0.8.2` `0.8.3` `0.8.4` `0.8.5` `0.8.6` `0.8.7` `0.8.8` `0.8.9` `0.8.10` `0.8.11` `0.8.12` `0.8.13` `0.8.14` `0.8.15` `0.8.16` `0.8.17` `0.8.18` `0.8.19` `0.8.20` `0.8.21` `0.8.22` -Among which, 28 versions have breaking changes: +Among which, 29 versions have breaking changes: -`0.4.11` `0.4.12` `0.4.14` `0.4.21` `0.4.22` `0.5.0` `0.5.3` `0.5.5` `0.5.10` `0.5.12` `0.5.14` `0.6.0` `0.6.2` `0.6.5` `0.6.7` `0.6.8` `0.6.11` `0.7.0` `0.7.1` `0.7.4` `0.8.0` `0.8.4` `0.8.7` `0.8.8` `0.8.13` `0.8.18` `0.8.19` `0.8.22` +`0.4.11` `0.4.12` `0.4.14` `0.4.21` `0.4.22` `0.5.0` `0.5.3` `0.5.5` `0.5.8` `0.5.10` `0.5.12` `0.5.14` `0.6.0` `0.6.2` `0.6.5` `0.6.7` `0.6.8` `0.6.11` `0.7.0` `0.7.1` `0.7.4` `0.8.0` `0.8.4` `0.8.7` `0.8.8` `0.8.13` `0.8.18` `0.8.19` `0.8.22` diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/generated/0.4.11-success.yml index b0264bad34..111aa9d74a 100644 --- a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/generated/0.4.11-success.yml @@ -1,12 +1,15 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ foo.bar │ 0..7 + 1 │ foo . bar │ 0..9 Errors: [] Tree: - - (YulExpression) ► (variant꞉ YulIdentifierPath): # "foo.bar" (0..7) + - (YulExpression) ► (variant꞉ YulIdentifierPath): # "foo . bar\n" (0..10) - (item꞉ YulIdentifier): "foo" # (0..3) - - (separator꞉ Period): "." # (3..4) - - (item꞉ YulIdentifier): "bar" # (4..7) + - (LeadingTrivia) ► (Whitespace): " " # (3..4) + - (separator꞉ Period): "." # (4..5) + - (LeadingTrivia) ► (Whitespace): " " # (5..6) + - (item꞉ YulIdentifier): "bar" # (6..9) + - (TrailingTrivia) ► (EndOfLine): "\n" # (9..10) diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/input.sol b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/input.sol index 4d5f9756e5..856118f32c 100644 --- a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/input.sol +++ b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_path/input.sol @@ -1 +1 @@ -foo.bar \ No newline at end of file +foo . bar diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.4.11-success.yml new file mode 100644 index 0000000000..ae5d7cb63f --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.4.11-success.yml @@ -0,0 +1,17 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // identifiers with dots were allowed specifically from = "0.5.8" till = "0.7.0": │ 0..81 + 2 │ foo.bar │ 82..89 + +Errors: [] + +Tree: + - (YulExpression) ► (variant꞉ YulIdentifierPath): # "// identifiers with dots were allowed specifically..." (0..90) + - (LeadingTrivia): # "// identifiers with dots were allowed specifically..." (0..82) + - (SingleLineComment): "// identifiers with dots were allowed specifically..." # (0..81) + - (EndOfLine): "\n" # (81..82) + - (item꞉ YulIdentifier): "foo" # (82..85) + - (separator꞉ Period): "." # (85..86) + - (item꞉ YulIdentifier): "bar" # (86..89) + - (TrailingTrivia) ► (EndOfLine): "\n" # (89..90) diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.5.8-success.yml b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.5.8-success.yml new file mode 100644 index 0000000000..1e4a115bec --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.5.8-success.yml @@ -0,0 +1,15 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // identifiers with dots were allowed specifically from = "0.5.8" till = "0.7.0": │ 0..81 + 2 │ foo.bar │ 82..89 + +Errors: [] + +Tree: + - (YulExpression) ► (variant꞉ YulIdentifierPath): # "// identifiers with dots were allowed specifically..." (0..90) + - (LeadingTrivia): # "// identifiers with dots were allowed specifically..." (0..82) + - (SingleLineComment): "// identifiers with dots were allowed specifically..." # (0..81) + - (EndOfLine): "\n" # (81..82) + - (item꞉ YulIdentifier): "foo.bar" # (82..89) + - (TrailingTrivia) ► (EndOfLine): "\n" # (89..90) diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.7.0-success.yml b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.7.0-success.yml new file mode 100644 index 0000000000..ae5d7cb63f --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/generated/0.7.0-success.yml @@ -0,0 +1,17 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // identifiers with dots were allowed specifically from = "0.5.8" till = "0.7.0": │ 0..81 + 2 │ foo.bar │ 82..89 + +Errors: [] + +Tree: + - (YulExpression) ► (variant꞉ YulIdentifierPath): # "// identifiers with dots were allowed specifically..." (0..90) + - (LeadingTrivia): # "// identifiers with dots were allowed specifically..." (0..82) + - (SingleLineComment): "// identifiers with dots were allowed specifically..." # (0..81) + - (EndOfLine): "\n" # (81..82) + - (item꞉ YulIdentifier): "foo" # (82..85) + - (separator꞉ Period): "." # (85..86) + - (item꞉ YulIdentifier): "bar" # (86..89) + - (TrailingTrivia) ► (EndOfLine): "\n" # (89..90) diff --git a/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/input.sol b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/input.sol new file mode 100644 index 0000000000..3fcbf25196 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/YulExpression/identifier_with_dot/input.sol @@ -0,0 +1,2 @@ +// identifiers with dots were allowed specifically from = "0.5.8" till = "0.7.0": +foo.bar