Skip to content

Commit a6b555c

Browse files
committed
fix trailing IdentifierPart in grammar
- Moved numeric literals to use `notFollowedBy: IdentifierStart` instead of `IdentifierPart`. - Removed `notFollowedBy: IdentifierPart` from string literals, to match the behavior of `solc`.
1 parent 36be89c commit a6b555c

8 files changed

Lines changed: 161 additions & 184 deletions

File tree

crates/solidity/inputs/language/definition/05-expressions/04-numbers/productions.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
- oneOrMore:
3838
reference: "HexCharacter"
3939
notFollowedBy:
40-
reference: "IdentifierPart"
40+
reference: "IdentifierStart"
4141
0.5.0:
4242
# removed uppercase "0X"
4343
trailingContext:
@@ -52,7 +52,7 @@
5252
- oneOrMore:
5353
reference: "HexCharacter"
5454
notFollowedBy:
55-
reference: "IdentifierPart"
55+
reference: "IdentifierStart"
5656

5757
- name: "DecimalLiteral"
5858
kind: "Scanner"
@@ -75,7 +75,7 @@
7575
- optional:
7676
reference: "DecimalExponent"
7777
notFollowedBy:
78-
reference: "IdentifierPart"
78+
reference: "IdentifierStart"
7979
0.5.0:
8080
# Second "DecimalDigits" is no longer "optional"
8181
trailingContext:
@@ -94,7 +94,7 @@
9494
- optional:
9595
reference: "DecimalExponent"
9696
notFollowedBy:
97-
reference: "IdentifierPart"
97+
reference: "IdentifierStart"
9898

9999
- name: "DecimalDigits"
100100
kind: "Scanner"

crates/solidity/inputs/language/definition/05-expressions/05-strings/productions.yml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
- name: "HexStringLiteral"
2525
kind: "Scanner"
2626
unversioned:
27-
trailingContext:
28-
scanner:
29-
choice:
30-
- reference: "SingleQuotedHexStringLiteral"
31-
- reference: "DoubleQuotedHexStringLiteral"
32-
notFollowedBy:
33-
reference: "IdentifierPart"
27+
choice:
28+
- reference: "SingleQuotedHexStringLiteral"
29+
- reference: "DoubleQuotedHexStringLiteral"
3430

3531
- name: "SingleQuotedHexStringLiteral"
3632
kind: "Scanner"
@@ -92,13 +88,9 @@
9288
- name: "AsciiStringLiteral"
9389
kind: "Scanner"
9490
unversioned:
95-
trailingContext:
96-
scanner:
97-
choice:
98-
- reference: "SingleQuotedAsciiStringLiteral"
99-
- reference: "DoubleQuotedAsciiStringLiteral"
100-
notFollowedBy:
101-
reference: "IdentifierPart"
91+
choice:
92+
- reference: "SingleQuotedAsciiStringLiteral"
93+
- reference: "DoubleQuotedAsciiStringLiteral"
10294

10395
- name: "SingleQuotedAsciiStringLiteral"
10496
kind: "Scanner"
@@ -151,13 +143,9 @@
151143
kind: "Scanner"
152144
versioned:
153145
0.7.0:
154-
trailingContext:
155-
scanner:
156-
choice:
157-
- reference: "SingleQuotedUnicodeStringLiteral"
158-
- reference: "DoubleQuotedUnicodeStringLiteral"
159-
notFollowedBy:
160-
reference: "IdentifierPart"
146+
choice:
147+
- reference: "SingleQuotedUnicodeStringLiteral"
148+
- reference: "DoubleQuotedUnicodeStringLiteral"
161149

162150
- name: "SingleQuotedUnicodeStringLiteral"
163151
kind: "Scanner"

crates/solidity/inputs/language/definition/06-yul/03-yul-expressions/productions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
- oneOrMore:
136136
reference: "HexCharacter"
137137
notFollowedBy:
138-
reference: "IdentifierPart"
138+
reference: "IdentifierStart"
139139

140140
- name: "YulDecimalLiteral"
141141
kind: "Scanner"
@@ -153,4 +153,4 @@
153153
from: "0"
154154
to: "9"
155155
notFollowedBy:
156-
reference: "IdentifierPart"
156+
reference: "IdentifierStart"

