This commit is contained in:
2025-01-08 19:04:40 +01:00
parent a987479617
commit aa0fab43e4
6 changed files with 166 additions and 123 deletions

51
ast.h
View File

@@ -40,7 +40,8 @@ typedef enum {
/// lhs catch rhs
/// lhs catch |err| rhs
/// main_token is the `catch` keyword.
/// payload is determined by looking at the next token after the `catch` keyword.
/// payload is determined by looking at the next token after the `catch`
/// keyword.
AST_NODE_CATCH,
/// `lhs.a`. main_token is the dot. rhs is the identifier token index.
AST_NODE_FIELD_ACCESS,
@@ -196,7 +197,8 @@ typedef enum {
/// main_token might be a ** token, which is shared with a parent/child
/// pointer type and may require special handling.
AST_NODE_PTR_TYPE,
/// lhs is index into ptr_type_bit_range. rhs is the element type expression.
/// lhs is index into ptr_type_bit_range. rhs is the element type
/// expression.
/// main_token is the asterisk if a single item pointer or the lbracket
/// if a slice, many-item pointer, or C-pointer
/// main_token might be a ** token, which is shared with a parent/child
@@ -208,7 +210,8 @@ typedef enum {
/// `lhs[b..c]`. rhs is index into Slice
/// main_token is the lbracket.
AST_NODE_SLICE,
/// `lhs[b..c :d]`. rhs is index into SliceSentinel. Slice end c can be omitted.
/// `lhs[b..c :d]`. rhs is index into SliceSentinel. Slice end c can be
/// omitted.
/// main_token is the lbracket.
AST_NODE_SLICE_SENTINEL,
/// `lhs.*`. rhs is unused.
@@ -221,7 +224,8 @@ typedef enum {
AST_NODE_ARRAY_INIT_ONE_COMMA,
/// `.{lhs, rhs}`. lhs and rhs can be omitted.
AST_NODE_ARRAY_INIT_DOT_TWO,
/// Same as `array_init_dot_two` except there is known to be a trailing comma
/// Same as `array_init_dot_two` except there is known to be a trailing
/// comma
/// before the final rbrace.
AST_NODE_ARRAY_INIT_DOT_TWO_COMMA,
/// `.{a, b}`. `sub_list[lhs..rhs]`.
@@ -229,7 +233,8 @@ typedef enum {
/// Same as `array_init_dot` except there is known to be a trailing comma
/// before the final rbrace.
AST_NODE_ARRAY_INIT_DOT_COMMA,
/// `lhs{a, b}`. `sub_range_list[rhs]`. lhs can be omitted which means `.{a, b}`.
/// `lhs{a, b}`. `sub_range_list[rhs]`. lhs can be omitted which means
/// `.{a, b}`.
AST_NODE_ARRAY_INIT,
/// Same as `array_init` except there is known to be a trailing comma
/// before the final rbrace.
@@ -244,7 +249,8 @@ typedef enum {
/// main_token is the lbrace.
/// No trailing comma before the rbrace.
AST_NODE_STRUCT_INIT_DOT_TWO,
/// Same as `struct_init_dot_two` except there is known to be a trailing comma
/// Same as `struct_init_dot_two` except there is known to be a trailing
/// comma
/// before the final rbrace.
AST_NODE_STRUCT_INIT_DOT_TWO_COMMA,
/// `.{.a = b, .c = d}`. `sub_list[lhs..rhs]`.
@@ -283,7 +289,8 @@ typedef enum {
/// main_token is the `(`.
AST_NODE_ASYNC_CALL_COMMA,
/// `switch(lhs) {}`. `SubRange[rhs]`.
/// `main_token` is the identifier of a preceding label, if any; otherwise `switch`.
/// `main_token` is the identifier of a preceding label, if any; otherwise
/// `switch`.
AST_NODE_SWITCH,
/// Same as switch except there is known to be a trailing comma
/// before the final rbrace
@@ -313,7 +320,8 @@ typedef enum {
AST_NODE_WHILE,
/// `for (lhs) rhs`.
AST_NODE_FOR_SIMPLE,
/// `for (lhs[0..inputs]) lhs[inputs + 1] else lhs[inputs + 2]`. `For[rhs]`.
/// `for (lhs[0..inputs]) lhs[inputs + 1] else lhs[inputs + 2]`.
/// `For[rhs]`.
AST_NODE_FOR,
/// `lhs..rhs`. rhs can be omitted.
AST_NODE_FOR_RANGE,
@@ -346,13 +354,15 @@ typedef enum {
/// main_token is the `fn` keyword.
/// extern function declarations use this tag.
AST_NODE_FN_PROTO_MULTI,
/// `fn (a: b) addrspace(e) linksection(f) callconv(g) rhs`. `FnProtoOne[lhs]`.
/// `fn (a: b) addrspace(e) linksection(f) callconv(g) rhs`.
/// `FnProtoOne[lhs]`.
/// zero or one parameters.
/// anytype and ... parameters are omitted from the AST tree.
/// main_token is the `fn` keyword.
/// extern function declarations use this tag.
AST_NODE_FN_PROTO_ONE,
/// `fn (a: b, c: d) addrspace(e) linksection(f) callconv(g) rhs`. `FnProto[lhs]`.
/// `fn (a: b, c: d) addrspace(e) linksection(f) callconv(g) rhs`.
/// `FnProto[lhs]`.
/// anytype and ... parameters are omitted from the AST tree.
/// main_token is the `fn` keyword.
/// extern function declarations use this tag.
@@ -373,8 +383,10 @@ typedef enum {
/// Both lhs and rhs unused.
AST_NODE_UNREACHABLE_LITERAL,
/// Both lhs and rhs unused.
/// Most identifiers will not have explicit AST nodes, however for expressions
/// which could be one of many different kinds of AST nodes, there will be an
/// Most identifiers will not have explicit AST nodes, however for
/// expressions
/// which could be one of many different kinds of AST nodes, there will be
/// an
/// identifier AST node for it.
AST_NODE_IDENTIFIER,
/// lhs is the dot token index, rhs unused, main_token is the identifier.
@@ -392,23 +404,27 @@ typedef enum {
/// `@a(lhs, rhs)`. lhs and rhs may be omitted.
/// main_token is the builtin token.
AST_NODE_BUILTIN_CALL_TWO,
/// Same as builtin_call_two but there is known to be a trailing comma before the rparen.
/// Same as builtin_call_two but there is known to be a trailing comma
/// before the rparen.
AST_NODE_BUILTIN_CALL_TWO_COMMA,
/// `@a(b, c)`. `sub_list[lhs..rhs]`.
/// main_token is the builtin token.
AST_NODE_BUILTIN_CALL,
/// Same as builtin_call but there is known to be a trailing comma before the rparen.
/// Same as builtin_call but there is known to be a trailing comma before
/// the rparen.
AST_NODE_BUILTIN_CALL_COMMA,
/// `error{a, b}`.
/// rhs is the rbrace, lhs is unused.
AST_NODE_ERROR_SET_DECL,
/// `struct {}`, `union {}`, `opaque {}`, `enum {}`. `extra_data[lhs..rhs]`.
/// `struct {}`, `union {}`, `opaque {}`, `enum {}`.
/// `extra_data[lhs..rhs]`.
/// main_token is `struct`, `union`, `opaque`, `enum` keyword.
AST_NODE_CONTAINER_DECL,
/// Same as ContainerDecl but there is known to be a trailing comma
/// or semicolon before the rbrace.
AST_NODE_CONTAINER_DECL_TRAILING,
/// `struct {lhs, rhs}`, `union {lhs, rhs}`, `opaque {lhs, rhs}`, `enum {lhs, rhs}`.
/// `struct {lhs, rhs}`, `union {lhs, rhs}`, `opaque {lhs, rhs}`, `enum
/// {lhs, rhs}`.
/// lhs or rhs can be omitted.
/// main_token is `struct`, `union`, `opaque`, `enum` keyword.
AST_NODE_CONTAINER_DECL_TWO,
@@ -458,7 +474,8 @@ typedef enum {
/// `{lhs rhs}`. rhs or lhs can be omitted.
/// main_token points at the lbrace.
AST_NODE_BLOCK_TWO,
/// Same as block_two but there is known to be a semicolon before the rbrace.
/// Same as block_two but there is known to be a semicolon before the
/// rbrace.
AST_NODE_BLOCK_TWO_SEMICOLON,
/// `{}`. `sub_list[lhs..rhs]`.
/// main_token points at the lbrace.