From 183976b242dac0731caa7d925e88ad151a4dc8ee Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Sep 2016 23:47:30 -0400 Subject: add this keyword refers to thing in immediate scope See #169 --- src/parser.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index e0423ae1e1..52d3a855d0 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -620,7 +620,7 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool m /* PrimaryExpression = "Number" | "String" | "CharLiteral" | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | "Symbol" | ("@" "Symbol" FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." "Symbol") -KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type" +KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type" | "this" */ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) { Token *token = &pc->tokens->at(*token_index); @@ -672,6 +672,10 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo AstNode *node = ast_create_node(pc, NodeTypeZeroesLiteral, token); *token_index += 1; return node; + } else if (token->id == TokenIdKeywordThis) { + AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token); + *token_index += 1; + return node; } else if (token->id == TokenIdKeywordType) { AstNode *node = ast_create_node(pc, NodeTypeTypeLiteral, token); *token_index += 1; @@ -2560,6 +2564,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont case NodeTypeZeroesLiteral: // none break; + case NodeTypeThisLiteral: + // none + break; case NodeTypeIfBoolExpr: visit_field(&node->data.if_bool_expr.condition, visit, context); visit_field(&node->data.if_bool_expr.then_block, visit, context); @@ -2840,6 +2847,9 @@ AstNode *ast_clone_subtree_special(AstNode *old_node, uint32_t *next_node_index, case NodeTypeZeroesLiteral: // none break; + case NodeTypeThisLiteral: + // none + break; case NodeTypeIfBoolExpr: clone_subtree_field(&new_node->data.if_bool_expr.condition, old_node->data.if_bool_expr.condition, next_node_index); clone_subtree_field(&new_node->data.if_bool_expr.then_block, old_node->data.if_bool_expr.then_block, next_node_index); -- cgit v1.2.3