move ast definitions into its own package

This commit is contained in:
2026-08-03 08:39:48 +02:00
parent 939043dd8b
commit a2ccf60eb1
2 changed files with 57 additions and 45 deletions
+50 -1
View File
@@ -1 +1,50 @@
# todo: move ast stuff from parser module to here
import "@source/lexer"
hide TokenId :: alias lexer.TokenId
NodeId :: distinct u32
ExtraId :: distinct u32
NO_ID_NODE :: maxval!(NodeId)
NO_ID_EXTRA :: maxval!(ExtraId)
# unsafe access on its own; NodeKind serves as a the tag
# that determines the variant.
NodeData :: union {
token_id TokenId
node_id NodeId
extra_id ExtraId
}
Node :: struct {
kind NodeKind
main_token TokenId
data0 NodeData = NodeData{ node_id = NO_ID_NODE }
data1 NodeData = NodeData{ node_id = NO_ID_NODE }
}
NodeKind :: enum {
# LITERALS:
# * main_token: token literal
literal_int
literal_float
literal_string
# IDENTIFIER EXPR:
# * main_token: token literal
expr_identifier
expr_unary
expr_binary
# DECL:
# * main_token: symbol name (identifier)
# * data0: ExtraId
# + extra[data0]: NodeId - type identifier node
# + extra[data0 + 1]: NodeId - initializer expression
# * data1: TokenId of either `::` or `=` indicating mutability
stmt_decl
invalid
}