Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify trait parsing; use method attributes #62

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust-semantics/preprocessing/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module RUST-PREPROCESSING-CONFIGURATION
<method-params> .NormalizedFunctionParameterList </method-params>
<method-return-type> ():Type </method-return-type>
<method-implementation> empty:FunctionBodyRepresentation </method-implementation>
<method-outer-attributes> `emptyOuterAttributes`(.KList):OuterAttributes </method-outer-attributes>
</method>
</methods>
</trait>
Expand Down
44 changes: 5 additions & 39 deletions rust-semantics/preprocessing/crate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
12 changes: 2 additions & 10 deletions rust-semantics/preprocessing/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<k> traitInitializer(Name:TypePath) => .K
...
Expand Down Expand Up @@ -43,7 +34,7 @@ module INITIALIZATION
Trait:TypePath,
Name:Identifier, P:NormalizedFunctionParameterList,
R:Type, B:BlockExpression,
_A:OuterAttributes
A:OuterAttributes
) => .K
...
</k>
Expand All @@ -57,6 +48,7 @@ module INITIALIZATION
<method-params> P </method-params>
<method-return-type> R </method-return-type>
<method-implementation> block(B) </method-implementation>
<method-outer-attributes> A </method-outer-attributes>
</method>
...
</methods>
Expand Down
6 changes: 1 addition & 5 deletions rust-semantics/preprocessing/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 7 additions & 5 deletions rust-semantics/preprocessing/trait-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
3 changes: 2 additions & 1 deletion rust-semantics/preprocessing/trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
3 changes: 2 additions & 1 deletion rust-semantics/rust-common-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading