From 7db6464d591cc46b981c28dcbc2b94116e40eb06 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:21:30 -0700 Subject: [PATCH] --- --- .../inputs/language/src/definition.rs | 18 ++++++++------ .../src/generated/language/generated/mod.rs | 12 +++++----- .../src/generated/ast/generated/ast_types.ts | 24 +++++++++---------- .../outputs/spec/generated/grammar.ebnf | 8 +++---- .../01-file-structure/02-source-unit.md | 2 +- .../public/02-definitions/01-contracts.md | 2 +- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 7c72787883..974097bc49 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -51,6 +51,7 @@ codegen_language_macros::compile!(Language( Enum( name = SourceUnitMember, variants = [ + // Variants that can be identified using the first token: EnumVariant(reference = PragmaDirective), EnumVariant(reference = ImportDirective), EnumVariant(reference = ContractDefinition), @@ -62,17 +63,18 @@ codegen_language_macros::compile!(Language( reference = FunctionDefinition, enabled = From("0.7.1") ), - EnumVariant( - reference = ConstantDefinition, - enabled = From("0.7.4") - ), EnumVariant(reference = ErrorDefinition, enabled = From("0.8.4")), EnumVariant( reference = UserDefinedValueTypeDefinition, enabled = From("0.8.8") ), EnumVariant(reference = UsingDirective, enabled = From("0.8.13")), - EnumVariant(reference = EventDefinition, enabled = From("0.8.22")) + EnumVariant(reference = EventDefinition, enabled = From("0.8.22")), + // These variants are more complex, and require backtracking: + EnumVariant( + reference = ConstantDefinition, + enabled = From("0.7.4") + ) ] ) ] @@ -2120,6 +2122,7 @@ codegen_language_macros::compile!(Language( Enum( name = ContractMember, variants = [ + // Variants that can be identified using the first token: EnumVariant(reference = UsingDirective), EnumVariant(reference = FunctionDefinition), EnumVariant( @@ -2142,12 +2145,13 @@ codegen_language_macros::compile!(Language( EnumVariant(reference = StructDefinition), EnumVariant(reference = EnumDefinition), EnumVariant(reference = EventDefinition), - EnumVariant(reference = StateVariableDefinition), EnumVariant(reference = ErrorDefinition, enabled = From("0.8.4")), EnumVariant( reference = UserDefinedValueTypeDefinition, enabled = From("0.8.8") - ) + ), + // These variants are more complex, and require backtracking: + EnumVariant(reference = StateVariableDefinition) ] ) ] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/generated/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/generated/mod.rs index f1c76e38e7..998526b61f 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/generated/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language/generated/mod.rs @@ -1023,8 +1023,6 @@ impl Language { choice.consider(input, result)?; let result = self.event_definition(input); choice.consider(input, result)?; - let result = self.state_variable_definition(input); - choice.consider(input, result)?; if self.version_is_at_least_0_8_4 { let result = self.error_definition(input); choice.consider(input, result)?; @@ -1033,6 +1031,8 @@ impl Language { let result = self.user_defined_value_type_definition(input); choice.consider(input, result)?; } + let result = self.state_variable_definition(input); + choice.consider(input, result)?; choice.finish(input) }) .with_label(EdgeLabel::Variant) @@ -4252,10 +4252,6 @@ impl Language { let result = self.function_definition(input); choice.consider(input, result)?; } - if self.version_is_at_least_0_7_4 { - let result = self.constant_definition(input); - choice.consider(input, result)?; - } if self.version_is_at_least_0_8_4 { let result = self.error_definition(input); choice.consider(input, result)?; @@ -4272,6 +4268,10 @@ impl Language { let result = self.event_definition(input); choice.consider(input, result)?; } + if self.version_is_at_least_0_7_4 { + let result = self.constant_definition(input); + choice.consider(input, result)?; + } choice.finish(input) }) .with_label(EdgeLabel::Variant) diff --git a/crates/solidity/outputs/npm/package/src/generated/ast/generated/ast_types.ts b/crates/solidity/outputs/npm/package/src/generated/ast/generated/ast_types.ts index a58953204d..208de3cf67 100644 --- a/crates/solidity/outputs/npm/package/src/generated/ast/generated/ast_types.ts +++ b/crates/solidity/outputs/npm/package/src/generated/ast/generated/ast_types.ts @@ -3769,11 +3769,11 @@ export class SourceUnitMember { | StructDefinition | EnumDefinition | FunctionDefinition - | ConstantDefinition | ErrorDefinition | UserDefinedValueTypeDefinition | UsingDirective - | EventDefinition = once(() => { + | EventDefinition + | ConstantDefinition = once(() => { const variant = ast_internal.selectChoice(this.cst); switch (variant.kind) { @@ -3793,8 +3793,6 @@ export class SourceUnitMember { return new EnumDefinition(variant as NonterminalNode); case NonterminalKind.FunctionDefinition: return new FunctionDefinition(variant as NonterminalNode); - case NonterminalKind.ConstantDefinition: - return new ConstantDefinition(variant as NonterminalNode); case NonterminalKind.ErrorDefinition: return new ErrorDefinition(variant as NonterminalNode); case NonterminalKind.UserDefinedValueTypeDefinition: @@ -3803,6 +3801,8 @@ export class SourceUnitMember { return new UsingDirective(variant as NonterminalNode); case NonterminalKind.EventDefinition: return new EventDefinition(variant as NonterminalNode); + case NonterminalKind.ConstantDefinition: + return new ConstantDefinition(variant as NonterminalNode); default: assert.fail(`Unexpected variant: ${variant.kind}`); @@ -3822,11 +3822,11 @@ export class SourceUnitMember { | StructDefinition | EnumDefinition | FunctionDefinition - | ConstantDefinition | ErrorDefinition | UserDefinedValueTypeDefinition | UsingDirective - | EventDefinition { + | EventDefinition + | ConstantDefinition { return this.fetch(); } } @@ -4017,9 +4017,9 @@ export class ContractMember { | StructDefinition | EnumDefinition | EventDefinition - | StateVariableDefinition | ErrorDefinition - | UserDefinedValueTypeDefinition = once(() => { + | UserDefinedValueTypeDefinition + | StateVariableDefinition = once(() => { const variant = ast_internal.selectChoice(this.cst); switch (variant.kind) { @@ -4043,12 +4043,12 @@ export class ContractMember { return new EnumDefinition(variant as NonterminalNode); case NonterminalKind.EventDefinition: return new EventDefinition(variant as NonterminalNode); - case NonterminalKind.StateVariableDefinition: - return new StateVariableDefinition(variant as NonterminalNode); case NonterminalKind.ErrorDefinition: return new ErrorDefinition(variant as NonterminalNode); case NonterminalKind.UserDefinedValueTypeDefinition: return new UserDefinedValueTypeDefinition(variant as NonterminalNode); + case NonterminalKind.StateVariableDefinition: + return new StateVariableDefinition(variant as NonterminalNode); default: assert.fail(`Unexpected variant: ${variant.kind}`); @@ -4070,9 +4070,9 @@ export class ContractMember { | StructDefinition | EnumDefinition | EventDefinition - | StateVariableDefinition | ErrorDefinition - | UserDefinedValueTypeDefinition { + | UserDefinedValueTypeDefinition + | StateVariableDefinition { return this.fetch(); } } diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index 5b3f4b9815..244ac85973 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -22,11 +22,11 @@ SourceUnitMember = (* variant: *) PragmaDirective | (* variant: *) StructDefinition (* Introduced in 0.6.0 *) | (* variant: *) EnumDefinition (* Introduced in 0.6.0 *) | (* variant: *) FunctionDefinition (* Introduced in 0.7.1 *) - | (* variant: *) ConstantDefinition (* Introduced in 0.7.4 *) | (* variant: *) ErrorDefinition (* Introduced in 0.8.4 *) | (* variant: *) UserDefinedValueTypeDefinition (* Introduced in 0.8.8 *) | (* variant: *) UsingDirective (* Introduced in 0.8.13 *) - | (* variant: *) EventDefinition; (* Introduced in 0.8.22 *) + | (* variant: *) EventDefinition (* Introduced in 0.8.22 *) + | (* variant: *) ConstantDefinition; (* Introduced in 0.7.4 *) (* 1.3. Pragma Directives: *) @@ -643,9 +643,9 @@ ContractMember = (* variant: *) UsingDirective | (* variant: *) StructDefinition | (* variant: *) EnumDefinition | (* variant: *) EventDefinition - | (* variant: *) StateVariableDefinition | (* variant: *) ErrorDefinition (* Introduced in 0.8.4 *) - | (* variant: *) UserDefinedValueTypeDefinition; (* Introduced in 0.8.8 *) + | (* variant: *) UserDefinedValueTypeDefinition (* Introduced in 0.8.8 *) + | (* variant: *) StateVariableDefinition; (* 2.2. Interfaces: *) diff --git a/crates/solidity/outputs/spec/generated/public/01-file-structure/02-source-unit.md b/crates/solidity/outputs/spec/generated/public/01-file-structure/02-source-unit.md index 7a1d506e89..218185a0ed 100644 --- a/crates/solidity/outputs/spec/generated/public/01-file-structure/02-source-unit.md +++ b/crates/solidity/outputs/spec/generated/public/01-file-structure/02-source-unit.md @@ -20,6 +20,6 @@ ``` -
+ --8<-- "crates/solidity/inputs/language/docs/01-file-structure/02-source-unit.md" diff --git a/crates/solidity/outputs/spec/generated/public/02-definitions/01-contracts.md b/crates/solidity/outputs/spec/generated/public/02-definitions/01-contracts.md index 17142f4a06..dc1602626f 100644 --- a/crates/solidity/outputs/spec/generated/public/02-definitions/01-contracts.md +++ b/crates/solidity/outputs/spec/generated/public/02-definitions/01-contracts.md @@ -38,6 +38,6 @@ ``` - + --8<-- "crates/solidity/inputs/language/docs/02-definitions/01-contracts.md"