diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 87cf7611b8..452c284958 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -3692,6 +3692,21 @@ codegen_language_macros::compile!(Language( not_followed_by = Fragment(IdentifierStart) ) ), + // Since 0.5.0, only consume a dot if it's followed by a digit: + TokenDefinition( + enabled = From("0.5.0"), + scanner = TrailingContext( + scanner = Sequence([ + Fragment(DecimalDigits), + Optional(Sequence([ + Atom("."), + Fragment(DecimalDigits) + ])), + Optional(Fragment(DecimalExponent)) + ]), + not_followed_by = Fragment(IdentifierStart) + ) + ), // A dot and a fraction (without an integer) is enabled in all versions: TokenDefinition( scanner = TrailingContext( 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 23ddd3ac31..1f64945ff6 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -6960,6 +6960,22 @@ impl Language { } else { false }, + if self.version_is_at_least_0_5_0 { + scan_not_followed_by!( + input, + scan_sequence!( + self.decimal_digits(input), + scan_optional!( + input, + scan_sequence!(scan_chars!(input, '.'), self.decimal_digits(input)) + ), + scan_optional!(input, self.decimal_exponent(input)) + ), + self.identifier_start(input) + ) + } else { + false + }, scan_not_followed_by!( input, scan_sequence!( diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index df8d0e3256..65da63b63f 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -1216,6 +1216,9 @@ DECIMAL_LITERAL = «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?; (* Deprecated in 0.5.0 *) DECIMAL_LITERAL = «DECIMAL_DIGITS» "." «DECIMAL_EXPONENT»?; +(* Introduced in 0.5.0 *) +DECIMAL_LITERAL = «DECIMAL_DIGITS» ("." «DECIMAL_DIGITS»)? «DECIMAL_EXPONENT»?; + DECIMAL_LITERAL = "." «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?; DECIMAL_LITERAL = «DECIMAL_DIGITS» "." «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?; diff --git a/crates/solidity/outputs/spec/generated/public/05-expressions/04-numbers.md b/crates/solidity/outputs/spec/generated/public/05-expressions/04-numbers.md index 9f838489df..4023817b21 100644 --- a/crates/solidity/outputs/spec/generated/public/05-expressions/04-numbers.md +++ b/crates/solidity/outputs/spec/generated/public/05-expressions/04-numbers.md @@ -26,7 +26,7 @@ ``` -
DECIMAL_LITERAL = «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?;

(* Deprecated in 0.5.0 *)
DECIMAL_LITERAL = «DECIMAL_DIGITS» "." «DECIMAL_EXPONENT»?;

DECIMAL_LITERAL = "." «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?;

DECIMAL_LITERAL = «DECIMAL_DIGITS» "." «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?;
+
DECIMAL_LITERAL = «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?;

(* Deprecated in 0.5.0 *)
DECIMAL_LITERAL = «DECIMAL_DIGITS» "." «DECIMAL_EXPONENT»?;

(* Introduced in 0.5.0 *)
DECIMAL_LITERAL = «DECIMAL_DIGITS» ("." «DECIMAL_DIGITS»)? «DECIMAL_EXPONENT»?;

DECIMAL_LITERAL = "." «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?;

