aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-01-06 01:28:58 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-01-06 01:28:58 -0700
commit3c43bc9208701af151a0346744e3bfc7eae43042 (patch)
treeb3732004becc9b759ddad1a86813668059cfc8d9 /src/parser.cpp
parent4ef062b9c819a2d7bfa9dd3394713ac9e8051660 (diff)
downloadzig-3c43bc9208701af151a0346744e3bfc7eae43042.tar.gz
zig-3c43bc9208701af151a0346744e3bfc7eae43042.zip
support unknown size arrays
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 36038a3bc2..24daca8864 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -219,7 +219,7 @@ void ast_print(AstNode *node, int indent) {
}
case AstNodeTypeTypePointer:
{
- const char *const_or_mut_str = node->data.type.is_const ? "const" : "mut";
+ const char *const_or_mut_str = node->data.type.is_const ? "const" : "var";
fprintf(stderr, "'%s' PointerType\n", const_or_mut_str);
ast_print(node->data.type.child_type, indent + 2);
@@ -227,9 +227,11 @@ void ast_print(AstNode *node, int indent) {
}
case AstNodeTypeTypeArray:
{
- fprintf(stderr, "ArrayType\n");
+ const char *const_or_mut_str = node->data.type.is_const ? "const" : "var";
+ fprintf(stderr, "'%s' ArrayType\n", const_or_mut_str);
+ if (node->data.type.array_size)
+ ast_print(node->data.type.array_size, indent + 2);
ast_print(node->data.type.child_type, indent + 2);
- ast_print(node->data.type.array_size, indent + 2);
break;
}
case AstNodeTypeTypeMaybe:
@@ -1107,6 +1109,12 @@ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) {
ast_eat_token(pc, token_index, TokenIdRBracket);
+ Token *const_tok = &pc->tokens->at(*token_index);
+ if (const_tok->id == TokenIdKeywordConst) {
+ *token_index += 1;
+ node->data.type.is_const = true;
+ }
+
node->data.type.child_type = ast_parse_type(pc, token_index);
} else {
ast_invalid_token_error(pc, token);