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() {
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
}

View File

@ -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
}

View File

@ -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 <value>)
// (.name <value> .name (.name <value))
ArgumentKindObjectDefaultValues
// <4 32 98 5>
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