Skip to content

Commit

Permalink
Reserve keywords more correctly in DSL v1 (#644)
Browse files Browse the repository at this point in the history
The DSL v1 and the codegen assumes that keyword "enablement" is the same
as the keyword being reserved, i.e. not usable in the identifier
position. This patch uses that to correctly reserve keywords and parse
correctly more code.

While this still unfortunately does not handle the known cases where the
atom can be accepted as identifier or a keyword, i.e. `emit` in 0.4.22,
this is strictly more correct and this will help by minimizing the final
diff once we switch to DSL v2, since the new definition already uses
these correct enabled/reserved version ranges.

Ref #638
  • Loading branch information
Xanewok authored Nov 8, 2023
1 parent a59a464 commit cb57044
Show file tree
Hide file tree
Showing 41 changed files with 1,115 additions and 465 deletions.
30 changes: 17 additions & 13 deletions crates/solidity/inputs/language/src/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,8 @@ slang_grammar! {
scanner EventKeyword = "event" ;
scanner ExperimentalKeyword = "experimental" ;
scanner ExternalKeyword = "external" ;
scanner FallbackKeyword = "fallback" ;
scanner FalseKeyword = "false" ;
scanner FinalKeyword = "final" ;
scanner FinneyKeyword = "finney" ;
scanner ForKeyword = "for" ;
scanner FromKeyword = "from" ;
scanner FunctionKeyword = "function" ;
Expand All @@ -901,13 +899,11 @@ slang_grammar! {
scanner NewKeyword = "new" ;
scanner NullKeyword = "null" ;
scanner OfKeyword = "of" ;
scanner OverrideKeyword = "override" ;
scanner PayableKeyword = "payable" ;
scanner PragmaKeyword = "pragma" ;
scanner PrivateKeyword = "private" ;
scanner PublicKeyword = "public" ;
scanner PureKeyword = "pure" ;
scanner ReceiveKeyword = "receive" ;
scanner RelocatableKeyword = "relocatable" ;
scanner ReturnKeyword = "return" ;
scanner ReturnsKeyword = "returns" ;
Expand All @@ -918,7 +914,6 @@ slang_grammar! {
scanner StringKeyword = "string" ;
scanner StructKeyword = "struct" ;
scanner SwitchKeyword = "switch" ;
scanner SzaboKeyword = "szabo" ;
scanner ThrowKeyword = "throw" ;
scanner TrueKeyword = "true" ;
scanner TypeKeyword = "type";
Expand All @@ -931,6 +926,9 @@ slang_grammar! {
scanner WhileKeyword = "while" ;
scanner YearsKeyword = "years" ;

// Always reserved but used since 0.6.0
scanner TryKeyword = "try" ;

// introduced in 0.4.21
// WRONG, it is both a keyword AND identifier for some versions.
scanner EmitKeyword = { introduced in "0.4.21" "emit" } ;
Expand All @@ -956,19 +954,25 @@ slang_grammar! {
scanner SupportsKeyword = { introduced in "0.5.0" "supports" } ;
scanner TypedefKeyword = { introduced in "0.5.0" "typedef" } ;

// Introduced in 0.6.0
scanner LeaveKeyword = { introduced in "0.6.0" "leave" } ; // warning: used in yul
scanner TryKeyword = { introduced in "0.6.0" "try" } ;
scanner VirtualKeyword = { introduced in "0.6.0" "virtual" } ;
// Reserved since 0.5.0 and used since 0.8.0
scanner UncheckedKeyword = { introduced in "0.5.0" "unchecked" } ;
// Reserved since 0.5.0 and used since 0.6.5
scanner ImmutableKeyword = { introduced in "0.5.0" "immutable" } ;
// Reserved since 0.5.0 and used since 0.6.0
scanner OverrideKeyword = { introduced in "0.5.0" "override" } ;

// Introduced in 0.6.5
scanner ImmutableKeyword = { introduced in "0.6.5" "immutable" } ;
// Introduced in 0.6.0
scanner FallbackKeyword = { introduced in "0.6.0" "fallback" } ;
scanner ReceiveKeyword = { introduced in "0.6.0" "receive" } ;
scanner LeaveKeyword = { introduced in "0.6.0" "leave" } ; // warning: used in yul
scanner VirtualKeyword = { introduced in "0.6.0" "virtual" } ;

// Introduced in 0.6.11
scanner GweiKeyword = { introduced in "0.6.11" "gwei" } ;

// Introduced in 0.8.0
scanner UncheckedKeyword = { introduced in "0.8.0" "unchecked" } ;
// Removed in 0.7.0
scanner FinneyKeyword = { removed in "0.7.0" "finney" } ;
scanner SzaboKeyword = { removed in "0.7.0" "szabo" } ;

// Introduced in 0.8.4
scanner ErrorKeyword = { introduced in "0.8.4" "error" } ;
Expand Down
138 changes: 80 additions & 58 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.

Loading

0 comments on commit cb57044

Please sign in to comment.