Skip to content

Commit

Permalink
feat: Support contextual error/revert/global keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Sep 19, 2023
1 parent 08f4272 commit 59c30dd
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 89 deletions.
12 changes: 4 additions & 8 deletions crates/solidity/inputs/language/src/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ slang_grammar! {
| FinneyKeyword
| ForKeyword
| FunctionKeyword
| GlobalKeyword
| HexKeyword
| HoursKeyword
| IfKeyword
Expand Down Expand Up @@ -96,7 +95,6 @@ slang_grammar! {
| RelocatableKeyword
| ReturnKeyword
| ReturnsKeyword
| RevertKeyword
| SecondsKeyword
| SolidityKeyword
| StaticKeyword
Expand Down Expand Up @@ -156,9 +154,6 @@ slang_grammar! {

// Introduced in 0.8.0
| UncheckedKeyword

// Introduced in 0.8.4
| ErrorKeyword
) ;

parser ABICoderPragma = (ABICoderKeyword Identifier) ;
Expand Down Expand Up @@ -885,7 +880,6 @@ slang_grammar! {
scanner FinneyKeyword = "finney" ;
scanner ForKeyword = "for" ;
scanner FunctionKeyword = "function" ;
scanner GlobalKeyword = "global" ;
scanner HexKeyword = "hex" ;
scanner HoursKeyword = "hours" ;
scanner IfKeyword = "if" ;
Expand Down Expand Up @@ -916,7 +910,6 @@ slang_grammar! {
scanner RelocatableKeyword = "relocatable" ;
scanner ReturnKeyword = "return" ;
scanner ReturnsKeyword = "returns" ;
scanner RevertKeyword = "revert" ;
scanner SecondsKeyword = "seconds" ;
scanner SolidityKeyword = "solidity" ;
scanner StaticKeyword = "static" ;
Expand Down Expand Up @@ -984,6 +977,9 @@ slang_grammar! {
scanner UncheckedKeyword = { introduced in "0.8.0" "unchecked" } ;

// Introduced in 0.8.4
scanner ErrorKeyword = { introduced in "0.8.4" "error" } ;
scanner ErrorKeyword = { introduced in "0.8.4" contextual "error" using Identifier } ;
scanner RevertKeyword = { introduced in "0.8.4" contextual "revert" using Identifier } ;

// Introduced in 0.8.13
scanner GlobalKeyword = { introduced in "0.8.13" contextual "global" using Identifier } ;
}
38 changes: 27 additions & 11 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.

38 changes: 27 additions & 11 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.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Source: >
11 │ } │ 202..207
12 │ } │ 208..209
Errors: # 3 total
Errors: # 2 total
- >
Error: Expected Equal or Semicolon.
╭─[crates/solidity/testing/snapshots/cst_output/ContractDefinition/contextual_keywords/input.sol:2:18]
Expand All @@ -24,21 +24,13 @@ Errors: # 3 total
│ ╰── Error occurred here.
───╯
- >
Error: Expected Ampersand or AmpersandAmpersand or AmpersandEqual or Asterisk or AsteriskAsterisk or AsteriskEqual or BangEqual or Bar or BarBar or BarEqual or Caret or CaretEqual or Equal or EqualEqual or GreaterThan or GreaterThanEqual or GreaterThanGreaterThan or GreaterThanGreaterThanEqual or GreaterThanGreaterThanGreaterThan or GreaterThanGreaterThanGreaterThanEqual or LessThan or LessThanEqual or LessThanLessThan or LessThanLessThanEqual or Minus or MinusEqual or Percent or PercentEqual or Plus or PlusEqual or Semicolon or Slash or SlashEqual.
╭─[crates/solidity/testing/snapshots/cst_output/ContractDefinition/contextual_keywords/input.sol:7:17]
7 │ uint256 revert;
│ ───┬──
│ ╰──── Error occurred here.
───╯
- >
Error: Expected Ampersand or AmpersandAmpersand or AmpersandEqual or Asterisk or AsteriskAsterisk or AsteriskEqual or BangEqual or Bar or BarBar or BarEqual or Caret or CaretEqual or Equal or EqualEqual or GreaterThan or GreaterThanEqual or GreaterThanGreaterThan or GreaterThanGreaterThanEqual or GreaterThanGreaterThanGreaterThan or GreaterThanGreaterThanGreaterThanEqual or LessThan or LessThanEqual or LessThanLessThan or LessThanLessThanEqual or Minus or MinusEqual or Percent or PercentEqual or Plus or PlusEqual or Semicolon or Slash or SlashEqual.
╭─[crates/solidity/testing/snapshots/cst_output/ContractDefinition/contextual_keywords/input.sol:8:17]
8 │ uint256 global;
│ ───┬──
│ ╰──── Error occurred here.
───╯
Error: Expected Equal or Semicolon.
╭─[crates/solidity/testing/snapshots/cst_output/ContractDefinition/contextual_keywords/input.sol:10:23]
10 │ revert MyError();
│ ─┬
│ ╰── Error occurred here.
────╯
Tree:
- ContractDefinition (Rule): # 0..210 "contract Contract {\n error MyError();\n\n func..."
Expand Down Expand Up @@ -80,25 +72,27 @@ Tree:
- Identifier (Token): "from" # 121..125
- Semicolon (Token): ";" # 125..126
- Statement (Rule): # 127..151 " uint256 revert;\n"
- ExpressionStatement (Rule): # 127..151 " uint256 revert;\n"
- Expression (Rule): # 127..142 " uint256"
- UnsignedIntegerType (Token): "uint256" # 135..142
- SKIPPED (Token): "revert" # 143..149
- VariableDeclarationStatement (Rule): # 127..151 " uint256 revert;\n"
- VariableDeclaration (Rule): # 127..149 " uint256 revert"
- TypeName (Rule): # 127..142 " uint256"
- UnsignedIntegerType (Token): "uint256" # 135..142
- Identifier (Token): "revert" # 143..149
- Semicolon (Token): ";" # 149..150
- Statement (Rule): # 151..175 " uint256 global;\n"
- ExpressionStatement (Rule): # 151..175 " uint256 global;\n"
- Expression (Rule): # 151..166 " uint256"
- UnsignedIntegerType (Token): "uint256" # 159..166
- SKIPPED (Token): "global" # 167..173
- VariableDeclarationStatement (Rule): # 151..175 " uint256 global;\n"
- VariableDeclaration (Rule): # 151..173 " uint256 global"
- TypeName (Rule): # 151..166 " uint256"
- UnsignedIntegerType (Token): "uint256" # 159..166
- Identifier (Token): "global" # 167..173
- Semicolon (Token): ";" # 173..174
- Statement (Rule): # 175..202 "\n revert MyError();\n"
- RevertStatement (Rule): # 175..202 "\n revert MyError();\n"
- RevertKeyword (Token): "revert" # 184..190
- IdentifierPath (Rule): # 190..198 " MyError"
- VariableDeclarationStatement (Rule): # 175..202 "\n revert MyError();\n"
- VariableDeclaration (Rule): # 175..198 "\n revert MyError"
- TypeName (Rule): # 175..190 "\n revert"
- IdentifierPath (Rule): # 175..190 "\n revert"
- Identifier (Token): "revert" # 184..190
- Identifier (Token): "MyError" # 191..198
- ArgumentsDeclaration (Rule): # 198..200 "()"
- OpenParen (Token): "(" # 198..199
- CloseParen (Token): ")" # 199..200
- SKIPPED (Token): "()" # 198..200
- Semicolon (Token): ";" # 200..201
- CloseBrace (Token): "}" # 206..207
- CloseBrace (Token): "}" # 208..209
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@ Source: >
11 │ } │ 202..207
12 │ } │ 208..209
Errors: # 2 total
- >
Error: Expected Ampersand or AmpersandAmpersand or AmpersandEqual or Asterisk or AsteriskAsterisk or AsteriskEqual or BangEqual or Bar or BarBar or BarEqual or Caret or CaretEqual or Equal or EqualEqual or GreaterThan or GreaterThanEqual or GreaterThanGreaterThan or GreaterThanGreaterThanEqual or GreaterThanGreaterThanGreaterThan or GreaterThanGreaterThanGreaterThanEqual or LessThan or LessThanEqual or LessThanLessThan or LessThanLessThanEqual or Minus or MinusEqual or Percent or PercentEqual or Plus or PlusEqual or Semicolon or Slash or SlashEqual.
╭─[crates/solidity/testing/snapshots/cst_output/ContractDefinition/contextual_keywords/input.sol:7:17]
7 │ uint256 revert;
│ ───┬──
│ ╰──── Error occurred here.
───╯
- >
Error: Expected Ampersand or AmpersandAmpersand or AmpersandEqual or Asterisk or AsteriskAsterisk or AsteriskEqual or BangEqual or Bar or BarBar or BarEqual or Caret or CaretEqual or Equal or EqualEqual or GreaterThan or GreaterThanEqual or GreaterThanGreaterThan or GreaterThanGreaterThanEqual or GreaterThanGreaterThanGreaterThan or GreaterThanGreaterThanGreaterThanEqual or LessThan or LessThanEqual or LessThanLessThan or LessThanLessThanEqual or Minus or MinusEqual or Percent or PercentEqual or Plus or PlusEqual or Semicolon or Slash or SlashEqual.
╭─[crates/solidity/testing/snapshots/cst_output/ContractDefinition/contextual_keywords/input.sol:8:17]
8 │ uint256 global;
│ ───┬──
│ ╰──── Error occurred here.
───╯
Errors: []

