diff --git a/selfhost/parser.n b/selfhost/parser.n index e7c815f..641b206 100644 --- a/selfhost/parser.n +++ b/selfhost/parser.n @@ -110,8 +110,8 @@ fn init() inline void { } fn add_with_token(tok: u32, tag: NodeType) u32 { - const retval = node_type.size(); - node_type.append_assume_capacity(tag); + const retval = node_type.add(); + node_type.get(retval).* = tag; node_token.append_assume_capacity(tok); node_payload.add(); node_next.add(); @@ -286,6 +286,18 @@ fn parse_primary_expression(context: *ParserContext, require: bool, precedence: else if(p == .unreachable_keyword) { return context.add_advance(.@"unreachable"); } + else if(p == .struct_keyword || p == .union_keyword || p == .enum_keyword) { + const retval = context.add_advance(.container_expression); + context.expect("Expected '{' before container body".&, .@"{"); + var is_enum = false; + // TODO: Make == a proper value so that we don't have to do this shit + if(p == .enum_keyword) { + is_enum = true; + } + node_payload.get(retval).* = parse_container_body(context, is_enum); + context.expect("Expected '}' before container body".&, .@"}"); + return retval; + } else if(p == .if_keyword) { const token = context.advance(); context.expect("Expected '(' after 'if'".&, .@"("); diff --git a/selfhost/tokenizer.n b/selfhost/tokenizer.n index cc28697..3a2a0df 100644 --- a/selfhost/tokenizer.n +++ b/selfhost/tokenizer.n @@ -21,18 +21,18 @@ const TokenType = enum(u8) { continue_keyword, else_keyword, //endcase_keyword, - //enum_keyword, + enum_keyword, //false_keyword, fn_keyword, if_keyword, inline_keyword, loop_keyword, return_keyword, - //struct_keyword, + struct_keyword, //switch_keyword, //true_keyword, undefined_keyword, - //union_keyword, + union_keyword, unreachable_keyword, var_keyword, //volatile_keyword, @@ -276,6 +276,9 @@ fn init() void { if(context.match_kw("else".&)) { context.add_token_advance(.else_keyword, 4); } + if(context.match_kw("enum".&)) { + context.add_token_advance(.enum_keyword, 4); + } else { ident_handler(context); } @@ -341,6 +344,15 @@ fn init() void { } }.&; + token_handlers['s'] = fn(context: *TokenizationContext) void { + if(context.match_kw("struct".&)) { + context.add_token_advance(.struct_keyword, 6); + } + else { + ident_handler(context); + } + }.&; + token_handlers['t'] = fn(context: *TokenizationContext) void { if(context.match_kw("type".&)) { context.add_token_advance(.type_keyword, 4); @@ -369,6 +381,9 @@ fn init() void { else if(context.match_kw("u64".&)) { context.add_token_advance(.@"u64", 3); } + else if(context.match_kw("union".&)) { + context.add_token_advance(.union_keyword, 5); + } else { ident_handler(context); }