From edd4b396424ddcf27c6d414e89baa6c22dc93ec1 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 26 Sep 2022 18:28:21 -0400 Subject: [PATCH] Parser tree changes --- analyzer/argument.go | 18 +++++++++++++++++- parser/node-traits.go | 14 ++++++++++---- parser/tree.go | 25 ++++++++----------------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/analyzer/argument.go b/analyzer/argument.go index b9f5707..5537f03 100644 --- a/analyzer/argument.go +++ b/analyzer/argument.go @@ -29,33 +29,49 @@ func (analyzer AnalysisOperation) analyzeArgument ( ) { switch inputArgument.Kind() { case parser.ArgumentKindNil: + panic ( + "invalid state: attempt to analyze nil argument") case parser.ArgumentKindPhrase: + // TODO case parser.ArgumentKindDereference: + // TODO case parser.ArgumentKindSubscript: + // TODO case parser.ArgumentKindObjectDefaultValues: + // TODO case parser.ArgumentKindArrayDefaultValues: + // TODO case parser.ArgumentKindIdentifier: + // TODO case parser.ArgumentKindDeclaration: + // TODO case parser.ArgumentKindInt: + outputArgument = IntLiteral(inputArgument.Value().(int64)) case parser.ArgumentKindUInt: + outputArgument = UIntLiteral(inputArgument.Value().(uint64)) case parser.ArgumentKindFloat: + outputArgument = FloatLiteral(inputArgument.Value().(float64)) case parser.ArgumentKindString: + outputArgument = StringLiteral(inputArgument.Value().(string)) case parser.ArgumentKindRune: + outputArgument = RuneLiteral(inputArgument.Value().(rune)) case parser.ArgumentKindOperator: - + panic ( + "invalid state: attempt to analyze operator argument " + + "directly") } return } diff --git a/parser/node-traits.go b/parser/node-traits.go index e16aeaf..2ec0da6 100644 --- a/parser/node-traits.go +++ b/parser/node-traits.go @@ -60,11 +60,17 @@ func (trait permissionable) Permission () (permission types.Permission) { // valuable allows a node to have an argument value. type valuable struct { - value Argument + values []Argument } -// Value returns the value argument of the node. -func (trait valuable) Value () (value Argument) { - value = trait.value +// Length returns the amount of default values in the node. +func (node valuable) Length () (length int) { + length = len(node.values) + return +} + +// Value returns the default value at the specified index. +func (node valuable) Value (index int) (value Argument) { + value = node.values[index] return } diff --git a/parser/tree.go b/parser/tree.go index 54a62e0..bb9147b 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -52,6 +52,7 @@ type TypeMember struct { nameable typeable permissionable + valuable bitWidth uint64 } @@ -72,9 +73,6 @@ type Type struct { // if non-nil, this type defines new members. members []TypeMember - - // the default value of the type. - defaultValue Argument } // Declaration represents a variable declaration. @@ -84,13 +82,6 @@ type Declaration struct { typeable } -// ObjectDefaultValues represents a list of object member initialization -// attributes. -type ObjectDefaultValues map[string] Argument - -// ArrayDefaultValues represents a list of elements initializing an array. -type ArrayDefaultValues []Argument - // ArgumentKind specifies the type of thing the value of an argument should be // cast to. type ArgumentKind int @@ -109,13 +100,6 @@ const ( // {name 23} ArgumentKindSubscript - // (.name ) - // (.name .name (.name - ArgumentKindArrayDefaultValues - // name.name // name.name.name // etc... @@ -249,6 +233,13 @@ type Phrase struct { // Block represents a scoped/indented block of code. type Block []Phrase +// FuncOutput represents a function output declaration. It allows for a default +// value. +type FuncOutput struct { + Declaration + valuable +} + // FuncSection represents a function section. type FuncSection struct { locatable