103 lines
1.0 KiB
V
103 lines
1.0 KiB
V
module ast
|
|
import tokenizer { Token, VuaToken }
|
|
|
|
struct Nil {}
|
|
|
|
struct String {
|
|
contents string
|
|
}
|
|
|
|
struct Number {
|
|
contents string
|
|
}
|
|
|
|
struct Boolean {
|
|
value bool
|
|
}
|
|
|
|
@[packed]
|
|
struct TableFlags {
|
|
array bool
|
|
object bool
|
|
enum bool
|
|
class bool
|
|
struct bool
|
|
}
|
|
|
|
struct Table {
|
|
flag TableFlags
|
|
data []Variable
|
|
}
|
|
|
|
struct Class {
|
|
properties []VariableDef
|
|
methods []Function
|
|
}
|
|
|
|
struct Function {
|
|
name string
|
|
params []VariableDef
|
|
body []Token
|
|
}
|
|
|
|
struct FunctionRef {
|
|
index u32
|
|
}
|
|
|
|
struct Lambda {
|
|
params []VariableDef
|
|
body []Token
|
|
scope ?FunctionRef
|
|
}
|
|
|
|
struct VariableDef {
|
|
name string
|
|
type VuaTaggedType
|
|
}
|
|
|
|
struct Variable {
|
|
// maybe this name should be a null terminated string
|
|
name string
|
|
value Expr
|
|
}
|
|
|
|
struct Expr {
|
|
index u32
|
|
type VuaTaggedType
|
|
}
|
|
|
|
enum VuaTaggedType as u8 {
|
|
nil
|
|
string
|
|
number
|
|
boolean
|
|
table
|
|
function
|
|
}
|
|
|
|
|
|
type TokenIndex = u32
|
|
|
|
@[heap]
|
|
struct Nodes {
|
|
}
|
|
|
|
@[heap]
|
|
struct Tokens {
|
|
}
|
|
|
|
struct AST {
|
|
tokens Tokens
|
|
nodes Nodes
|
|
pos int
|
|
}
|
|
|
|
union NodeData {
|
|
}
|
|
|
|
struct Node {
|
|
token_type VuaToken
|
|
data NodeData
|
|
}
|
|
|