Fix field parsing

This commit is contained in:
Krzosa Karol
2022-06-01 15:00:27 +02:00
parent 82bb3ae493
commit 364daed1c7
4 changed files with 32 additions and 12 deletions

View File

@@ -208,7 +208,7 @@ function Ast_Named *parse_named(B32);
function Ast_Block *
parse_block(){
Ast_Block *block = 0;
if(token_match(OPEN_SCOPE)){
if(token_expect(OPEN_SCOPE)){ // @todo: Fix error message here, it doesn't show proper token context
Token *token_block = token_get();
Scratch scratch;
@@ -392,7 +392,7 @@ left_denotation(Token *op, Ast_Expr *left){
function S64
postfix_binding_power(Token_Kind kind){
switch(kind){
case TK_Dot: case TK_Decrement: case TK_Increment: case TK_OpenBracket: case TK_OpenParen: return 1;
case TK_Dot: case TK_Decrement: case TK_Increment: case TK_OpenBracket: case TK_OpenParen: return 3;
default: return 0;
}
}
@@ -405,17 +405,16 @@ parse_expr(S64 rbp){
token = token_get();
// @note: parse postfix
if(postfix_binding_power(token->kind) > rbp){
S64 pbp = postfix_binding_power(token->kind);
if(pbp > rbp){
token_next();
switch(token->kind){
case TK_Dot: {
// @note: making sure that we always get a configuration where
// Identifier is in left node
Ast_Expr *right = parse_expr();
Ast_Expr *right = parse_expr(pbp-1);
left = ast_expr_binary(left, right, token);
}break;
case TK_OpenBracket:{
Ast_Expr *index = parse_expr();
Ast_Expr *index = parse_expr(pbp-1);
left = ast_expr_index(token, left, index);
token_expect(TK_CloseBracket);
}break;
@@ -423,6 +422,7 @@ parse_expr(S64 rbp){
left = parse_expr_call(left);
}break;
default:{
assert(token->kind == TK_Increment || token->kind == TK_Decrement);
if(token->kind == TK_Increment) token->kind = TK_PostIncrement;
else if(token->kind == TK_Decrement) token->kind = TK_PostDecrement;
left = ast_expr_unary(token, token->kind, left);