implemented member access parsing
This commit is contained in:
parent
c566f7d490
commit
d1b89939ae
4 changed files with 33 additions and 1 deletions
23
parser.c
23
parser.c
|
|
@ -233,6 +233,10 @@ ast_node *parse_expression(parser *p)
|
|||
left = node;
|
||||
}
|
||||
|
||||
/*
|
||||
* If after parsing an expression a `[` character
|
||||
* is found, it should be an array subscript expression.
|
||||
*/
|
||||
if (match(p, TOKEN_LSQUARE)) {
|
||||
ast_node *index = parse_expression(p);
|
||||
ast_node *node = arena_alloc(p->allocator, sizeof(ast_node));
|
||||
|
|
@ -247,6 +251,25 @@ ast_node *parse_expression(parser *p)
|
|||
return node;
|
||||
}
|
||||
|
||||
/*
|
||||
* If after parsing an expression a `.` character
|
||||
* is found, it should be a member access expression.
|
||||
*/
|
||||
if (match(p, TOKEN_DOT)) {
|
||||
if (!match_peek(p, TOKEN_IDENTIFIER)) {
|
||||
error(p, "expected identifier after member access.");
|
||||
return NULL;
|
||||
}
|
||||
ast_node *node = arena_alloc(p->allocator, sizeof(ast_node));
|
||||
node->type = NODE_ACCESS;
|
||||
node->expr.access.expr = left;
|
||||
node->expr.access.member = p->tokens->lexeme;
|
||||
node->expr.access.member_len = p->tokens->lexeme_len;
|
||||
advance(p);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue