This repository has been archived on 2024-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
arf/analyzer/argument.go

115 lines
2.4 KiB
Go
Raw Normal View History

2022-09-22 15:51:45 -06:00
package analyzer
2022-10-11 16:31:37 -06:00
import "git.tebibyte.media/arf/arf/file"
2022-09-22 15:51:45 -06:00
import "git.tebibyte.media/arf/arf/parser"
2022-10-11 16:31:37 -06:00
import "git.tebibyte.media/arf/arf/infoerr"
2022-09-22 15:51:45 -06:00
// Argument represents a value that can be placed anywhere a value goes. This
// allows things like phrases being arguments to other phrases.
type Argument interface {
// Phrase
// List
2022-09-22 15:51:45 -06:00
// Dereference
// Variable
// IntLiteral
// UIntLiteral
// FloatLiteral
// StringLiteral
2022-10-11 16:31:37 -06:00
What () (what Type)
Location () (location file.Location)
NewError (message string, kind infoerr.ErrorKind) (err error)
2022-09-22 15:51:45 -06:00
ToString (indent int) (output string)
canBePassedAs (what Type) (allowed bool)
2022-09-22 15:51:45 -06:00
}
// phrase
// is what
// list
// is what
// dereference
// if length is greater than 1
// length is 1
// is what (ignore length)
// else
// is points of reduced of what
// variable
// is what
// int
// primitive is basic signed | float
// length is 1
// uint
// primitive is basic signed | unsigned | float
// length is 1
// float
// primitive is basic float
// length is 1
// string
// primitive is basic signed | unsigned | float
// length is equal
// or
// reduced is variable array
// reduced points to signed | unsigned | float
// length is 1
2022-09-22 15:51:45 -06:00
// analyzeArgument analyzes an argument
2022-10-11 21:53:38 -06:00
func (analyzer analysisOperation) analyzeArgument (
2022-09-22 15:51:45 -06:00
inputArgument parser.Argument,
) (
outputArgument Argument,
err error,
2022-09-22 15:51:45 -06:00
) {
switch inputArgument.Kind() {
case parser.ArgumentKindNil:
2022-09-29 15:34:51 -06:00
panic("invalid state: attempt to analyze nil argument")
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindPhrase:
2022-09-26 16:28:21 -06:00
// TODO
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindDereference:
2022-09-26 16:28:21 -06:00
// TODO
2022-09-22 15:51:45 -06:00
2022-09-29 15:34:51 -06:00
case parser.ArgumentKindList:
2022-09-26 16:28:21 -06:00
// TODO
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindIdentifier:
2022-09-26 16:28:21 -06:00
// TODO
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindDeclaration:
2022-09-26 16:28:21 -06:00
// TODO
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindInt:
2022-10-11 16:31:37 -06:00
outputArgument = IntLiteral {
value: inputArgument.Value().(int64),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindUInt:
2022-10-11 16:31:37 -06:00
outputArgument = UIntLiteral {
value: inputArgument.Value().(uint64),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindFloat:
2022-10-11 16:31:37 -06:00
outputArgument = FloatLiteral {
value: inputArgument.Value().(float64),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 15:51:45 -06:00
case parser.ArgumentKindString:
2022-10-11 16:31:37 -06:00
outputArgument = StringLiteral {
value: inputArgument.Value().(string),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 15:51:45 -06:00
}
return
}