Skip to content

Commit

Permalink
Selfhost: Parse block expressions with and without identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
N00byEdge committed Oct 4, 2023
1 parent e616372 commit 622fdef
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions selfhost/parser.n
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ fn parse_statement(context: *ParserContext) u32 {
context.expect("Expected ';' after expression statement".&, .@";");
return result;
}
// if(p == .@"{") {
// const result = add_with_token(context.current_token, .block);
// stmt_payload[0].get(result).* = parse_block(context);
// return result;
// }
// else if(p == .break_keyword) {
// context.report_error("TODO: Break statement".&);
// }
Expand Down Expand Up @@ -254,6 +249,12 @@ fn parse_primary_expression(context: *ParserContext) u32 {
const p = context.peek();

if(p == .identifier) {
if(tokenizer.token_type.get(context.current_token + 1).* == .@":") {
context.current_token += 2;
const result = add_with_token(context.current_token, .block);
node_payload.get(result).* = parse_block(context);
return result;
}
return context.add_advance(.identifier);
}
else if(p == .int_literal) {
Expand All @@ -266,6 +267,11 @@ fn parse_primary_expression(context: *ParserContext) u32 {
context.advance();
return parse_function_expression(context);
}
else if(p == .@"{") {
const result = add_with_token(context.current_token, .block);
node_payload.get(result).* = parse_block(context);
return result;
}
else if(p == .@"+") {
const plus_tok = context.advance();
_ = parse_primary_expression(context);
Expand Down

0 comments on commit 622fdef

Please sign in to comment.