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/parser/tree.go
Sasha Koshka e42bad5810 Identifiers can no longer have arguments in them
Previously [[something something].something] would have been syntactically
correct. This can lead to ugly and cluttered syntax due to violating the one
thing per line guideline (that I've forgotten to write down) and would make the
parser incredibly convoluded. Member selection in arf is not an operator and
should not be treated as such. It would be much better to just use variables for
this.
2022-08-15 17:05:57 -04:00

146 lines
3.0 KiB
Go

package parser
import "git.tebibyte.media/sashakoshka/arf/file"
import "git.tebibyte.media/sashakoshka/arf/types"
// SyntaxTree represents an abstract syntax tree. It covers an entire module. It
// can be expected to be syntactically correct, but it might not be semantically
// correct (because it has not been analyzed yet.)
type SyntaxTree struct {
license string
author string
requires []string
dataSections map[string] *DataSection
}
// Identifier represents a chain of arguments separated by a dot.
type Identifier struct {
location file.Location
trail []string
}
// TypeKind represents what kind of type a type is
type TypeKind int
const (
// TypeKindBasic either means it's a primitive, or it inherits from
// something.
TypeKindBasic TypeKind = iota
// TypeKindPointer means it's a pointer
TypeKindPointer
// TypeKindArray means it's an array.
TypeKindArray
)
// Type represents a type specifier
type Type struct {
location file.Location
mutable bool
kind TypeKind
// only applicable for arrays. a value of nil means it has an
// undefined/dynamic length.
length *Argument
// only applicable for basic.
name Identifier
// not applicable for basic.
points *Type
}
// Declaration represents a variable declaration.
type Declaration struct {
location file.Location
name string
what Type
value []Argument
}
// ObjectAttribute represents a notation to initialize object attributes. It
// contains a name, and the value that the attribute should be initialized to.
type ObjectAttribute struct {
location file.Location
name string
value Argument
}
// Phrase represents a function call or operator. In ARF they are the same
// syntactical concept.
type Phrase struct {
location file.Location
command Argument
arguments []Argument
returnsTo []Argument
}
// ArgumentKind specifies the type of thing the value of an argument should be
// cast to.
type ArgumentKind int
const (
// [name argument]
// [name argument argument]
// etc...
ArgumentKindPhrase ArgumentKind = iota
// , name value
ArgumentKindObjectAttribute
// name.name
// name.name.name
// etc...
ArgumentKindIdentifier
// name:Type
// name:{Type}
// name:{Type ...}
// name:{Type 23}
// etc...
ArgumentKindDeclaration
// -1337
ArgumentKindInt
// 1337
ArgumentKindUInt
// 0.44
ArgumentKindFloat
// "hello world"
ArgumentKindString
// 'S'
ArgumentKindRune
// + - * / etc...
// this is only used as a phrase command
ArgumentKindOperator
)
// Argument represents a value that can be placed anywhere a value goes. This
// allows things like phrases being arguments to other phrases.
type Argument struct {
location file.Location
what ArgumentKind
value any
// TODO: if there is an argument expansion operator its existence should
// be stored here in a boolean.
}
// DataSection represents a global variable.
type DataSection struct {
location file.Location
name string
what Type
value []Argument
permission types.Permission
}