From 8d10d965ff4b55aabc460fc7e3719fa7cf387744 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 8 Mar 2024 22:55:50 +0100 Subject: [PATCH] fix: Support the constant state modifier in function types --- .../inputs/language/src/definition.rs | 1 + .../slang_solidity/src/generated/language.rs | 7 ++++ .../generated/napi_interface/ast_selectors.rs | 1 + .../package/src/ast/generated/ast_types.ts | 1 + .../outputs/spec/generated/grammar.ebnf | 1 + .../public/03-types/01-advanced-types.md | 2 +- .../generated/0.4.11-success.yml | 32 +++++++++++++++++++ .../{0.4.11-failure.yml => 0.5.0-failure.yml} | 0 8 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.4.11-success.yml rename crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/{0.4.11-failure.yml => 0.5.0-failure.yml} (100%) diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 5ee46ebcce..2f3ab7f8b9 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -2696,6 +2696,7 @@ codegen_language_macros::compile!(Language( EnumVariant(reference = ExternalKeyword), EnumVariant(reference = PrivateKeyword), EnumVariant(reference = PublicKeyword), + EnumVariant(reference = ConstantKeyword, enabled = Till("0.5.0")), EnumVariant(reference = PureKeyword, enabled = From("0.4.16")), EnumVariant(reference = ViewKeyword, enabled = From("0.4.16")), EnumVariant(reference = PayableKeyword) 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 7b3e7895bc..7b0488cd46 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -2734,6 +2734,13 @@ impl Language { TokenKind::PublicKeyword, ); choice.consider(input, result)?; + if !self.version_is_at_least_0_5_0 { + let result = self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ); + choice.consider(input, result)?; + } if self.version_is_at_least_0_4_16 { 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 9ea381bed2..7951eaf73e 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 @@ -1829,6 +1829,7 @@ impl Selector { TokenKind::ExternalKeyword, TokenKind::PrivateKeyword, TokenKind::PublicKeyword, + TokenKind::ConstantKeyword, TokenKind::PureKeyword, TokenKind::ViewKeyword, TokenKind::PayableKeyword, 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 1cb89a68b2..11ae037e18 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 @@ -4413,6 +4413,7 @@ export class FunctionTypeAttribute { case TokenKind.ExternalKeyword: case TokenKind.PrivateKeyword: case TokenKind.PublicKeyword: + case TokenKind.ConstantKeyword: case TokenKind.PureKeyword: case TokenKind.ViewKeyword: case TokenKind.PayableKeyword: diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index 3c86890497..16e4cc3b12 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -887,6 +887,7 @@ FunctionTypeAttribute = INTERNAL_KEYWORD | EXTERNAL_KEYWORD | PRIVATE_KEYWORD | PUBLIC_KEYWORD + | CONSTANT_KEYWORD (* Deprecated in 0.5.0 *) | PURE_KEYWORD (* Introduced in 0.4.16 *) | VIEW_KEYWORD (* Introduced in 0.4.16 *) | PAYABLE_KEYWORD; diff --git a/crates/solidity/outputs/spec/generated/public/03-types/01-advanced-types.md b/crates/solidity/outputs/spec/generated/public/03-types/01-advanced-types.md index 055227b757..6e0d93977d 100644 --- a/crates/solidity/outputs/spec/generated/public/03-types/01-advanced-types.md +++ b/crates/solidity/outputs/spec/generated/public/03-types/01-advanced-types.md @@ -26,7 +26,7 @@ ``` -
FunctionTypeAttribute = INTERNAL_KEYWORD
| EXTERNAL_KEYWORD
| PRIVATE_KEYWORD
| PUBLIC_KEYWORD
| PURE_KEYWORD (* Introduced in 0.4.16 *)
| VIEW_KEYWORD (* Introduced in 0.4.16 *)
| PAYABLE_KEYWORD;
+
FunctionTypeAttribute = INTERNAL_KEYWORD
| EXTERNAL_KEYWORD
| PRIVATE_KEYWORD
| PUBLIC_KEYWORD
| CONSTANT_KEYWORD (* Deprecated in 0.5.0 *)
| PURE_KEYWORD (* Introduced in 0.4.16 *)
| VIEW_KEYWORD (* Introduced in 0.4.16 *)
| PAYABLE_KEYWORD;
```{ .ebnf #MappingType } diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.4.11-success.yml new file mode 100644 index 0000000000..26479f5115 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.4.11-success.yml @@ -0,0 +1,32 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ function () constant internal returns (uint) │ 0..44 + +Errors: [] + +Tree: + - (FunctionType): # "function () constant internal returns (uint)\n" (0..45) + - (function_keyword꞉ FunctionKeyword): "function" # (0..8) + - (parameters꞉ ParametersDeclaration): # " ()" (8..11) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (open_paren꞉ OpenParen): "(" # (9..10) + - (parameters꞉ Parameters): [] # (10..10) + - (close_paren꞉ CloseParen): ")" # (10..11) + - (attributes꞉ FunctionTypeAttributes): # " constant internal" (11..29) + - (item꞉ FunctionTypeAttribute): # " constant" (11..20) + - (leading_trivia꞉ Whitespace): " " # (11..12) + - (variant꞉ ConstantKeyword): "constant" # (12..20) + - (item꞉ FunctionTypeAttribute): # " internal" (20..29) + - (leading_trivia꞉ Whitespace): " " # (20..21) + - (variant꞉ InternalKeyword): "internal" # (21..29) + - (returns꞉ ReturnsDeclaration): # " returns (uint)\n" (29..45) + - (leading_trivia꞉ Whitespace): " " # (29..30) + - (returns_keyword꞉ ReturnsKeyword): "returns" # (30..37) + - (variables꞉ ParametersDeclaration): # " (uint)\n" (37..45) + - (leading_trivia꞉ Whitespace): " " # (37..38) + - (open_paren꞉ OpenParen): "(" # (38..39) + - (parameters꞉ Parameters): # "uint" (39..43) + - (item꞉ Parameter) ► (type_name꞉ TypeName) ► (variant꞉ ElementaryType) ► (variant꞉ UintKeyword): "uint" # (39..43) + - (close_paren꞉ CloseParen): ")" # (43..44) + - (trailing_trivia꞉ EndOfLine): "\n" # (44..45) diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.5.0-failure.yml similarity index 100% rename from crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.4.11-failure.yml rename to crates/solidity/testing/snapshots/cst_output/FunctionType/constant_state_mutability/generated/0.5.0-failure.yml