Skip to content

Commit

Permalink
fix: After 0.5.0 we can't consume the dot if not followed by digit
Browse files Browse the repository at this point in the history
See ethereum/solidity#4172.

This unblocks parsing member access expressions where the primary
expression can't consume the dot in order to parse the `.member` postfix
expression.
  • Loading branch information
Xanewok committed Mar 9, 2024
1 parent 7426418 commit 788f76d
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 73 deletions.
15 changes: 15 additions & 0 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

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

3 changes: 3 additions & 0 deletions crates/solidity/outputs/spec/generated/grammar.ebnf

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

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
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 788f76d

Please sign in to comment.