zig0

my attempts at zig bootstrapping in C
Log | Files | Refs | README | LICENSE

ast.h (22384B) - Raw


      1 #ifndef _ZIG0_AST_H__
      2 #define _ZIG0_AST_H__
      3 
      4 #include <stdbool.h>
      5 #include <stdint.h>
      6 
      7 #include "common.h"
      8 #include "tokenizer.h"
      9 
     10 typedef enum {
     11     /// sub_list[lhs...rhs]
     12     AST_NODE_ROOT,
     13     /// `usingnamespace lhs;`. rhs unused. main_token is `usingnamespace`.
     14     AST_NODE_USINGNAMESPACE,
     15     /// lhs is test name token (must be string literal or identifier), if any.
     16     /// rhs is the body node.
     17     AST_NODE_TEST_DECL,
     18     /// lhs is the index into extra_data.
     19     /// rhs is the initialization expression, if any.
     20     /// main_token is `var` or `const`.
     21     AST_NODE_GLOBAL_VAR_DECL,
     22     /// `var a: x align(y) = rhs`
     23     /// lhs is the index into extra_data.
     24     /// main_token is `var` or `const`.
     25     AST_NODE_LOCAL_VAR_DECL,
     26     /// `var a: lhs = rhs`. lhs and rhs may be unused.
     27     /// Can be local or global.
     28     /// main_token is `var` or `const`.
     29     AST_NODE_SIMPLE_VAR_DECL,
     30     /// `var a align(lhs) = rhs`. lhs and rhs may be unused.
     31     /// Can be local or global.
     32     /// main_token is `var` or `const`.
     33     AST_NODE_ALIGNED_VAR_DECL,
     34     /// lhs is the identifier token payload if any,
     35     /// rhs is the deferred expression.
     36     AST_NODE_ERRDEFER,
     37     /// lhs is unused.
     38     /// rhs is the deferred expression.
     39     AST_NODE_DEFER,
     40     /// lhs catch rhs
     41     /// lhs catch |err| rhs
     42     /// main_token is the `catch` keyword.
     43     /// payload is determined by looking at the next token after the `catch`
     44     /// keyword.
     45     AST_NODE_CATCH,
     46     /// `lhs.a`. main_token is the dot. rhs is the identifier token index.
     47     AST_NODE_FIELD_ACCESS,
     48     /// `lhs.?`. main_token is the dot. rhs is the `?` token index.
     49     AST_NODE_UNWRAP_OPTIONAL,
     50     /// `lhs == rhs`. main_token is op.
     51     AST_NODE_EQUAL_EQUAL,
     52     /// `lhs != rhs`. main_token is op.
     53     AST_NODE_BANG_EQUAL,
     54     /// `lhs < rhs`. main_token is op.
     55     AST_NODE_LESS_THAN,
     56     /// `lhs > rhs`. main_token is op.
     57     AST_NODE_GREATER_THAN,
     58     /// `lhs <= rhs`. main_token is op.
     59     AST_NODE_LESS_OR_EQUAL,
     60     /// `lhs >= rhs`. main_token is op.
     61     AST_NODE_GREATER_OR_EQUAL,
     62     /// `lhs *= rhs`. main_token is op.
     63     AST_NODE_ASSIGN_MUL,
     64     /// `lhs /= rhs`. main_token is op.
     65     AST_NODE_ASSIGN_DIV,
     66     /// `lhs %= rhs`. main_token is op.
     67     AST_NODE_ASSIGN_MOD,
     68     /// `lhs += rhs`. main_token is op.
     69     AST_NODE_ASSIGN_ADD,
     70     /// `lhs -= rhs`. main_token is op.
     71     AST_NODE_ASSIGN_SUB,
     72     /// `lhs <<= rhs`. main_token is op.
     73     AST_NODE_ASSIGN_SHL,
     74     /// `lhs <<|= rhs`. main_token is op.
     75     AST_NODE_ASSIGN_SHL_SAT,
     76     /// `lhs >>= rhs`. main_token is op.
     77     AST_NODE_ASSIGN_SHR,
     78     /// `lhs &= rhs`. main_token is op.
     79     AST_NODE_ASSIGN_BIT_AND,
     80     /// `lhs ^= rhs`. main_token is op.
     81     AST_NODE_ASSIGN_BIT_XOR,
     82     /// `lhs |= rhs`. main_token is op.
     83     AST_NODE_ASSIGN_BIT_OR,
     84     /// `lhs *%= rhs`. main_token is op.
     85     AST_NODE_ASSIGN_MUL_WRAP,
     86     /// `lhs +%= rhs`. main_token is op.
     87     AST_NODE_ASSIGN_ADD_WRAP,
     88     /// `lhs -%= rhs`. main_token is op.
     89     AST_NODE_ASSIGN_SUB_WRAP,
     90     /// `lhs *|= rhs`. main_token is op.
     91     AST_NODE_ASSIGN_MUL_SAT,
     92     /// `lhs +|= rhs`. main_token is op.
     93     AST_NODE_ASSIGN_ADD_SAT,
     94     /// `lhs -|= rhs`. main_token is op.
     95     AST_NODE_ASSIGN_SUB_SAT,
     96     /// `lhs = rhs`. main_token is op.
     97     AST_NODE_ASSIGN,
     98     /// `a, b, ... = rhs`. main_token is op. lhs is index into `extra_data`
     99     /// of an lhs elem count followed by an array of that many `Node.Index`,
    100     /// with each node having one of the following types:
    101     /// * `global_var_decl`
    102     /// * `local_var_decl`
    103     /// * `simple_var_decl`
    104     /// * `aligned_var_decl`
    105     /// * Any expression node
    106     /// The first 3 types correspond to a `var` or `const` lhs node (note
    107     /// that their `rhs` is always 0). An expression node corresponds to a
    108     /// standard assignment LHS (which must be evaluated as an lvalue).
    109     /// There may be a preceding `comptime` token, which does not create a
    110     /// corresponding `comptime` node so must be manually detected.
    111     AST_NODE_ASSIGN_DESTRUCTURE,
    112     /// `lhs || rhs`. main_token is the `||`.
    113     AST_NODE_MERGE_ERROR_SETS,
    114     /// `lhs * rhs`. main_token is the `*`.
    115     AST_NODE_MUL,
    116     /// `lhs / rhs`. main_token is the `/`.
    117     AST_NODE_DIV,
    118     /// `lhs % rhs`. main_token is the `%`.
    119     AST_NODE_MOD,
    120     /// `lhs ** rhs`. main_token is the `**`.
    121     AST_NODE_ARRAY_MULT,
    122     /// `lhs *% rhs`. main_token is the `*%`.
    123     AST_NODE_MUL_WRAP,
    124     /// `lhs *| rhs`. main_token is the `*|`.
    125     AST_NODE_MUL_SAT,
    126     /// `lhs + rhs`. main_token is the `+`.
    127     AST_NODE_ADD,
    128     /// `lhs - rhs`. main_token is the `-`.
    129     AST_NODE_SUB,
    130     /// `lhs ++ rhs`. main_token is the `++`.
    131     AST_NODE_ARRAY_CAT,
    132     /// `lhs +% rhs`. main_token is the `+%`.
    133     AST_NODE_ADD_WRAP,
    134     /// `lhs -% rhs`. main_token is the `-%`.
    135     AST_NODE_SUB_WRAP,
    136     /// `lhs +| rhs`. main_token is the `+|`.
    137     AST_NODE_ADD_SAT,
    138     /// `lhs -| rhs`. main_token is the `-|`.
    139     AST_NODE_SUB_SAT,
    140     /// `lhs << rhs`. main_token is the `<<`.
    141     AST_NODE_SHL,
    142     /// `lhs <<| rhs`. main_token is the `<<|`.
    143     AST_NODE_SHL_SAT,
    144     /// `lhs >> rhs`. main_token is the `>>`.
    145     AST_NODE_SHR,
    146     /// `lhs & rhs`. main_token is the `&`.
    147     AST_NODE_BIT_AND,
    148     /// `lhs ^ rhs`. main_token is the `^`.
    149     AST_NODE_BIT_XOR,
    150     /// `lhs | rhs`. main_token is the `|`.
    151     AST_NODE_BIT_OR,
    152     /// `lhs orelse rhs`. main_token is the `orelse`.
    153     AST_NODE_ORELSE,
    154     /// `lhs and rhs`. main_token is the `and`.
    155     AST_NODE_BOOL_AND,
    156     /// `lhs or rhs`. main_token is the `or`.
    157     AST_NODE_BOOL_OR,
    158     /// `op lhs`. rhs unused. main_token is op.
    159     AST_NODE_BOOL_NOT,
    160     /// `op lhs`. rhs unused. main_token is op.
    161     AST_NODE_NEGATION,
    162     /// `op lhs`. rhs unused. main_token is op.
    163     AST_NODE_BIT_NOT,
    164     /// `op lhs`. rhs unused. main_token is op.
    165     AST_NODE_NEGATION_WRAP,
    166     /// `op lhs`. rhs unused. main_token is op.
    167     AST_NODE_ADDRESS_OF,
    168     /// `op lhs`. rhs unused. main_token is op.
    169     AST_NODE_TRY,
    170     /// `op lhs`. rhs unused. main_token is op.
    171     AST_NODE_AWAIT,
    172     /// `?lhs`. rhs unused. main_token is the `?`.
    173     AST_NODE_OPTIONAL_TYPE,
    174     /// `[lhs]rhs`.
    175     AST_NODE_ARRAY_TYPE,
    176     /// `[lhs:a]b`. `ArrayTypeSentinel[rhs]`.
    177     AST_NODE_ARRAY_TYPE_SENTINEL,
    178     /// `[*]align(lhs) rhs`. lhs can be omitted.
    179     /// `*align(lhs) rhs`. lhs can be omitted.
    180     /// `[]rhs`.
    181     /// main_token is the asterisk if a single item pointer or the lbracket
    182     /// if a slice, many-item pointer, or C-pointer
    183     /// main_token might be a ** token, which is shared with a parent/child
    184     /// pointer type and may require special handling.
    185     AST_NODE_PTR_TYPE_ALIGNED,
    186     /// `[*:lhs]rhs`. lhs can be omitted.
    187     /// `*rhs`.
    188     /// `[:lhs]rhs`.
    189     /// main_token is the asterisk if a single item pointer or the lbracket
    190     /// if a slice, many-item pointer, or C-pointer
    191     /// main_token might be a ** token, which is shared with a parent/child
    192     /// pointer type and may require special handling.
    193     AST_NODE_PTR_TYPE_SENTINEL,
    194     /// lhs is index into ptr_type. rhs is the element type expression.
    195     /// main_token is the asterisk if a single item pointer or the lbracket
    196     /// if a slice, many-item pointer, or C-pointer
    197     /// main_token might be a ** token, which is shared with a parent/child
    198     /// pointer type and may require special handling.
    199     AST_NODE_PTR_TYPE,
    200     /// lhs is index into ptr_type_bit_range. rhs is the element type
    201     /// expression.
    202     /// main_token is the asterisk if a single item pointer or the lbracket
    203     /// if a slice, many-item pointer, or C-pointer
    204     /// main_token might be a ** token, which is shared with a parent/child
    205     /// pointer type and may require special handling.
    206     AST_NODE_PTR_TYPE_BIT_RANGE,
    207     /// `lhs[rhs..]`
    208     /// main_token is the lbracket.
    209     AST_NODE_SLICE_OPEN,
    210     /// `lhs[b..c]`. rhs is index into Slice
    211     /// main_token is the lbracket.
    212     AST_NODE_SLICE,
    213     /// `lhs[b..c :d]`. rhs is index into SliceSentinel. Slice end c can be
    214     /// omitted.
    215     /// main_token is the lbracket.
    216     AST_NODE_SLICE_SENTINEL,
    217     /// `lhs.*`. rhs is unused.
    218     AST_NODE_DEREF,
    219     /// `lhs[rhs]`.
    220     AST_NODE_ARRAY_ACCESS,
    221     /// `lhs{rhs}`. rhs can be omitted.
    222     AST_NODE_ARRAY_INIT_ONE,
    223     /// `lhs{rhs,}`. rhs can *not* be omitted
    224     AST_NODE_ARRAY_INIT_ONE_COMMA,
    225     /// `.{lhs, rhs}`. lhs and rhs can be omitted.
    226     AST_NODE_ARRAY_INIT_DOT_TWO,
    227     /// Same as `array_init_dot_two` except there is known to be a trailing
    228     /// comma
    229     /// before the final rbrace.
    230     AST_NODE_ARRAY_INIT_DOT_TWO_COMMA,
    231     /// `.{a, b}`. `sub_list[lhs..rhs]`.
    232     AST_NODE_ARRAY_INIT_DOT,
    233     /// Same as `array_init_dot` except there is known to be a trailing comma
    234     /// before the final rbrace.
    235     AST_NODE_ARRAY_INIT_DOT_COMMA,
    236     /// `lhs{a, b}`. `sub_range_list[rhs]`. lhs can be omitted which means
    237     /// `.{a, b}`.
    238     AST_NODE_ARRAY_INIT,
    239     /// Same as `array_init` except there is known to be a trailing comma
    240     /// before the final rbrace.
    241     AST_NODE_ARRAY_INIT_COMMA,
    242     /// `lhs{.a = rhs}`. rhs can be omitted making it empty.
    243     /// main_token is the lbrace.
    244     AST_NODE_STRUCT_INIT_ONE,
    245     /// `lhs{.a = rhs,}`. rhs can *not* be omitted.
    246     /// main_token is the lbrace.
    247     AST_NODE_STRUCT_INIT_ONE_COMMA,
    248     /// `.{.a = lhs, .b = rhs}`. lhs and rhs can be omitted.
    249     /// main_token is the lbrace.
    250     /// No trailing comma before the rbrace.
    251     AST_NODE_STRUCT_INIT_DOT_TWO,
    252     /// Same as `struct_init_dot_two` except there is known to be a trailing
    253     /// comma
    254     /// before the final rbrace.
    255     AST_NODE_STRUCT_INIT_DOT_TWO_COMMA,
    256     /// `.{.a = b, .c = d}`. `sub_list[lhs..rhs]`.
    257     /// main_token is the lbrace.
    258     AST_NODE_STRUCT_INIT_DOT,
    259     /// Same as `struct_init_dot` except there is known to be a trailing comma
    260     /// before the final rbrace.
    261     AST_NODE_STRUCT_INIT_DOT_COMMA,
    262     /// `lhs{.a = b, .c = d}`. `sub_range_list[rhs]`.
    263     /// lhs can be omitted which means `.{.a = b, .c = d}`.
    264     /// main_token is the lbrace.
    265     AST_NODE_STRUCT_INIT,
    266     /// Same as `struct_init` except there is known to be a trailing comma
    267     /// before the final rbrace.
    268     AST_NODE_STRUCT_INIT_COMMA,
    269     /// `lhs(rhs)`. rhs can be omitted.
    270     /// main_token is the lparen.
    271     AST_NODE_CALL_ONE,
    272     /// `lhs(rhs,)`. rhs can be omitted.
    273     /// main_token is the lparen.
    274     AST_NODE_CALL_ONE_COMMA,
    275     /// `async lhs(rhs)`. rhs can be omitted.
    276     AST_NODE_ASYNC_CALL_ONE,
    277     /// `async lhs(rhs,)`.
    278     AST_NODE_ASYNC_CALL_ONE_COMMA,
    279     /// `lhs(a, b, c)`. `SubRange[rhs]`.
    280     /// main_token is the `(`.
    281     AST_NODE_CALL,
    282     /// `lhs(a, b, c,)`. `SubRange[rhs]`.
    283     /// main_token is the `(`.
    284     AST_NODE_CALL_COMMA,
    285     /// `async lhs(a, b, c)`. `SubRange[rhs]`.
    286     /// main_token is the `(`.
    287     AST_NODE_ASYNC_CALL,
    288     /// `async lhs(a, b, c,)`. `SubRange[rhs]`.
    289     /// main_token is the `(`.
    290     AST_NODE_ASYNC_CALL_COMMA,
    291     /// `switch(lhs) {}`. `SubRange[rhs]`.
    292     /// `main_token` is the identifier of a preceding label, if any; otherwise
    293     /// `switch`.
    294     AST_NODE_SWITCH,
    295     /// Same as switch except there is known to be a trailing comma
    296     /// before the final rbrace
    297     AST_NODE_SWITCH_COMMA,
    298     /// `lhs => rhs`. If lhs is omitted it means `else`.
    299     /// main_token is the `=>`
    300     AST_NODE_SWITCH_CASE_ONE,
    301     /// Same ast `switch_case_one` but the case is inline
    302     AST_NODE_SWITCH_CASE_INLINE_ONE,
    303     /// `a, b, c => rhs`. `SubRange[lhs]`.
    304     /// main_token is the `=>`
    305     AST_NODE_SWITCH_CASE,
    306     /// Same ast `switch_case` but the case is inline
    307     AST_NODE_SWITCH_CASE_INLINE,
    308     /// `lhs...rhs`.
    309     AST_NODE_SWITCH_RANGE,
    310     /// `while (lhs) rhs`.
    311     /// `while (lhs) |x| rhs`.
    312     AST_NODE_WHILE_SIMPLE,
    313     /// `while (lhs) : (a) b`. `WhileCont[rhs]`.
    314     /// `while (lhs) : (a) b`. `WhileCont[rhs]`.
    315     AST_NODE_WHILE_CONT,
    316     /// `while (lhs) : (a) b else c`. `While[rhs]`.
    317     /// `while (lhs) |x| : (a) b else c`. `While[rhs]`.
    318     /// `while (lhs) |x| : (a) b else |y| c`. `While[rhs]`.
    319     /// The cont expression part `: (a)` may be omitted.
    320     AST_NODE_WHILE,
    321     /// `for (lhs) rhs`.
    322     AST_NODE_FOR_SIMPLE,
    323     /// `for (lhs[0..inputs]) lhs[inputs + 1] else lhs[inputs + 2]`.
    324     /// `For[rhs]`.
    325     AST_NODE_FOR,
    326     /// `lhs..rhs`. rhs can be omitted.
    327     AST_NODE_FOR_RANGE,
    328     /// `if (lhs) rhs`.
    329     /// `if (lhs) |a| rhs`.
    330     AST_NODE_IF_SIMPLE,
    331     /// `if (lhs) a else b`. `If[rhs]`.
    332     /// `if (lhs) |x| a else b`. `If[rhs]`.
    333     /// `if (lhs) |x| a else |y| b`. `If[rhs]`.
    334     AST_NODE_IF,
    335     /// `suspend lhs`. lhs can be omitted. rhs is unused.
    336     AST_NODE_SUSPEND,
    337     /// `resume lhs`. rhs is unused.
    338     AST_NODE_RESUME,
    339     /// `continue :lhs rhs`
    340     /// both lhs and rhs may be omitted.
    341     AST_NODE_CONTINUE,
    342     /// `break :lhs rhs`
    343     /// both lhs and rhs may be omitted.
    344     AST_NODE_BREAK,
    345     /// `return lhs`. lhs can be omitted. rhs is unused.
    346     AST_NODE_RETURN,
    347     /// `fn (a: lhs) rhs`. lhs can be omitted.
    348     /// anytype and ... parameters are omitted from the AST tree.
    349     /// main_token is the `fn` keyword.
    350     /// extern function declarations use this tag.
    351     AST_NODE_FN_PROTO_SIMPLE,
    352     /// `fn (a: b, c: d) rhs`. `sub_range_list[lhs]`.
    353     /// anytype and ... parameters are omitted from the AST tree.
    354     /// main_token is the `fn` keyword.
    355     /// extern function declarations use this tag.
    356     AST_NODE_FN_PROTO_MULTI,
    357     /// `fn (a: b) addrspace(e) linksection(f) callconv(g) rhs`.
    358     /// `FnProtoOne[lhs]`.
    359     /// zero or one parameters.
    360     /// anytype and ... parameters are omitted from the AST tree.
    361     /// main_token is the `fn` keyword.
    362     /// extern function declarations use this tag.
    363     AST_NODE_FN_PROTO_ONE,
    364     /// `fn (a: b, c: d) addrspace(e) linksection(f) callconv(g) rhs`.
    365     /// `FnProto[lhs]`.
    366     /// anytype and ... parameters are omitted from the AST tree.
    367     /// main_token is the `fn` keyword.
    368     /// extern function declarations use this tag.
    369     AST_NODE_FN_PROTO,
    370     /// lhs is the fn_proto.
    371     /// rhs is the function body block.
    372     /// Note that extern function declarations use the fn_proto tags rather
    373     /// than this one.
    374     AST_NODE_FN_DECL,
    375     /// `anyframe->rhs`. main_token is `anyframe`. `lhs` is arrow token index.
    376     AST_NODE_ANYFRAME_TYPE,
    377     /// Both lhs and rhs unused.
    378     AST_NODE_ANYFRAME_LITERAL,
    379     /// Both lhs and rhs unused.
    380     AST_NODE_CHAR_LITERAL,
    381     /// Both lhs and rhs unused.
    382     AST_NODE_NUMBER_LITERAL,
    383     /// Both lhs and rhs unused.
    384     AST_NODE_UNREACHABLE_LITERAL,
    385     /// Both lhs and rhs unused.
    386     /// Most identifiers will not have explicit AST nodes, however for
    387     /// expressions
    388     /// which could be one of many different kinds of AST nodes, there will be
    389     /// an
    390     /// identifier AST node for it.
    391     AST_NODE_IDENTIFIER,
    392     /// lhs is the dot token index, rhs unused, main_token is the identifier.
    393     AST_NODE_ENUM_LITERAL,
    394     /// main_token is the string literal token
    395     /// Both lhs and rhs unused.
    396     AST_NODE_STRING_LITERAL,
    397     /// main_token is the first token index (redundant with lhs)
    398     /// lhs is the first token index; rhs is the last token index.
    399     /// Could be a series of multiline_string_literal_line tokens, or a single
    400     /// string_literal token.
    401     AST_NODE_MULTILINE_STRING_LITERAL,
    402     /// `(lhs)`. main_token is the `(`; rhs is the token index of the `)`.
    403     AST_NODE_GROUPED_EXPRESSION,
    404     /// `@a(lhs, rhs)`. lhs and rhs may be omitted.
    405     /// main_token is the builtin token.
    406     AST_NODE_BUILTIN_CALL_TWO,
    407     /// Same as builtin_call_two but there is known to be a trailing comma
    408     /// before the rparen.
    409     AST_NODE_BUILTIN_CALL_TWO_COMMA,
    410     /// `@a(b, c)`. `sub_list[lhs..rhs]`.
    411     /// main_token is the builtin token.
    412     AST_NODE_BUILTIN_CALL,
    413     /// Same as builtin_call but there is known to be a trailing comma before
    414     /// the rparen.
    415     AST_NODE_BUILTIN_CALL_COMMA,
    416     /// `error{a, b}`.
    417     /// rhs is the rbrace, lhs is unused.
    418     AST_NODE_ERROR_SET_DECL,
    419     /// `struct {}`, `union {}`, `opaque {}`, `enum {}`.
    420     /// `extra_data[lhs..rhs]`.
    421     /// main_token is `struct`, `union`, `opaque`, `enum` keyword.
    422     AST_NODE_CONTAINER_DECL,
    423     /// Same as ContainerDecl but there is known to be a trailing comma
    424     /// or semicolon before the rbrace.
    425     AST_NODE_CONTAINER_DECL_TRAILING,
    426     /// `struct {lhs, rhs}`, `union {lhs, rhs}`, `opaque {lhs, rhs}`, `enum
    427     /// {lhs, rhs}`.
    428     /// lhs or rhs can be omitted.
    429     /// main_token is `struct`, `union`, `opaque`, `enum` keyword.
    430     AST_NODE_CONTAINER_DECL_TWO,
    431     /// Same as ContainerDeclTwo except there is known to be a trailing comma
    432     /// or semicolon before the rbrace.
    433     AST_NODE_CONTAINER_DECL_TWO_TRAILING,
    434     /// `struct(lhs)` / `union(lhs)` / `enum(lhs)`. `SubRange[rhs]`.
    435     AST_NODE_CONTAINER_DECL_ARG,
    436     /// Same as container_decl_arg but there is known to be a trailing
    437     /// comma or semicolon before the rbrace.
    438     AST_NODE_CONTAINER_DECL_ARG_TRAILING,
    439     /// `union(enum) {}`. `sub_list[lhs..rhs]`.
    440     /// Note that tagged unions with explicitly provided enums are represented
    441     /// by `container_decl_arg`.
    442     AST_NODE_TAGGED_UNION,
    443     /// Same as tagged_union but there is known to be a trailing comma
    444     /// or semicolon before the rbrace.
    445     AST_NODE_TAGGED_UNION_TRAILING,
    446     /// `union(enum) {lhs, rhs}`. lhs or rhs may be omitted.
    447     /// Note that tagged unions with explicitly provided enums are represented
    448     /// by `container_decl_arg`.
    449     AST_NODE_TAGGED_UNION_TWO,
    450     /// Same as tagged_union_two but there is known to be a trailing comma
    451     /// or semicolon before the rbrace.
    452     AST_NODE_TAGGED_UNION_TWO_TRAILING,
    453     /// `union(enum(lhs)) {}`. `SubRange[rhs]`.
    454     AST_NODE_TAGGED_UNION_ENUM_TAG,
    455     /// Same as tagged_union_enum_tag but there is known to be a trailing comma
    456     /// or semicolon before the rbrace.
    457     AST_NODE_TAGGED_UNION_ENUM_TAG_TRAILING,
    458     /// `a: lhs = rhs,`. lhs and rhs can be omitted.
    459     /// main_token is the field name identifier.
    460     /// lastToken() does not include the possible trailing comma.
    461     AST_NODE_CONTAINER_FIELD_INIT,
    462     /// `a: lhs align(rhs),`. rhs can be omitted.
    463     /// main_token is the field name identifier.
    464     /// lastToken() does not include the possible trailing comma.
    465     AST_NODE_CONTAINER_FIELD_ALIGN,
    466     /// `a: lhs align(c) = d,`. `container_field_list[rhs]`.
    467     /// main_token is the field name identifier.
    468     /// lastToken() does not include the possible trailing comma.
    469     AST_NODE_CONTAINER_FIELD,
    470     /// `comptime lhs`. rhs unused.
    471     AST_NODE_COMPTIME,
    472     /// `nosuspend lhs`. rhs unused.
    473     AST_NODE_NOSUSPEND,
    474     /// `{lhs rhs}`. rhs or lhs can be omitted.
    475     /// main_token points at the lbrace.
    476     AST_NODE_BLOCK_TWO,
    477     /// Same as block_two but there is known to be a semicolon before the
    478     /// rbrace.
    479     AST_NODE_BLOCK_TWO_SEMICOLON,
    480     /// `{}`. `sub_list[lhs..rhs]`.
    481     /// main_token points at the lbrace.
    482     AST_NODE_BLOCK,
    483     /// Same as block but there is known to be a semicolon before the rbrace.
    484     AST_NODE_BLOCK_SEMICOLON,
    485     /// `asm(lhs)`. rhs is the token index of the rparen.
    486     AST_NODE_ASM_SIMPLE,
    487     /// Legacy asm with string clobbers. `asm(lhs, a)`.
    488     /// `AsmLegacy[rhs]`.
    489     AST_NODE_ASM_LEGACY,
    490     /// `asm(lhs, a)`. `Asm[rhs]`.
    491     AST_NODE_ASM,
    492     /// `[a] "b" (c)`. lhs is 0, rhs is token index of the rparen.
    493     /// `[a] "b" (-> lhs)`. rhs is token index of the rparen.
    494     /// main_token is `a`.
    495     AST_NODE_ASM_OUTPUT,
    496     /// `[a] "b" (lhs)`. rhs is token index of the rparen.
    497     /// main_token is `a`.
    498     AST_NODE_ASM_INPUT,
    499     /// `error.a`. lhs is token index of `.`. rhs is token index of `a`.
    500     AST_NODE_ERROR_VALUE,
    501     /// `lhs!rhs`. main_token is the `!`.
    502     AST_NODE_ERROR_UNION,
    503 } AstNodeTag;
    504 
    505 typedef uint32_t AstTokenIndex;
    506 typedef uint32_t AstNodeIndex;
    507 typedef uint32_t AstIndex;
    508 
    509 typedef struct {
    510     AstIndex lhs;
    511     AstIndex rhs;
    512 } AstData;
    513 
    514 typedef struct {
    515     uint32_t len;
    516     uint32_t cap;
    517     AstNodeTag* tags;
    518     AstTokenIndex* main_tokens;
    519     AstData* datas;
    520 } AstNodeList;
    521 
    522 typedef struct {
    523     AstNodeTag tag;
    524     AstTokenIndex main_token;
    525     AstData data;
    526 } AstNodeItem;
    527 
    528 typedef struct {
    529     uint32_t len;
    530     uint32_t cap;
    531     TokenizerTag* tags;
    532     AstIndex* starts;
    533 } AstTokenList;
    534 
    535 typedef SLICE(AstNodeIndex) AstNodeIndexSlice;
    536 
    537 typedef struct {
    538     const char* source;
    539     uint32_t source_len;
    540     AstTokenList tokens;
    541     AstNodeList nodes;
    542     AstNodeIndexSlice extra_data;
    543     bool has_error;
    544     char* err_msg;
    545 } Ast;
    546 
    547 typedef struct AstPtrType {
    548     AstNodeIndex sentinel;
    549     AstNodeIndex align_node;
    550     AstNodeIndex addrspace_node;
    551 } AstPtrType;
    552 
    553 typedef struct AstPtrTypeBitRange {
    554     AstNodeIndex sentinel;
    555     AstNodeIndex align_node;
    556     AstNodeIndex addrspace_node;
    557     AstNodeIndex bit_range_start;
    558     AstNodeIndex bit_range_end;
    559 } AstPtrTypeBitRange;
    560 
    561 typedef struct AstFnProtoOne {
    562     AstNodeIndex param;
    563     AstNodeIndex align_expr;
    564     AstNodeIndex addrspace_expr;
    565     AstNodeIndex section_expr;
    566     AstNodeIndex callconv_expr;
    567 } AstFnProtoOne;
    568 
    569 typedef struct AstFnProto {
    570     AstNodeIndex params_start;
    571     AstNodeIndex params_end;
    572     AstNodeIndex align_expr;
    573     AstNodeIndex addrspace_expr;
    574     AstNodeIndex section_expr;
    575     AstNodeIndex callconv_expr;
    576 } AstFnProto;
    577 
    578 typedef struct AstSubRange {
    579     AstNodeIndex start;
    580     AstNodeIndex end;
    581 } AstSubRange;
    582 
    583 typedef struct AstSliceSentinel {
    584     AstNodeIndex start;
    585     AstNodeIndex end;
    586     AstNodeIndex sentinel;
    587 } AstSliceSentinel;
    588 
    589 typedef struct AstWhileCont {
    590     AstNodeIndex cont_expr;
    591     AstNodeIndex then_expr;
    592 } AstWhileCont;
    593 
    594 typedef struct AstWhile {
    595     AstNodeIndex cont_expr;
    596     AstNodeIndex then_expr;
    597     AstNodeIndex else_expr;
    598 } AstWhile;
    599 
    600 typedef struct AstFor {
    601     unsigned int inputs : 31;
    602     unsigned int has_else : 1;
    603 } AstFor;
    604 
    605 typedef struct AstIf {
    606     AstNodeIndex then_expr;
    607     AstNodeIndex else_expr;
    608 } AstIf;
    609 
    610 typedef struct AstError {
    611     bool is_note;
    612     AstTokenIndex token;
    613     union {
    614         struct {
    615             TokenizerTag expected_tag;
    616         } expected;
    617         struct {
    618         } none;
    619     } extra;
    620 } AstError;
    621 
    622 Ast astParse(const char* source, uint32_t len);
    623 void astDeinit(Ast*);
    624 
    625 #endif