From ef375810fba14269db3320770ad6efb482dd1df1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 3 Sep 2022 22:56:08 -0400 Subject: [PATCH] Did the same thing with type specifiers --- parser/argument.go | 5 ++--- parser/node-traits.go | 15 +++++++++++++++ parser/tree-tostring.go | 2 +- parser/tree.go | 16 ++++++++-------- parser/type.go | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/parser/argument.go b/parser/argument.go index c86b717..c56a8d7 100644 --- a/parser/argument.go +++ b/parser/argument.go @@ -42,9 +42,8 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error) return } - declaration := Declaration { - what: what, - } + declaration := Declaration { } + declaration.what = what declaration.setName(identifier.trail[0]) declaration.setLocation(argument.Location()) diff --git a/parser/node-traits.go b/parser/node-traits.go index d6ac5df..3493aa6 100644 --- a/parser/node-traits.go +++ b/parser/node-traits.go @@ -43,3 +43,18 @@ func (trait nameable) Name () (name string) { func (trait *nameable) setName (name string) { trait.name = name } + +// typeable allows a node to have a type. +type typeable struct { + what Type +} + +// Type returns the type of the node. +func (trait typeable) Type () (what Type) { + return trait.what +} + +// setType sets the type of the node. +func (trait *typeable) setType (what Type) () { + +} diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index 35a3d35..6ef1978 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -309,7 +309,7 @@ func (section *TypeSection) ToString (indent int) (output string) { "type ", section.permission.ToString(), " ", section.name, ":", - section.inherits.ToString()) + section.what.ToString()) isComplexInitialization := section.defaultValue.kind == ArgumentKindObjectInitializationValues || diff --git a/parser/tree.go b/parser/tree.go index 90cda2c..bf99c55 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -62,7 +62,7 @@ type Type struct { type Declaration struct { locatable nameable - what Type + typeable } // ObjectInitializationValues represents a list of object member initialization @@ -150,8 +150,8 @@ type Argument struct { type DataSection struct { locatable nameable + typeable - what Type permission types.Permission value Argument } @@ -160,8 +160,8 @@ type DataSection struct { type TypeSection struct { locatable nameable + typeable - inherits Type permission types.Permission defaultValue Argument } @@ -170,8 +170,8 @@ type TypeSection struct { type ObjtMember struct { locatable nameable - - what Type + typeable + bitWidth uint64 permission types.Permission defaultValue Argument @@ -181,8 +181,8 @@ type ObjtMember struct { type ObjtSection struct { locatable nameable + inherits Identifier - inherits Identifier permission types.Permission members []ObjtMember } @@ -198,8 +198,8 @@ type EnumMember struct { type EnumSection struct { locatable nameable - - what Type + typeable + permission types.Permission members []EnumMember } diff --git a/parser/type.go b/parser/type.go index cc4e60f..b6620c2 100644 --- a/parser/type.go +++ b/parser/type.go @@ -31,7 +31,7 @@ func (parser *ParsingOperation) parseTypeSection () ( if err != nil { return } err = parser.nextToken() if err != nil { return } - section.inherits, err = parser.parseType() + section.what, err = parser.parseType() if err != nil { return } // parse default values