diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-02-05 17:15:19 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-02-05 17:15:19 -0700 |
| commit | 4339d555626197f4b8c9598b602f098b76488c2d (patch) | |
| tree | 2773f3dbace6d3603f7fddaddee8f2683b645d37 /src/parser.cpp | |
| parent | 4208435f662030abf24929c90a4bb8c7fb0d2908 (diff) | |
| download | zig-4339d555626197f4b8c9598b602f098b76488c2d.tar.gz zig-4339d555626197f4b8c9598b602f098b76488c2d.zip | |
update for loop syntax
it matches more closely the %% binary operator syntax
See #51
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index f9880156d8..78481f61f0 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1797,7 +1797,7 @@ static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) { } /* -ForExpression : token(For) token(LParen) Symbol token(Comma) Expression option(token(Comma) token(Symbol)) token(RParen) Expression +ForExpression = "for" "(" Expression ")" option("|" "Symbol" option("," "Symbol") "|") Expression */ static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mandatory) { Token *token = &pc->tokens->at(*token_index); @@ -1814,17 +1814,23 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mand AstNode *node = ast_create_node(pc, NodeTypeForExpr, token); ast_eat_token(pc, token_index, TokenIdLParen); - node->data.for_expr.elem_node = ast_parse_symbol(pc, token_index); - ast_eat_token(pc, token_index, TokenIdComma); node->data.for_expr.array_expr = ast_parse_expression(pc, token_index, true); + ast_eat_token(pc, token_index, TokenIdRParen); - Token *comma = &pc->tokens->at(*token_index); - if (comma->id == TokenIdComma) { + Token *maybe_bar = &pc->tokens->at(*token_index); + if (maybe_bar->id == TokenIdBinOr) { *token_index += 1; - node->data.for_expr.index_node = ast_parse_symbol(pc, token_index); - } + node->data.for_expr.elem_node = ast_parse_symbol(pc, token_index); - ast_eat_token(pc, token_index, TokenIdRParen); + Token *maybe_comma = &pc->tokens->at(*token_index); + if (maybe_comma->id == TokenIdComma) { + *token_index += 1; + + node->data.for_expr.index_node = ast_parse_symbol(pc, token_index); + } + + ast_eat_token(pc, token_index, TokenIdBinOr); + } node->data.for_expr.body = ast_parse_expression(pc, token_index, true); |
