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

118 lines
2.5 KiB
Go
Raw Permalink Normal View History

2022-09-22 21:51:45 +00:00
package analyzer
2022-10-11 22:31:37 +00:00
import "git.tebibyte.media/arf/arf/file"
2022-09-22 21:51:45 +00:00
import "git.tebibyte.media/arf/arf/parser"
2022-10-11 22:31:37 +00:00
import "git.tebibyte.media/arf/arf/infoerr"
2022-09-22 21:51:45 +00: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 21:51:45 +00:00
// Dereference
// Variable
// IntLiteral
// UIntLiteral
// FloatLiteral
// StringLiteral
2022-10-11 22:31:37 +00:00
What () (what Type)
Location () (location file.Location)
NewError (message string, kind infoerr.ErrorKind) (err error)
2022-09-22 21:51:45 +00:00
ToString (indent int) (output string)
Equals (value any) (equal bool)
Value () (value any)
2022-10-15 00:06:11 +00:00
Resolve () (constant Argument, err error)
canBePassedAs (what Type) (allowed bool)
2022-09-22 21:51:45 +00: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 21:51:45 +00:00
// analyzeArgument analyzes an argument
2022-10-12 03:53:38 +00:00
func (analyzer analysisOperation) analyzeArgument (
2022-09-22 21:51:45 +00:00
inputArgument parser.Argument,
) (
outputArgument Argument,
err error,
2022-09-22 21:51:45 +00:00
) {
switch inputArgument.Kind() {
case parser.ArgumentKindNil:
2022-09-29 21:34:51 +00:00
panic("invalid state: attempt to analyze nil argument")
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindPhrase:
2022-09-26 22:28:21 +00:00
// TODO
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindDereference:
2022-09-26 22:28:21 +00:00
// TODO
2022-09-22 21:51:45 +00:00
2022-09-29 21:34:51 +00:00
case parser.ArgumentKindList:
2022-09-26 22:28:21 +00:00
// TODO
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindIdentifier:
2022-09-26 22:28:21 +00:00
// TODO
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindDeclaration:
2022-09-26 22:28:21 +00:00
// TODO
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindInt:
2022-10-11 22:31:37 +00:00
outputArgument = IntLiteral {
value: inputArgument.Value().(int64),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindUInt:
2022-10-11 22:31:37 +00:00
outputArgument = UIntLiteral {
value: inputArgument.Value().(uint64),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindFloat:
2022-10-11 22:31:37 +00:00
outputArgument = FloatLiteral {
value: inputArgument.Value().(float64),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 21:51:45 +00:00
case parser.ArgumentKindString:
2022-10-11 22:31:37 +00:00
outputArgument = StringLiteral {
value: inputArgument.Value().(string),
locatable: locatable {
location: inputArgument.Location(),
},
}
2022-09-22 21:51:45 +00:00
}
return
}