2022-09-03 20:17:05 -06:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import "git.tebibyte.media/arf/arf/file"
|
2022-09-03 21:03:09 -06:00
|
|
|
import "git.tebibyte.media/arf/arf/types"
|
2022-09-03 20:17:05 -06:00
|
|
|
import "git.tebibyte.media/arf/arf/infoerr"
|
|
|
|
|
|
|
|
// locatable allows a tree node to have a location.
|
|
|
|
type locatable struct {
|
|
|
|
location file.Location
|
|
|
|
}
|
|
|
|
|
|
|
|
// Location returns the location of the node.
|
2022-09-27 12:18:46 -06:00
|
|
|
func (node locatable) Location () (location file.Location) {
|
|
|
|
location = node.location
|
2022-09-03 20:17:05 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewError creates a new error at the node's location.
|
2022-09-27 12:18:46 -06:00
|
|
|
func (node locatable) NewError (
|
2022-09-03 20:17:05 -06:00
|
|
|
message string,
|
|
|
|
kind infoerr.ErrorKind,
|
|
|
|
) (
|
2022-09-04 17:30:59 -06:00
|
|
|
err error,
|
2022-09-03 20:17:05 -06:00
|
|
|
) {
|
2022-09-27 12:18:46 -06:00
|
|
|
err = infoerr.NewError(node.location, message, kind)
|
2022-09-03 21:03:09 -06:00
|
|
|
return
|
2022-09-03 20:17:05 -06:00
|
|
|
}
|
2022-09-03 20:33:34 -06:00
|
|
|
|
|
|
|
// nameable allows a tree node to have a name.
|
|
|
|
type nameable struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the name of the node.
|
2022-09-27 12:18:46 -06:00
|
|
|
func (node nameable) Name () (name string) {
|
|
|
|
name = node.name
|
2022-09-03 20:33:34 -06:00
|
|
|
return
|
|
|
|
}
|
2022-09-03 20:56:08 -06:00
|
|
|
// typeable allows a node to have a type.
|
|
|
|
type typeable struct {
|
|
|
|
what Type
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type returns the type of the node.
|
2022-09-27 12:18:46 -06:00
|
|
|
func (node typeable) Type () (what Type) {
|
|
|
|
what = node.what
|
2022-09-03 21:03:09 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// permissionable allows a node to have a permission.
|
|
|
|
type permissionable struct {
|
|
|
|
permission types.Permission
|
|
|
|
}
|
|
|
|
|
2022-09-04 01:31:35 -06:00
|
|
|
// Permission returns the permision of the node.
|
2022-09-27 12:18:46 -06:00
|
|
|
func (node permissionable) Permission () (permission types.Permission) {
|
|
|
|
permission = node.permission
|
2022-09-03 21:03:09 -06:00
|
|
|
return
|
2022-09-03 20:56:08 -06:00
|
|
|
}
|
2022-09-04 01:31:35 -06:00
|
|
|
|
|
|
|
// valuable allows a node to have an argument value.
|
|
|
|
type valuable struct {
|
2022-09-27 12:26:02 -06:00
|
|
|
argument Argument
|
2022-09-27 12:17:03 -06:00
|
|
|
}
|
|
|
|
|
2022-09-27 12:26:02 -06:00
|
|
|
// Argument returns the value argument of the node.
|
|
|
|
func (node valuable) Argument () (argument Argument) {
|
|
|
|
argument = node.argument
|
2022-09-27 12:17:03 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// multiValuable allows a node to have several argument values.
|
|
|
|
type multiValuable struct {
|
2022-09-27 12:26:02 -06:00
|
|
|
arguments []Argument
|
2022-09-04 01:31:35 -06:00
|
|
|
}
|
|
|
|
|
2022-09-27 12:26:02 -06:00
|
|
|
// Argument returns the argument at index.
|
|
|
|
func (node multiValuable) Argument (index int) (argument Argument) {
|
|
|
|
argument = node.arguments[index]
|
2022-09-26 16:28:21 -06:00
|
|
|
return
|
2022-09-27 12:17:03 -06:00
|
|
|
}
|
2022-09-26 16:28:21 -06:00
|
|
|
|
2022-09-27 12:26:02 -06:00
|
|
|
// Length returns the amount of arguments in the mode.
|
2022-09-27 12:18:46 -06:00
|
|
|
func (node multiValuable) Length () (length int) {
|
2022-09-27 12:26:02 -06:00
|
|
|
length = len(node.arguments)
|
2022-09-04 01:31:35 -06:00
|
|
|
return
|
|
|
|
}
|