aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-04 15:50:06 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-04 15:50:06 -0700
commit5490f907fe4b5c8323eaf917b1ead8760c9eca34 (patch)
tree33d1326656b91928927b6e58ffcfef776c68db67 /src/parser.cpp
parentfcbeaddbb2321cd1006e0e007144b0f116de80be (diff)
downloadzig-5490f907fe4b5c8323eaf917b1ead8760c9eca34.tar.gz
zig-5490f907fe4b5c8323eaf917b1ead8760c9eca34.zip
switch statements resolve peer compatibility
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index fe17495fc4..f9880156d8 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1834,7 +1834,7 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mand
/*
SwitchExpression : "switch" "(" Expression ")" "{" many(SwitchProng) "}"
-SwitchProng : (list(SwitchItem, ",") | "else") option("," "(" "Symbol" ")") "=>" Expression ","
+SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" "Symbol" "|") Expression ","
SwitchItem : Expression | (Expression "..." Expression)
*/
static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool mandatory) {
@@ -1895,15 +1895,15 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, int *token_index, bool m
break;
}
- Token *arrow_or_colon = &pc->tokens->at(*token_index);
- if (arrow_or_colon->id == TokenIdColon) {
+ ast_eat_token(pc, token_index, TokenIdFatArrow);
+
+ Token *maybe_bar = &pc->tokens->at(*token_index);
+ if (maybe_bar->id == TokenIdBinOr) {
*token_index += 1;
- ast_eat_token(pc, token_index, TokenIdLParen);
prong_node->data.switch_prong.var_symbol = ast_parse_symbol(pc, token_index);
- ast_eat_token(pc, token_index, TokenIdRParen);
+ ast_eat_token(pc, token_index, TokenIdBinOr);
}
- ast_eat_token(pc, token_index, TokenIdFatArrow);
prong_node->data.switch_prong.expr = ast_parse_expression(pc, token_index, true);
ast_eat_token(pc, token_index, TokenIdComma);