Parser tree changes

This commit is contained in:
Sasha Koshka 2022-09-26 18:28:21 -04:00
parent f6ff3c725d
commit edd4b39642
3 changed files with 35 additions and 22 deletions

View File

@ -29,33 +29,49 @@ func (analyzer AnalysisOperation) analyzeArgument (
) { ) {
switch inputArgument.Kind() { switch inputArgument.Kind() {
case parser.ArgumentKindNil: case parser.ArgumentKindNil:
panic (
"invalid state: attempt to analyze nil argument")
case parser.ArgumentKindPhrase: case parser.ArgumentKindPhrase:
// TODO
case parser.ArgumentKindDereference: case parser.ArgumentKindDereference:
// TODO
case parser.ArgumentKindSubscript: case parser.ArgumentKindSubscript:
// TODO
case parser.ArgumentKindObjectDefaultValues: case parser.ArgumentKindObjectDefaultValues:
// TODO
case parser.ArgumentKindArrayDefaultValues: case parser.ArgumentKindArrayDefaultValues:
// TODO
case parser.ArgumentKindIdentifier: case parser.ArgumentKindIdentifier:
// TODO
case parser.ArgumentKindDeclaration: case parser.ArgumentKindDeclaration:
// TODO
case parser.ArgumentKindInt: case parser.ArgumentKindInt:
outputArgument = IntLiteral(inputArgument.Value().(int64))
case parser.ArgumentKindUInt: case parser.ArgumentKindUInt:
outputArgument = UIntLiteral(inputArgument.Value().(uint64))
case parser.ArgumentKindFloat: case parser.ArgumentKindFloat:
outputArgument = FloatLiteral(inputArgument.Value().(float64))
case parser.ArgumentKindString: case parser.ArgumentKindString:
outputArgument = StringLiteral(inputArgument.Value().(string))
case parser.ArgumentKindRune: case parser.ArgumentKindRune:
outputArgument = RuneLiteral(inputArgument.Value().(rune))
case parser.ArgumentKindOperator: case parser.ArgumentKindOperator:
panic (
"invalid state: attempt to analyze operator argument " +
"directly")
} }
return return
} }

View File

@ -60,11 +60,17 @@ func (trait permissionable) Permission () (permission types.Permission) {
// valuable allows a node to have an argument value. // valuable allows a node to have an argument value.
type valuable struct { type valuable struct {
value Argument values []Argument
} }
// Value returns the value argument of the node. // Length returns the amount of default values in the node.
func (trait valuable) Value () (value Argument) { func (node valuable) Length () (length int) {
value = trait.value 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 return
} }

View File

@ -52,6 +52,7 @@ type TypeMember struct {
nameable nameable
typeable typeable
permissionable permissionable
valuable
bitWidth uint64 bitWidth uint64
} }
@ -72,9 +73,6 @@ type Type struct {
// if non-nil, this type defines new members. // if non-nil, this type defines new members.
members []TypeMember members []TypeMember
// the default value of the type.
defaultValue Argument
} }
// Declaration represents a variable declaration. // Declaration represents a variable declaration.
@ -84,13 +82,6 @@ type Declaration struct {
typeable 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 // ArgumentKind specifies the type of thing the value of an argument should be
// cast to. // cast to.
type ArgumentKind int type ArgumentKind int
@ -109,13 +100,6 @@ const (
// {name 23} // {name 23}
ArgumentKindSubscript ArgumentKindSubscript
// (.name <value>)
// (.name <value> .name (.name <value))
ArgumentKindObjectDefaultValues
// <4 32 98 5>
ArgumentKindArrayDefaultValues
// name.name // name.name
// name.name.name // name.name.name
// etc... // etc...
@ -249,6 +233,13 @@ type Phrase struct {
// Block represents a scoped/indented block of code. // Block represents a scoped/indented block of code.
type Block []Phrase 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. // FuncSection represents a function section.
type FuncSection struct { type FuncSection struct {
locatable locatable