From ac47c39c2850a82bbe3b89f395b6e62beaa76f92 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Thu, 22 Feb 2024 02:14:12 -0800 Subject: [PATCH 1/2] add `private` to `UnnamedFunctionAttribute` till `0.5.0` --- .changeset/unlucky-trains-care.md | 5 +++++ crates/solidity/inputs/language/src/definition.rs | 1 + .../outputs/cargo/slang_solidity/src/generated/language.rs | 7 +++++++ .../src/generated/napi_interface/ast_selectors.rs | 1 + .../outputs/npm/package/src/ast/generated/ast_types.ts | 1 + crates/solidity/outputs/spec/generated/grammar.ebnf | 1 + .../spec/generated/public/02-definitions/08-functions.md | 2 +- 7 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/unlucky-trains-care.md diff --git a/.changeset/unlucky-trains-care.md b/.changeset/unlucky-trains-care.md new file mode 100644 index 0000000000..69ea7ef86d --- /dev/null +++ b/.changeset/unlucky-trains-care.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": patch +--- + +add `private` to `UnnamedFunctionAttribute` till `0.5.0` diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 5056c2655a..9b3ecd68d5 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -2374,6 +2374,7 @@ codegen_language_macros::compile!(Language( EnumVariant(reference = ExternalKeyword), EnumVariant(reference = InternalKeyword, enabled = Till("0.5.0")), EnumVariant(reference = PayableKeyword), + EnumVariant(reference = PrivateKeyword, enabled = Till("0.5.0")), EnumVariant(reference = PublicKeyword, enabled = Till("0.5.0")), EnumVariant(reference = PureKeyword), EnumVariant(reference = ViewKeyword) diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs index d2f486ff6e..b1788bb1ee 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -5034,6 +5034,13 @@ impl Language { TokenKind::PayableKeyword, ); choice.consider(input, result)?; + if !self.version_is_at_least_0_5_0 { + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); + choice.consider(input, result)?; + } if !self.version_is_at_least_0_5_0 { let result = self.parse_token_with_trivia::( input, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs index bbbcd7b088..8f34599abc 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs @@ -1733,6 +1733,7 @@ impl Selector { TokenKind::ExternalKeyword, TokenKind::InternalKeyword, TokenKind::PayableKeyword, + TokenKind::PrivateKeyword, TokenKind::PublicKeyword, TokenKind::PureKeyword, TokenKind::ViewKeyword, diff --git a/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts b/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts index 0127c6a669..e4797d362b 100644 --- a/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts +++ b/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts @@ -4211,6 +4211,7 @@ export class UnnamedFunctionAttribute { case TokenKind.ExternalKeyword: case TokenKind.InternalKeyword: case TokenKind.PayableKeyword: + case TokenKind.PrivateKeyword: case TokenKind.PublicKeyword: case TokenKind.PureKeyword: case TokenKind.ViewKeyword: diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index fc85b52910..2fcce4fcbf 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -753,6 +753,7 @@ UnnamedFunctionAttribute = ModifierInvocation | EXTERNAL_KEYWORD | INTERNAL_KEYWORD (* Deprecated in 0.5.0 *) | PAYABLE_KEYWORD + | PRIVATE_KEYWORD (* Deprecated in 0.5.0 *) | PUBLIC_KEYWORD (* Deprecated in 0.5.0 *) | PURE_KEYWORD | VIEW_KEYWORD; diff --git a/crates/solidity/outputs/spec/generated/public/02-definitions/08-functions.md b/crates/solidity/outputs/spec/generated/public/02-definitions/08-functions.md index 0944e513d6..d48368bd89 100644 --- a/crates/solidity/outputs/spec/generated/public/02-definitions/08-functions.md +++ b/crates/solidity/outputs/spec/generated/public/02-definitions/08-functions.md @@ -110,7 +110,7 @@ ``` -
(* Deprecated in 0.6.0 *)
UnnamedFunctionAttribute = ModifierInvocation
| OverrideSpecifier
| EXTERNAL_KEYWORD
| INTERNAL_KEYWORD (* Deprecated in 0.5.0 *)
| PAYABLE_KEYWORD
| PUBLIC_KEYWORD (* Deprecated in 0.5.0 *)
| PURE_KEYWORD
| VIEW_KEYWORD;
+
(* Deprecated in 0.6.0 *)
UnnamedFunctionAttribute = ModifierInvocation
| OverrideSpecifier
| EXTERNAL_KEYWORD
| INTERNAL_KEYWORD (* Deprecated in 0.5.0 *)
| PAYABLE_KEYWORD
| PRIVATE_KEYWORD (* Deprecated in 0.5.0 *)
| PUBLIC_KEYWORD (* Deprecated in 0.5.0 *)
| PURE_KEYWORD
| VIEW_KEYWORD;
```{ .ebnf #FallbackFunctionDefinition } From f2c0bfbae2bae1c7fe55ec0f9b06ef72e6539ce0 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Thu, 22 Feb 2024 02:16:38 -0800 Subject: [PATCH 2/2] add tests --- .../generated/UnnamedFunctionDefinition.rs | 5 ++++ .../generated/0.4.11-success.yml | 23 +++++++++++++++++++ .../generated/0.5.0-failure.yml | 23 +++++++++++++++++++ .../generated/0.6.0-failure.yml | 17 ++++++++++++++ .../private_attribute/input.sol | 1 + 5 files changed, 69 insertions(+) create mode 100644 crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.5.0-failure.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.6.0-failure.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/input.sol diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UnnamedFunctionDefinition.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UnnamedFunctionDefinition.rs index 711deb881e..a62c605ada 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UnnamedFunctionDefinition.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/UnnamedFunctionDefinition.rs @@ -9,6 +9,11 @@ fn internal_attribute() -> Result<()> { run("UnnamedFunctionDefinition", "internal_attribute") } +#[test] +fn private_attribute() -> Result<()> { + run("UnnamedFunctionDefinition", "private_attribute") +} + #[test] fn public_attribute() -> Result<()> { run("UnnamedFunctionDefinition", "public_attribute") diff --git a/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.4.11-success.yml new file mode 100644 index 0000000000..6dfd128753 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.4.11-success.yml @@ -0,0 +1,23 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function () private {} │ 0..22 + +Errors: [] + +Tree: + - (UnnamedFunctionDefinition): # "function () private {}\n" (0..23) + - (function_keyword꞉ FunctionKeyword): "function" # (0..8) + - (parameters꞉ ParametersDeclaration): # " ()" (8..11) + - (LeadingTrivia) ► (Whitespace): " " # (8..9) + - (open_paren꞉ OpenParen): "(" # (9..10) + - (close_paren꞉ CloseParen): ")" # (10..11) + - (attributes꞉ UnnamedFunctionAttributes): # " private" (11..19) + - (item꞉ UnnamedFunctionAttribute): # " private" (11..19) + - (LeadingTrivia) ► (Whitespace): " " # (11..12) + - (variant꞉ PrivateKeyword): "private" # (12..19) + - (body꞉ FunctionBody) ► (variant꞉ Block): # " {}\n" (19..23) + - (LeadingTrivia) ► (Whitespace): " " # (19..20) + - (open_brace꞉ OpenBrace): "{" # (20..21) + - (close_brace꞉ CloseBrace): "}" # (21..22) + - (TrailingTrivia) ► (EndOfLine): "\n" # (22..23) diff --git a/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.5.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.5.0-failure.yml new file mode 100644 index 0000000000..84dbec7733 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.5.0-failure.yml @@ -0,0 +1,23 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function () private {} │ 0..22 + +Errors: # 1 total + - > + Error: Expected ExternalKeyword or Identifier or OpenBrace or OverrideKeyword or PayableKeyword or PureKeyword or Semicolon or ViewKeyword. + ╭─[crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/input.sol:1:12] + │ + 1 │ function () private {} + │ ──────┬───── + │ ╰─────── Error occurred here. + ───╯ + +Tree: + - (UnnamedFunctionDefinition): # "function () private {}\n" (0..23) + - (function_keyword꞉ FunctionKeyword): "function" # (0..8) + - (parameters꞉ ParametersDeclaration): # " ()" (8..11) + - (LeadingTrivia) ► (Whitespace): " " # (8..9) + - (open_paren꞉ OpenParen): "(" # (9..10) + - (close_paren꞉ CloseParen): ")" # (10..11) + - (SKIPPED): " private {}\n" # (11..23) diff --git a/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.6.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.6.0-failure.yml new file mode 100644 index 0000000000..4bd8d5e7d4 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/generated/0.6.0-failure.yml @@ -0,0 +1,17 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function () private {} │ 0..22 + +Errors: # 1 total + - > + Error: Expected end of file. + ╭─[crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/input.sol:1:1] + │ + 1 │ function () private {} + │ ───────────┬─────────── + │ ╰───────────── Error occurred here. + ───╯ + +Tree: + - (SKIPPED): "function () private {}\n" # (0..23) diff --git a/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/input.sol b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/input.sol new file mode 100644 index 0000000000..eaaac043af --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/UnnamedFunctionDefinition/private_attribute/input.sol @@ -0,0 +1 @@ +function () private {}