2022-08-12 09:11:43 -06:00
|
|
|
package parser
|
|
|
|
|
2022-08-14 23:47:42 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/arf/file"
|
|
|
|
import "git.tebibyte.media/sashakoshka/arf/types"
|
|
|
|
|
2022-08-12 09:11:43 -06:00
|
|
|
// 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 {
|
2022-08-12 10:55:17 -06:00
|
|
|
license string
|
|
|
|
author string
|
|
|
|
|
2022-08-15 12:04:57 -06:00
|
|
|
requires []string
|
2022-08-18 15:39:19 -06:00
|
|
|
typeSections map[string] *TypeSection
|
2022-08-20 11:24:56 -06:00
|
|
|
objtSections map[string] *ObjtSection
|
2022-08-21 00:40:04 -06:00
|
|
|
enumSections map[string] *EnumSection
|
2022-08-23 08:56:37 -06:00
|
|
|
faceSections map[string] *FaceSection
|
2022-08-15 13:09:07 -06:00
|
|
|
dataSections map[string] *DataSection
|
2022-08-12 09:11:43 -06:00
|
|
|
}
|
2022-08-14 23:47:42 -06:00
|
|
|
|
|
|
|
// Identifier represents a chain of arguments separated by a dot.
|
|
|
|
type Identifier struct {
|
|
|
|
location file.Location
|
2022-08-15 15:05:57 -06:00
|
|
|
trail []string
|
2022-08-14 23:47:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2022-08-16 08:44:02 -06:00
|
|
|
// only applicable for arrays. a value of zero means it has an
|
2022-08-14 23:47:42 -06:00
|
|
|
// undefined/dynamic length.
|
2022-08-16 08:44:02 -06:00
|
|
|
length uint64
|
2022-08-14 23:47:42 -06:00
|
|
|
|
2022-08-15 12:04:57 -06:00
|
|
|
// only applicable for basic.
|
2022-08-14 23:47:42 -06:00
|
|
|
name Identifier
|
|
|
|
|
2022-08-15 12:04:57 -06:00
|
|
|
// not applicable for basic.
|
2022-08-14 23:47:42 -06:00
|
|
|
points *Type
|
|
|
|
}
|
|
|
|
|
|
|
|
// Declaration represents a variable declaration.
|
|
|
|
type Declaration struct {
|
|
|
|
location file.Location
|
|
|
|
name string
|
2022-08-16 13:50:34 -06:00
|
|
|
what Type
|
2022-08-14 23:47:42 -06:00
|
|
|
}
|
|
|
|
|
2022-08-16 22:49:49 -06:00
|
|
|
// ObjectInitializationValues represents a list of object member initialization
|
2022-08-16 21:45:25 -06:00
|
|
|
// attributes.
|
2022-08-16 22:49:49 -06:00
|
|
|
type ObjectInitializationValues struct {
|
2022-08-16 21:45:25 -06:00
|
|
|
location file.Location
|
|
|
|
attributes map[string] Argument
|
2022-08-14 23:47:42 -06:00
|
|
|
}
|
|
|
|
|
2022-08-16 22:49:49 -06:00
|
|
|
// ArrayInitializationValues represents a list of attributes initializing an
|
|
|
|
// array.
|
|
|
|
type ArrayInitializationValues struct {
|
|
|
|
location file.Location
|
|
|
|
values []Argument
|
|
|
|
}
|
|
|
|
|
2022-08-14 23:47:42 -06:00
|
|
|
// 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 (
|
2022-08-17 09:30:17 -06:00
|
|
|
ArgumentKindNil ArgumentKind = iota
|
|
|
|
|
2022-08-14 23:47:42 -06:00
|
|
|
// [name argument]
|
|
|
|
// [name argument argument]
|
|
|
|
// etc...
|
2022-08-17 09:30:17 -06:00
|
|
|
ArgumentKindPhrase = iota
|
2022-08-14 23:47:42 -06:00
|
|
|
|
2022-08-16 11:43:36 -06:00
|
|
|
// {name}
|
|
|
|
ArgumentKindDereference
|
|
|
|
|
|
|
|
// {name 23}
|
|
|
|
ArgumentKindSubscript
|
|
|
|
|
2022-08-16 21:45:25 -06:00
|
|
|
// .name value
|
|
|
|
// but like, a lot of them
|
2022-08-16 22:49:49 -06:00
|
|
|
ArgumentKindObjectInitializationValues
|
|
|
|
|
|
|
|
// value value...
|
|
|
|
ArgumentKindArrayInitializationValues
|
2022-08-14 23:47:42 -06:00
|
|
|
|
|
|
|
// name.name
|
|
|
|
// name.name.name
|
|
|
|
// etc...
|
|
|
|
ArgumentKindIdentifier
|
|
|
|
|
|
|
|
// name:Type
|
|
|
|
// name:{Type}
|
2022-08-16 21:45:25 -06:00
|
|
|
// name:{Type ..}
|
2022-08-14 23:47:42 -06:00
|
|
|
// name:{Type 23}
|
|
|
|
// etc...
|
|
|
|
ArgumentKindDeclaration
|
|
|
|
|
|
|
|
// -1337
|
|
|
|
ArgumentKindInt
|
|
|
|
|
|
|
|
// 1337
|
|
|
|
ArgumentKindUInt
|
|
|
|
|
|
|
|
// 0.44
|
|
|
|
ArgumentKindFloat
|
|
|
|
|
|
|
|
// "hello world"
|
|
|
|
ArgumentKindString
|
|
|
|
|
|
|
|
// 'S'
|
|
|
|
ArgumentKindRune
|
|
|
|
|
|
|
|
// + - * / etc...
|
2022-08-15 12:04:57 -06:00
|
|
|
// this is only used as a phrase command
|
2022-08-14 23:47:42 -06:00
|
|
|
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
|
2022-08-16 13:50:34 -06:00
|
|
|
kind ArgumentKind
|
2022-08-14 23:47:42 -06:00
|
|
|
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
|
2022-08-18 14:56:42 -06:00
|
|
|
permission types.Permission
|
2022-08-16 22:49:49 -06:00
|
|
|
value Argument
|
2022-08-18 14:56:42 -06:00
|
|
|
}
|
|
|
|
|
2022-08-20 00:46:40 -06:00
|
|
|
// TypeSection represents a blind type definition.
|
|
|
|
type TypeSection struct {
|
2022-08-18 14:56:42 -06:00
|
|
|
location file.Location
|
|
|
|
name string
|
|
|
|
|
2022-08-20 10:40:44 -06:00
|
|
|
inherits Type
|
2022-08-18 14:56:42 -06:00
|
|
|
permission types.Permission
|
|
|
|
defaultValue Argument
|
|
|
|
}
|
|
|
|
|
2022-08-20 10:40:44 -06:00
|
|
|
// ObjtMember represents a part of an object type definition.
|
|
|
|
type ObjtMember struct {
|
2022-08-20 00:46:40 -06:00
|
|
|
location file.Location
|
|
|
|
name string
|
2022-08-24 16:22:47 -06:00
|
|
|
|
2022-08-20 00:46:40 -06:00
|
|
|
what Type
|
2022-08-24 16:29:15 -06:00
|
|
|
bitWidth uint64
|
2022-08-20 00:46:40 -06:00
|
|
|
permission types.Permission
|
2022-08-20 10:40:44 -06:00
|
|
|
defaultValue Argument
|
2022-08-20 00:46:40 -06:00
|
|
|
}
|
|
|
|
|
2022-08-20 10:40:44 -06:00
|
|
|
// ObjtSection represents an object type definition
|
|
|
|
type ObjtSection struct {
|
2022-08-18 14:56:42 -06:00
|
|
|
location file.Location
|
2022-08-20 00:46:40 -06:00
|
|
|
name string
|
2022-08-24 16:22:47 -06:00
|
|
|
|
2022-08-24 16:52:31 -06:00
|
|
|
inherits Identifier
|
2022-08-20 00:46:40 -06:00
|
|
|
permission types.Permission
|
2022-08-23 23:16:44 -06:00
|
|
|
// TODO: order matters here we need to store these in an array
|
2022-08-20 10:40:44 -06:00
|
|
|
members map[string] ObjtMember
|
2022-08-14 23:47:42 -06:00
|
|
|
}
|
2022-08-21 00:40:04 -06:00
|
|
|
|
2022-08-23 23:16:44 -06:00
|
|
|
type EnumMember struct {
|
|
|
|
location file.Location
|
|
|
|
name string
|
|
|
|
value Argument
|
|
|
|
}
|
|
|
|
|
2022-08-21 00:40:04 -06:00
|
|
|
// EnumSection represents an enumerated type section.
|
|
|
|
type EnumSection struct {
|
|
|
|
location file.Location
|
|
|
|
name string
|
|
|
|
|
|
|
|
what Type
|
|
|
|
permission types.Permission
|
2022-08-23 23:16:44 -06:00
|
|
|
members []EnumMember
|
2022-08-21 00:40:04 -06:00
|
|
|
}
|
2022-08-23 08:56:37 -06:00
|
|
|
|
|
|
|
// FaceBehavior represents a behavior of an interface section.
|
|
|
|
type FaceBehavior struct {
|
|
|
|
location file.Location
|
|
|
|
name string
|
|
|
|
|
|
|
|
inputs []Declaration
|
|
|
|
outputs []Declaration
|
|
|
|
}
|
|
|
|
|
|
|
|
// FaceSection represents an interface type section.
|
|
|
|
type FaceSection struct {
|
|
|
|
location file.Location
|
|
|
|
name string
|
2022-08-24 16:57:07 -06:00
|
|
|
inherits Identifier
|
2022-08-23 08:56:37 -06:00
|
|
|
|
|
|
|
permission types.Permission
|
|
|
|
behaviors map[string] FaceBehavior
|
|
|
|
}
|