Skip to content

Commit

Permalink
fix: Mark global binding in the using directive as introduced in 0.…
Browse files Browse the repository at this point in the history
…8.13

See ethereum/solidity#12288

It's impossible to specify a newly introduced keyword optionally in the
YML spec directly or even as an additional inline parser (`null`
definitions are treated as an undefined parser and error out), so this
adds versioning to the UsingDirective to add the new `global` contextual
keyword.
  • Loading branch information
Xanewok committed Sep 21, 2023
1 parent be71af9 commit 987c639
Show file tree
Hide file tree
Showing 34 changed files with 239 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,38 @@

- name: "UsingDirective"
kind: "Parser"
unversioned:
terminatedBy:
parser:
sequence:
- reference: "UsingKeyword"
- choice:
- reference: "UsingDirectivePath"
- reference: "UsingDirectiveDeconstruction"
- reference: "ForKeyword"
- choice:
- reference: "Asterisk"
- reference: "TypeName"
- optional:
reference: "GlobalKeyword"
terminator:
reference: "Semicolon"
versioned:
0.4.11:
terminatedBy:
parser:
sequence:
- reference: "UsingKeyword"
- choice:
- reference: "UsingDirectivePath"
- reference: "UsingDirectiveDeconstruction"
- reference: "ForKeyword"
- choice:
- reference: "Asterisk"
- reference: "TypeName"
terminator:
reference: "Semicolon"
# Added an optional `global` keyword
0.8.13:
terminatedBy:
parser:
sequence:
- reference: "UsingKeyword"
- choice:
- reference: "UsingDirectivePath"
- reference: "UsingDirectiveDeconstruction"
- reference: "ForKeyword"
- choice:
- reference: "Asterisk"
- reference: "TypeName"
- optional:
reference: "GlobalKeyword"
terminator:
reference: "Semicolon"

- name: "UsingDirectivePath"
kind: "Parser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,13 @@

- name: "GlobalKeyword"
kind: "Scanner"
unversioned:
trailingContext:
scanner:
terminal: "global"
notFollowedBy:
reference: "IdentifierPart"
versioned:
0.8.13:
trailingContext:
scanner:
terminal: "global"
notFollowedBy:
reference: "IdentifierPart"

- name: "GweiKeyword"
kind: "Scanner"
Expand Down
9 changes: 6 additions & 3 deletions crates/solidity/inputs/language/src/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ slang_grammar! {
| ForKeyword
| FromKeyword
| FunctionKeyword
| GlobalKeyword
| HexKeyword
| HoursKeyword
| IfKeyword
Expand Down Expand Up @@ -160,6 +159,9 @@ slang_grammar! {
// Introduced in 0.8.4
| ErrorKeyword
| RevertKeyword

// Introduced in 0.8.13
| GlobalKeyword
) ;

parser ABICoderPragma = (ABICoderKeyword Identifier) ;
Expand Down Expand Up @@ -540,7 +542,7 @@ slang_grammar! {

parser UserDefinedValueTypeDefinition = { introduced in "0.8.8" ((TypeKeyword Identifier IsKeyword ElementaryType) terminated by Semicolon) } ;

parser UsingDirective = ((UsingKeyword (UsingDirectivePath | UsingDirectiveDeconstruction) ForKeyword (Asterisk | TypeName) (GlobalKeyword ?)) terminated by Semicolon) ;
parser UsingDirective = ((UsingKeyword (UsingDirectivePath | UsingDirectiveDeconstruction) ForKeyword (Asterisk | TypeName) ({ introduced in "0.8.13" GlobalKeyword } ?)) terminated by Semicolon) ;

parser UsingDirectiveDeconstruction = (UsingDirectiveSymbolsList delimited by OpenBrace and CloseBrace) ;

Expand Down Expand Up @@ -888,7 +890,6 @@ slang_grammar! {
scanner ForKeyword = "for" ;
scanner FromKeyword = "from" ;
scanner FunctionKeyword = "function" ;
scanner GlobalKeyword = "global" ;
scanner HexKeyword = "hex" ;
scanner HoursKeyword = "hours" ;
scanner IfKeyword = "if" ;
Expand Down Expand Up @@ -982,4 +983,6 @@ slang_grammar! {
scanner ErrorKeyword = { introduced in "0.8.4" "error" } ;
scanner RevertKeyword = { introduced in "0.8.4" "revert" } ;

// Introduced in 0.8.13
scanner GlobalKeyword = { introduced in "0.8.13" "global" } ;
}
18 changes: 13 additions & 5 deletions crates/solidity/outputs/cargo/crate/src/generated/language.rs

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

18 changes: 13 additions & 5 deletions crates/solidity/outputs/npm/crate/src/generated/language.rs

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.

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.

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.

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.

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

Loading

0 comments on commit 987c639

Please sign in to comment.