crates/solidity/inputs/language/src/definition.rs

Lines changed: 122 additions & 100 deletions
Large diffs are not rendered by default.

crates/solidity/inputs/language/src/dsl.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -796,30 +796,21 @@ slang_grammar! {
796796

797797
// Ascii String Literals
798798

799-
scanner AsciiStringLiteral = (
800-
(SingleQuotedAsciiStringLiteral | DoubleQuotedAsciiStringLiteral)
801-
not followed by IdentifierStart
802-
) ;
799+
scanner AsciiStringLiteral = (SingleQuotedAsciiStringLiteral | DoubleQuotedAsciiStringLiteral) ;
803800
scanner DoubleQuotedAsciiStringLiteral = ("\"" ((EscapeSequence | AsciiCharacterWithoutDoubleQuoteOrBackslash) *) "\"") ;
804801
scanner SingleQuotedAsciiStringLiteral = ("\'" ((EscapeSequence | AsciiCharacterWithoutSingleQuoteOrBackslash) *) "\'") ;
805802

806803
// Hex String Literals
807804

808-
scanner HexStringLiteral = (
809-
(SingleQuotedHexStringLiteral | DoubleQuotedHexStringLiteral)
810-
not followed by IdentifierStart
811-
) ;
805+
scanner HexStringLiteral = (SingleQuotedHexStringLiteral | DoubleQuotedHexStringLiteral) ;
812806
scanner DoubleQuotedHexStringLiteral = ("hex\"" (HexStringContents ?) "\"") ;
813807
scanner SingleQuotedHexStringLiteral = ("hex\'" (HexStringContents ?) "\'") ;
814808
scanner HexStringContents = (HexCharacter HexCharacter ((('_' ?) HexCharacter HexCharacter) *)) ;
815809

816810
// Unicode String Literals
817811

818812
scanner UnicodeStringLiteral = {
819-
introduced in "0.7.0" (
820-
(SingleQuotedUnicodeStringLiteral | DoubleQuotedUnicodeStringLiteral)
821-
not followed by IdentifierStart
822-
)
813+
introduced in "0.7.0" (SingleQuotedUnicodeStringLiteral | DoubleQuotedUnicodeStringLiteral)
823814
} ;
824815
scanner DoubleQuotedUnicodeStringLiteral = { introduced in "0.7.0" ("unicode\"" ((EscapeSequence | (! "\n\r\"\\")) *) "\"") } ;
825816
scanner SingleQuotedUnicodeStringLiteral = { introduced in "0.7.0" ("unicode\'" ((EscapeSequence | (! "\n\r\'\\")) *) "\'") } ;

crates/solidity/outputs/cargo/crate/src/generated/language.rs

Lines changed: 9 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity/outputs/cargo/tests/src/scanner/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ fn test_next_token() {
1818
("1", DecimalLiteral),
1919
("\n", EndOfLine),
2020
("unicode'abc'", UnicodeStringLiteral),
21-
("unicode'abc'ZZ", Identifier), // TODO: This needs to be further checked against solc
2221
("hex'abcd'", HexStringLiteral),
23-
("hex'abcd'ZZz", HexKeyword), // TODO: This needs to be further checked against solc
22+
("'abc'ZZ", AsciiStringLiteral), // with an identifier afterwards
23+
("unicode'abc'ZZ", UnicodeStringLiteral), // with an identifier afterwards
24+
("hex'abcd'ZZz", HexStringLiteral), // with an identifier afterwards
2425
("// single line\n", SingleLineComment),
2526
("/* multi-line\n comment */ blah", MultilineComment),
2627
("/* multi-line comment **/ blah", MultilineComment),
2728
("0ZZ", SKIPPED),
2829
("0xabZZ", SKIPPED),
29-
("'abc'ZZ", SKIPPED),
3030
] {
3131
assert_eq!(language.scan(LexicalContext::Default, s), Some(*k));
3232
}

crates/solidity/outputs/npm/crate/src/generated/language.rs

Lines changed: 9 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)