Tree:
- ContractDefinition (Rule): # 0..210 "contract Contract {\n error MyError();\n\n func..."
Expand Down Expand Up @@ -71,16 +55,18 @@ Tree:
- Identifier (Token): "from" # 121..125
- Semicolon (Token): ";" # 125..126
- Statement (Rule): # 127..151 " uint256 revert;\n"
- ExpressionStatement (Rule): # 127..151 " uint256 revert;\n"
- Expression (Rule): # 127..142 " uint256"
- UnsignedIntegerType (Token): "uint256" # 135..142
- SKIPPED (Token): "revert" # 143..149
- VariableDeclarationStatement (Rule): # 127..151 " uint256 revert;\n"
- VariableDeclaration (Rule): # 127..149 " uint256 revert"
- TypeName (Rule): # 127..142 " uint256"
- UnsignedIntegerType (Token): "uint256" # 135..142
- Identifier (Token): "revert" # 143..149
- Semicolon (Token): ";" # 149..150
- Statement (Rule): # 151..175 " uint256 global;\n"
- ExpressionStatement (Rule): # 151..175 " uint256 global;\n"
- Expression (Rule): # 151..166 " uint256"
- UnsignedIntegerType (Token): "uint256" # 159..166
- SKIPPED (Token): "global" # 167..173
- VariableDeclarationStatement (Rule): # 151..175 " uint256 global;\n"
- VariableDeclaration (Rule): # 151..173 " uint256 global"
- TypeName (Rule): # 151..166 " uint256"
- UnsignedIntegerType (Token): "uint256" # 159..166
- Identifier (Token): "global" # 167..173
- Semicolon (Token): ";" # 173..174
- Statement (Rule): # 175..202 "\n revert MyError();\n"
- RevertStatement (Rule): # 175..202 "\n revert MyError();\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Source: >
1 │ using {add as +, sub, mul, div as /} for Int global; │ 0..52
Errors: # 1 total
Errors: # 2 total
- >
Error: Expected CloseBrace or Comma.
╭─[crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/input.sol:1:12]
Expand All @@ -12,6 +12,14 @@ Errors: # 1 total
│ ────────────┬───────────
│ ╰───────────── Error occurred here.
───╯
- >
Error: Expected GlobalKeyword or Semicolon.
╭─[crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/input.sol:1:46]
1 │ using {add as +, sub, mul, div as /} for Int global;
│ ───┬──
│ ╰──── Error occurred here.
───╯
Tree:
- UsingDirective (Rule): # 0..52 "using {add as +, sub, mul, div as /} for Int globa..."
Expand All @@ -28,5 +36,5 @@ Tree:
- TypeName (Rule): # 40..44 " Int"
- IdentifierPath (Rule): # 40..44 " Int"
- Identifier (Token): "Int" # 41..44
- GlobalKeyword (Token): "global" # 45..51
- SKIPPED (Token): "global" # 45..51
- Semicolon (Token): ";" # 51..52
Loading

0 comments on commit 59c30dd

Please sign in to comment.