Skip to content

Commit

Permalink
add ThisKeyword and SuperKeyword (#1138)
Browse files Browse the repository at this point in the history
add `ThisKeyword` and `SuperKeyword` to the grammar, instead of parsing
them as identifiers.
  • Loading branch information
OmarTawfik authored Nov 5, 2024
1 parent 4c475ec commit 44a706f
Show file tree
Hide file tree
Showing 202 changed files with 436 additions and 220 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-yaks-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/slang": patch
---

add `ThisKeyword` and `SuperKeyword` to the grammar, instead of parsing them as identifiers.
8 changes: 5 additions & 3 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -1778,8 +1778,10 @@ inherit .parent_scope
edge @expr.lexical_scope -> @tuple_expr.lexical_scope
}

;; Identifier expressions
@expr [Expression @name variant: [Identifier]] {
;; primary expressions
@expr [Expression @name (
variant: [Identifier] | variant: [SuperKeyword] | variant: [ThisKeyword]
)] {
node ref
attr (ref) node_reference = @name
attr (ref) parents = [@expr.enclosing_def]
Expand Down Expand Up @@ -1809,7 +1811,7 @@ inherit .parent_scope
;; Special case: member accesses to `super` are tagged with "super" to rank
;; virtual methods correctly
[MemberAccessExpression
operand: [Expression ["super"]]
operand: [Expression [SuperKeyword]]
@name member: [Identifier]
] {
attr (@name.ref) tag = "super"
Expand Down
24 changes: 24 additions & 0 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,11 @@ codegen_language_macros::compile!(Language(
identifier = Identifier,
definitions = [KeywordDefinition(value = Atom("struct"))]
),
Keyword(
name = SuperKeyword,
identifier = Identifier,
definitions = [KeywordDefinition(value = Atom("super"))]
),
Keyword(
name = SupportsKeyword,
identifier = Identifier,
Expand All @@ -1416,6 +1421,11 @@ codegen_language_macros::compile!(Language(
value = Atom("szabo")
)]
),
Keyword(
name = ThisKeyword,
identifier = Identifier,
definitions = [KeywordDefinition(value = Atom("this"))]
),
Keyword(
name = ThrowKeyword,
identifier = Identifier,
Expand Down Expand Up @@ -3504,6 +3514,8 @@ codegen_language_macros::compile!(Language(
reference = PayableKeyword,
enabled = From("0.6.0")
),
PrimaryExpression(reference = ThisKeyword),
PrimaryExpression(reference = SuperKeyword),
PrimaryExpression(reference = TrueKeyword),
PrimaryExpression(reference = FalseKeyword),
PrimaryExpression(reference = Identifier)
Expand Down Expand Up @@ -6081,6 +6093,12 @@ codegen_language_macros::compile!(Language(
value = Atom("suicide")
)]
),
Keyword(
name = YulSuperKeyword,
identifier = YulIdentifier,
definitions =
[KeywordDefinition(enabled = Never, value = Atom("super"))]
),
Keyword(
name = YulSupportsKeyword,
identifier = YulIdentifier,
Expand Down Expand Up @@ -6109,6 +6127,12 @@ codegen_language_macros::compile!(Language(
identifier = YulIdentifier,
definitions = [KeywordDefinition(value = Atom("timestamp"))]
),
Keyword(
name = YulThisKeyword,
identifier = YulIdentifier,
definitions =
[KeywordDefinition(enabled = Never, value = Atom("this"))]
),
Keyword(
name = YulThrowKeyword,
identifier = YulIdentifier,
Expand Down
4 changes: 4 additions & 0 deletions crates/solidity/outputs/cargo/crate/generated/public_api.txt

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 44a706f

Please sign in to comment.