2022-09-22 15:51:45 -06:00
|
|
|
package analyzer
|
|
|
|
|
|
|
|
import "git.tebibyte.media/arf/arf/parser"
|
|
|
|
// import "git.tebibyte.media/arf/arf/infoerr"
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// Dereference
|
|
|
|
// Subscript
|
|
|
|
// Object
|
|
|
|
// Array
|
|
|
|
// Variable
|
|
|
|
// IntLiteral
|
|
|
|
// UIntLiteral
|
|
|
|
// FloatLiteral
|
|
|
|
// StringLiteral
|
|
|
|
// RuneLiteral
|
|
|
|
|
|
|
|
ToString (indent int) (output string)
|
|
|
|
}
|
|
|
|
|
|
|
|
// analyzeArgument analyzes an argument
|
|
|
|
func (analyzer AnalysisOperation) analyzeArgument (
|
|
|
|
inputArgument parser.Argument,
|
|
|
|
) (
|
|
|
|
outputArgument Argument,
|
|
|
|
) {
|
|
|
|
switch inputArgument.Kind() {
|
|
|
|
case parser.ArgumentKindNil:
|
2022-09-26 16:28:21 -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
|
|
|
|
|
|
|
case parser.ArgumentKindSubscript:
|
2022-09-26 16:28:21 -06:00
|
|
|
// TODO
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindObjectDefaultValues:
|
2022-09-26 16:28:21 -06:00
|
|
|
// TODO
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindArrayDefaultValues:
|
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-09-26 16:28:21 -06:00
|
|
|
outputArgument = IntLiteral(inputArgument.Value().(int64))
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindUInt:
|
2022-09-26 16:28:21 -06:00
|
|
|
outputArgument = UIntLiteral(inputArgument.Value().(uint64))
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindFloat:
|
2022-09-26 16:28:21 -06:00
|
|
|
outputArgument = FloatLiteral(inputArgument.Value().(float64))
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindString:
|
2022-09-26 16:28:21 -06:00
|
|
|
outputArgument = StringLiteral(inputArgument.Value().(string))
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindRune:
|
2022-09-26 16:28:21 -06:00
|
|
|
outputArgument = RuneLiteral(inputArgument.Value().(rune))
|
2022-09-22 15:51:45 -06:00
|
|
|
|
|
|
|
case parser.ArgumentKindOperator:
|
2022-09-26 16:28:21 -06:00
|
|
|
panic (
|
|
|
|
"invalid state: attempt to analyze operator argument " +
|
|
|
|
"directly")
|
2022-09-22 15:51:45 -06:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|