From 8501a82c758d210acc6e6fe3a432a222439607b7 Mon Sep 17 00:00:00 2001 From: Virgil <25692529+virgil-serbanuta@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:38:06 +0300 Subject: [PATCH] Simplify trait parsing; use method attributes (#62) Co-authored-by: Virgil Serbanuta --- rust-semantics/preprocessing/configuration.md | 1 + rust-semantics/preprocessing/crate.md | 44 +++---------------- .../preprocessing/initialization.md | 12 +---- rust-semantics/preprocessing/syntax.md | 6 +-- rust-semantics/preprocessing/trait-methods.md | 12 ++--- rust-semantics/preprocessing/trait.md | 3 +- rust-semantics/rust-common-syntax.md | 3 +- 7 files changed, 20 insertions(+), 61 deletions(-) diff --git a/rust-semantics/preprocessing/configuration.md b/rust-semantics/preprocessing/configuration.md index 585745f..e39afb2 100644 --- a/rust-semantics/preprocessing/configuration.md +++ b/rust-semantics/preprocessing/configuration.md @@ -23,6 +23,7 @@ module RUST-PREPROCESSING-CONFIGURATION .NormalizedFunctionParameterList ():Type empty:FunctionBodyRepresentation + `emptyOuterAttributes`(.KList):OuterAttributes diff --git a/rust-semantics/preprocessing/crate.md b/rust-semantics/preprocessing/crate.md index 66d5e3b..099a3e6 100644 --- a/rust-semantics/preprocessing/crate.md +++ b/rust-semantics/preprocessing/crate.md @@ -8,57 +8,23 @@ module CRATE imports private RUST-PREPROCESSING-SYNTAX imports private RUST-REPRESENTATION - syntax Initializer ::= crateParser(crate: Crate, traitName: MaybeIdentifier, traitFunctions: Map) - - rule crateParser(C:Crate) => crateParser(... crate : C, traitName : .Identifier, traitFunctions : .Map) - rule crateParser - ( ... crate: - (_Atts:InnerAttributes (_A:OuterAttributes _U:UseDeclaration):Item Is:Items):Crate + ( (_Atts:InnerAttributes (_A:OuterAttributes _U:UseDeclaration):Item Is:Items):Crate => (.InnerAttributes Is):Crate - , traitName : _Name:MaybeIdentifier - , traitFunctions: _TraitFunctions:Map ) rule (.K => traitParser(T)) ~> crateParser - ( ... crate: - (_Atts:InnerAttributes (ItemAtts:OuterAttributes _V:MaybeVisibility T:Trait):Item Is:Items):Crate - => (.InnerAttributes (ItemAtts T):Item Is):Crate - , traitName : .Identifier - , traitFunctions: .Map - ) - rule ( traitMethodsParser(.AssociatedItems, Functions:Map, Name:Identifier) - => .K + ( (_Atts:InnerAttributes (_ItemAtts:OuterAttributes _V:MaybeVisibility T:Trait):Item Is:Items):Crate + => (.InnerAttributes Is):Crate ) - ~> crateParser - ( ... crate: - (_Atts:InnerAttributes (_ItemAtts:OuterAttributes _T:Trait):Item Is:Items):Crate - => (.InnerAttributes Is):Crate - , traitName : .Identifier => Name - , traitFunctions: .Map => Functions - ) - rule (.K => CI:ConstantItem:KItem) ~> crateParser - ( ... crate: - (Atts:InnerAttributes (_ItemAtts:OuterAttributes _:MaybeVisibility CI:ConstantItem):Item Is:Items):Crate + ( (Atts:InnerAttributes (_ItemAtts:OuterAttributes _:MaybeVisibility CI:ConstantItem):Item Is:Items):Crate => (Atts Is):Crate - , traitName : _Name:MaybeIdentifier - , traitFunctions: _TraitFunctions:Map ) - rule - crateParser - ( ... crate: (_Atts:InnerAttributes .Items):Crate - , traitName : Name:Identifier - , traitFunctions: Functions:Map - ) - => traitInitializer(Name) - ~> traitMethodInitializer - ( ... traitName: Name - , functionNames:keys_list(Functions), functions: Functions - ) + rule crateParser( (_Atts:InnerAttributes .Items):Crate) => .K endmodule ``` diff --git a/rust-semantics/preprocessing/initialization.md b/rust-semantics/preprocessing/initialization.md index 2e4ff58..1f143b3 100644 --- a/rust-semantics/preprocessing/initialization.md +++ b/rust-semantics/preprocessing/initialization.md @@ -6,15 +6,6 @@ module INITIALIZATION imports private RUST-PREPROCESSING-PRIVATE-HELPERS imports private RUST-PREPROCESSING-PRIVATE-SYNTAX - rule (.K => addMethod(TraitName, F, A)) - ~> traitMethodInitializer - ( ... traitName : TraitName:TypePath - , functionNames: (ListItem(Name:Identifier:KItem) => .List) _Names:List - , functions: _Functions:Map - ((Name:Identifier:KItem |-> (A:OuterAttributes F:Function):AssociatedItem) => .Map) - ) - rule traitMethodInitializer(... functionNames: .List) => .K - rule traitInitializer(Name:TypePath) => .K ... @@ -43,7 +34,7 @@ module INITIALIZATION Trait:TypePath, Name:Identifier, P:NormalizedFunctionParameterList, R:Type, B:BlockExpression, - _A:OuterAttributes + A:OuterAttributes ) => .K ... @@ -57,6 +48,7 @@ module INITIALIZATION P R block(B) + A ... diff --git a/rust-semantics/preprocessing/syntax.md b/rust-semantics/preprocessing/syntax.md index 1b5867f..3b7fdc9 100644 --- a/rust-semantics/preprocessing/syntax.md +++ b/rust-semantics/preprocessing/syntax.md @@ -13,14 +13,10 @@ module RUST-PREPROCESSING-PRIVATE-SYNTAX imports RUST-SHARED-SYNTAX syntax Initializer ::= traitParser(Trait) - | traitMethodsParser(AssociatedItems, functions: Map, traitName:Identifier) + | traitMethodsParser(AssociatedItems, traitName:Identifier) | traitInitializer ( traitName: TypePath ) - | traitMethodInitializer - ( traitName: TypePath - , functionNames:List, functions: Map - ) syntax Initializer ::= addMethod(traitName : TypePath, function: Function, atts:OuterAttributes) | #addMethod( diff --git a/rust-semantics/preprocessing/trait-methods.md b/rust-semantics/preprocessing/trait-methods.md index 1b2c106..79bb0f7 100644 --- a/rust-semantics/preprocessing/trait-methods.md +++ b/rust-semantics/preprocessing/trait-methods.md @@ -4,11 +4,13 @@ module TRAIT-METHODS imports private RUST-PREPROCESSING-PRIVATE-HELPERS imports private RUST-PREPROCESSING-PRIVATE-SYNTAX - rule traitMethodsParser( - (A:OuterAttributes F:Function) AIs:AssociatedItems => AIs, - Functions => Functions[getFunctionName(F):Identifier:KItem <- (A F):AssociatedItem], - _Name:Identifier - ) + rule traitMethodsParser(.AssociatedItems, _Name:Identifier) + => .K + rule (.K => addMethod(TraitName, F, A)) + ~> traitMethodsParser( + (A:OuterAttributes F:Function) AIs:AssociatedItems => AIs, + TraitName:Identifier + ) endmodule ``` diff --git a/rust-semantics/preprocessing/trait.md b/rust-semantics/preprocessing/trait.md index 97c0ce1..0fc23aa 100644 --- a/rust-semantics/preprocessing/trait.md +++ b/rust-semantics/preprocessing/trait.md @@ -4,7 +4,8 @@ module TRAIT imports private RUST-PREPROCESSING-PRIVATE-SYNTAX rule traitParser(trait Name:Identifier { .InnerAttributes Functions:AssociatedItems }) - => traitMethodsParser(Functions, .Map, Name) + => traitInitializer(Name) + ~> traitMethodsParser(Functions, Name) endmodule ``` diff --git a/rust-semantics/rust-common-syntax.md b/rust-semantics/rust-common-syntax.md index 2932643..fde0f40 100644 --- a/rust-semantics/rust-common-syntax.md +++ b/rust-semantics/rust-common-syntax.md @@ -53,7 +53,8 @@ module RUST-SHARED-SYNTAX syntax Item ::= OuterAttributes VisOrMacroItem [symbol(item)] syntax NonEmptyOuterAttributes ::= NeList{OuterAttribute, ""} - syntax OuterAttributes ::= "" | NonEmptyOuterAttributes + syntax OuterAttributes ::= "" [symbol("emptyOuterAttributes")] + | NonEmptyOuterAttributes syntax VisOrMacroItem ::= VisItem | MacroItem syntax MacroItem ::= MacroInvocationSemi | MacroRulesDefinition syntax VisItem ::= MaybeVisibility VisItemItem