Skip to content

Commit

Permalink
Allow plain control flow expressions without semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
N00byEdge committed Oct 8, 2023
1 parent e4cec2d commit 90e647d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion selfhost/parser.n
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ fn parse_statement(context: *ParserContext) u32 {
node_payload.get(result).* = type_expr;
return result;
}
if(.if_keyword <= p && p <= .while_keyword) {
return parse_primary_expression(context, true, -1);
}
else if(p == .__keyword) {
const token = context.advance();
context.expect("Expected '=' after '_'".&, .@"=");
Expand Down Expand Up @@ -471,7 +474,7 @@ fn parse_expression_with_precedence(context: *ParserContext, require: bool, prec
}

fn parse_expression(context: *ParserContext) inline u32 {
return parse_expression_with_precedence(context, true, 99);
return parse_expression_with_precedence(context, true, -1);
}

fn parse_container_body(context: *ParserContext, is_enum: bool) u32 {
Expand Down
9 changes: 5 additions & 4 deletions selfhost/tokenizer.n
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ const TokenType = enum(u8) {
//endcase_keyword,
//false_keyword,
fn_keyword,
if_keyword,
inline_keyword,
loop_keyword,
return_keyword,
//switch_keyword,
//true_keyword,
undefined_keyword,
unreachable_keyword,
var_keyword,
//volatile_keyword,
while_keyword,
__keyword,

if_keyword,
loop_keyword,
//switch_keyword,
while_keyword,

enum_keyword,
struct_keyword,
union_keyword,
Expand Down

0 comments on commit 90e647d

Please sign in to comment.