From 8e7421643012debd46f1d5a17c763440634d6471 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 3 Sep 2022 22:33:34 -0400 Subject: [PATCH] Names are now composed from a nameable struct --- parser/argument.go | 12 ++++++++---- parser/node-traits.go | 19 +++++++++++++++++-- parser/tree.go | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/parser/argument.go b/parser/argument.go index eae5085..c86b717 100644 --- a/parser/argument.go +++ b/parser/argument.go @@ -41,12 +41,16 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error) infoerr.ErrorKindError) return } - - argument.kind = ArgumentKindDeclaration - argument.value = Declaration { - name: identifier.trail[0], + + declaration := Declaration { what: what, } + declaration.setName(identifier.trail[0]) + declaration.setLocation(argument.Location()) + + argument.kind = ArgumentKindDeclaration + argument.value = declaration + } else { argument.kind = ArgumentKindIdentifier argument.value = identifier diff --git a/parser/node-traits.go b/parser/node-traits.go index dc81506..d6ac5df 100644 --- a/parser/node-traits.go +++ b/parser/node-traits.go @@ -9,13 +9,13 @@ type locatable struct { } // Location returns the location of the node. -func (trait locatable) Location (location file.Location) { +func (trait locatable) Location () (location file.Location) { location = trait.location return } // setLocation sets the location of the node. -func (trait locatable) setLocation (location file.Location) { +func (trait* locatable) setLocation (location file.Location) { trait.location = location } @@ -28,3 +28,18 @@ func (trait locatable) NewError ( ) { return infoerr.NewError(trait.location, message, kind) } + +// nameable allows a tree node to have a name. +type nameable struct { + name string +} + +// Name returns the name of the node. +func (trait nameable) Name () (name string) { + name = trait.name + return +} +// setName sets the name of the node. +func (trait *nameable) setName (name string) { + trait.name = name +} diff --git a/parser/tree.go b/parser/tree.go index 64945b8..90cda2c 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -61,7 +61,7 @@ type Type struct { // Declaration represents a variable declaration. type Declaration struct { locatable - name string + nameable what Type } @@ -149,7 +149,7 @@ type Argument struct { // DataSection represents a global variable. type DataSection struct { locatable - name string + nameable what Type permission types.Permission @@ -159,7 +159,7 @@ type DataSection struct { // TypeSection represents a blind type definition. type TypeSection struct { locatable - name string + nameable inherits Type permission types.Permission @@ -169,7 +169,7 @@ type TypeSection struct { // ObjtMember represents a part of an object type definition. type ObjtMember struct { locatable - name string + nameable what Type bitWidth uint64 @@ -180,7 +180,7 @@ type ObjtMember struct { // ObjtSection represents an object type definition. type ObjtSection struct { locatable - name string + nameable inherits Identifier permission types.Permission @@ -190,14 +190,14 @@ type ObjtSection struct { // EnumMember represents a member of an enum section. type EnumMember struct { locatable - name string + nameable value Argument } // EnumSection represents an enumerated type section. type EnumSection struct { locatable - name string + nameable what Type permission types.Permission @@ -207,7 +207,7 @@ type EnumSection struct { // FaceBehavior represents a behavior of an interface section. type FaceBehavior struct { locatable - name string + nameable inputs []Declaration outputs []Declaration @@ -216,7 +216,7 @@ type FaceBehavior struct { // FaceSection represents an interface type section. type FaceSection struct { locatable - name string + nameable inherits Identifier permission types.Permission @@ -269,7 +269,7 @@ type FuncOutput struct { // FuncSection represents a function section. type FuncSection struct { locatable - name string + nameable permission types.Permission receiver *Declaration