DECIMAL_LITERAL = «DECIMAL_DIGITS» "." «DECIMAL_DIGITS» «DECIMAL_EXPONENT»?;
```{ .ebnf #DecimalDigits } diff --git a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.5.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.5.0-failure.yml index b9d28bd74c..031553fa5b 100644 --- a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.5.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.5.0-failure.yml @@ -5,13 +5,15 @@ Source: > Errors: # 1 total - > - Error: Expected DecimalLiteral. - ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/input.sol:1:1] + Error: Expected DaysKeyword or EtherKeyword or FinneyKeyword or HoursKeyword or MinutesKeyword or SecondsKeyword or SzaboKeyword or WeeksKeyword or WeiKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/input.sol:1:2] │ 1 │ 1. - │ ─┬ + │ ┬ │ ╰── Error occurred here. ───╯ Tree: - - (SKIPPED): "1." # (0..2) + - (DecimalNumberExpression): # "1." (0..2) + - (literal꞉ DecimalLiteral): "1" # (0..1) + - (SKIPPED): "." # (1..2) diff --git a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.6.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.6.11-failure.yml new file mode 100644 index 0000000000..5d8ae956bc --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.6.11-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ 1. │ 0..2 + +Errors: # 1 total + - > + Error: Expected DaysKeyword or EtherKeyword or FinneyKeyword or GweiKeyword or HoursKeyword or MinutesKeyword or SecondsKeyword or SzaboKeyword or WeeksKeyword or WeiKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/input.sol:1:2] + │ + 1 │ 1. + │ ┬ + │ ╰── Error occurred here. + ───╯ + +Tree: + - (DecimalNumberExpression): # "1." (0..2) + - (literal꞉ DecimalLiteral): "1" # (0..1) + - (SKIPPED): "." # (1..2) diff --git a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.7.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.7.0-failure.yml new file mode 100644 index 0000000000..1e01195c2e --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/generated/0.7.0-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ 1. │ 0..2 + +Errors: # 1 total + - > + Error: Expected DaysKeyword or EtherKeyword or GweiKeyword or HoursKeyword or MinutesKeyword or SecondsKeyword or WeeksKeyword or WeiKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/float_no_fraction/input.sol:1:2] + │ + 1 │ 1. + │ ┬ + │ ╰── Error occurred here. + ───╯ + +Tree: + - (DecimalNumberExpression): # "1." (0..2) + - (literal꞉ DecimalLiteral): "1" # (0..1) + - (SKIPPED): "." # (1..2) diff --git a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.5.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.5.0-failure.yml new file mode 100644 index 0000000000..7da1389311 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.5.0-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ 1.a │ 0..3 + +Errors: # 1 total + - > + Error: Expected DaysKeyword or EtherKeyword or FinneyKeyword or HoursKeyword or MinutesKeyword or SecondsKeyword or SzaboKeyword or WeeksKeyword or WeiKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/input.sol:1:2] + │ + 1 │ 1.a + │ ─┬─ + │ ╰─── Error occurred here. + ───╯ + +Tree: + - (DecimalNumberExpression): # "1.a\n" (0..4) + - (literal꞉ DecimalLiteral): "1" # (0..1) + - (SKIPPED): ".a\n" # (1..4) diff --git a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.6.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.6.11-failure.yml new file mode 100644 index 0000000000..bf48eef5e4 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.6.11-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ 1.a │ 0..3 + +Errors: # 1 total + - > + Error: Expected DaysKeyword or EtherKeyword or FinneyKeyword or GweiKeyword or HoursKeyword or MinutesKeyword or SecondsKeyword or SzaboKeyword or WeeksKeyword or WeiKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/input.sol:1:2] + │ + 1 │ 1.a + │ ─┬─ + │ ╰─── Error occurred here. + ───╯ + +Tree: + - (DecimalNumberExpression): # "1.a\n" (0..4) + - (literal꞉ DecimalLiteral): "1" # (0..1) + - (SKIPPED): ".a\n" # (1..4) diff --git a/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.7.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.7.0-failure.yml new file mode 100644 index 0000000000..7f66f11aac --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/generated/0.7.0-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ 1.a │ 0..3 + +Errors: # 1 total + - > + Error: Expected DaysKeyword or EtherKeyword or GweiKeyword or HoursKeyword or MinutesKeyword or SecondsKeyword or WeeksKeyword or WeiKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/DecimalNumberExpression/integer_ident_after_period/input.sol:1:2] + │ + 1 │ 1.a + │ ─┬─ + │ ╰─── Error occurred here. + ───╯ + +Tree: + - (DecimalNumberExpression): # "1.a\n" (0..4) + - (literal꞉ DecimalLiteral): "1" # (0..1) + - (SKIPPED): ".a\n" # (1..4) diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.5.0-success.yml b/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.5.0-success.yml new file mode 100644 index 0000000000..f8cd1715f3 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.5.0-success.yml @@ -0,0 +1,18 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ 5.fromUint() │ 0..12 + +Errors: [] + +Tree: + - (Expression) ► (variant꞉ FunctionCallExpression): # "5.fromUint()\n" (0..13) + - (operand꞉ Expression) ► (variant꞉ MemberAccessExpression): # "5.fromUint" (0..10) + - (operand꞉ Expression) ► (variant꞉ DecimalNumberExpression) ► (literal꞉ DecimalLiteral): "5" # (0..1) + - (period꞉ Period): "." # (1..2) + - (member꞉ MemberAccess) ► (variant꞉ Identifier): "fromUint" # (2..10) + - (arguments꞉ ArgumentsDeclaration) ► (variant꞉ PositionalArgumentsDeclaration): # "()\n" (10..13) + - (open_paren꞉ OpenParen): "(" # (10..11) + - (arguments꞉ PositionalArguments): [] # (11..11) + - (close_paren꞉ CloseParen): ")" # (11..12) + - (trailing_trivia꞉ EndOfLine): "\n" # (12..13) diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.5.3-failure.yml b/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.5.3-failure.yml deleted file mode 100644 index 4494802b21..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.5.3-failure.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ 5.fromUint() │ 0..12 - -Errors: # 1 total - - > - Error: Expected AddressKeyword or BoolKeyword or ByteKeyword or BytesKeyword or DecimalLiteral or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or FalseKeyword or FixedKeyword or HexLiteral or Identifier or IntKeyword or NewKeyword or OpenBracket or OpenParen or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or StringKeyword or TrueKeyword or TypeKeyword or UfixedKeyword or UintKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/input.sol:1:1] - │ - 1 │ 5.fromUint() - │ ──────┬────── - │ ╰──────── Error occurred here. - ───╯ - -Tree: - - (SKIPPED): "5.fromUint()\n" # (0..13) diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.6.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.6.0-failure.yml deleted file mode 100644 index 0876d2e10b..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.6.0-failure.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ 5.fromUint() │ 0..12 - -Errors: # 1 total - - > - Error: Expected AddressKeyword or BoolKeyword or ByteKeyword or BytesKeyword or DecimalLiteral or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or FalseKeyword or FixedKeyword or HexLiteral or Identifier or IntKeyword or NewKeyword or OpenBracket or OpenParen or PayableKeyword or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or StringKeyword or TrueKeyword or TypeKeyword or UfixedKeyword or UintKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/input.sol:1:1] - │ - 1 │ 5.fromUint() - │ ──────┬────── - │ ╰──────── Error occurred here. - ───╯ - -Tree: - - (SKIPPED): "5.fromUint()\n" # (0..13) diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.7.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.7.0-failure.yml deleted file mode 100644 index 031c9e3bfa..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.7.0-failure.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ 5.fromUint() │ 0..12 - -Errors: # 1 total - - > - Error: Expected AddressKeyword or BoolKeyword or ByteKeyword or BytesKeyword or DecimalLiteral or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or DoubleQuotedUnicodeStringLiteral or FalseKeyword or FixedKeyword or HexLiteral or Identifier or IntKeyword or NewKeyword or OpenBracket or OpenParen or PayableKeyword or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or SingleQuotedUnicodeStringLiteral or StringKeyword or TrueKeyword or TypeKeyword or UfixedKeyword or UintKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/input.sol:1:1] - │ - 1 │ 5.fromUint() - │ ──────┬────── - │ ╰──────── Error occurred here. - ───╯ - -Tree: - - (SKIPPED): "5.fromUint()\n" # (0..13) diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.8.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.8.0-failure.yml deleted file mode 100644 index b1223c013b..0000000000 --- a/crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/generated/0.8.0-failure.yml +++ /dev/null @@ -1,17 +0,0 @@ -# This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -Source: > - 1 │ 5.fromUint() │ 0..12 - -Errors: # 1 total - - > - Error: Expected AddressKeyword or BoolKeyword or BytesKeyword or DecimalLiteral or DoubleQuotedHexStringLiteral or DoubleQuotedStringLiteral or DoubleQuotedUnicodeStringLiteral or FalseKeyword or FixedKeyword or HexLiteral or Identifier or IntKeyword or NewKeyword or OpenBracket or OpenParen or PayableKeyword or SingleQuotedHexStringLiteral or SingleQuotedStringLiteral or SingleQuotedUnicodeStringLiteral or StringKeyword or TrueKeyword or TypeKeyword or UfixedKeyword or UintKeyword. - ╭─[crates/solidity/testing/snapshots/cst_output/Expression/member_access_integer/input.sol:1:1] - │ - 1 │ 5.fromUint() - │ ──────┬────── - │ ╰──────── Error occurred here. - ───╯ - -Tree: - - (SKIPPED): "5.fromUint()\n" # (0..13)