From 15a7e6216a424d1073ad161f337442525c7c75c2 Mon Sep 17 00:00:00 2001 From: Virgil Serbanuta Date: Mon, 26 Aug 2024 23:54:55 +0300 Subject: [PATCH] Simplify trait parsing; use method attributes --- 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 a305429..d127ff8 100644 --- a/rust-semantics/preprocessing/crate.md +++ b/rust-semantics/preprocessing/crate.md @@ -8,57 +8,23 @@ module CRATE imports private RUST-REPRESENTATION imports private RUST-RUNNING-CONFIGURATION - 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 e35e93d..00557a9 100644 --- a/rust-semantics/preprocessing/initialization.md +++ b/rust-semantics/preprocessing/initialization.md @@ -5,15 +5,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 ... @@ -42,7 +33,7 @@ module INITIALIZATION Trait:TypePath, Name:Identifier, P:NormalizedFunctionParameterList, R:Type, B:BlockExpression, - _A:OuterAttributes + A:OuterAttributes ) => .K ... @@ -56,6 +47,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 0746f21..eb830bd 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