aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-12-22 12:03:48 +0000
committergingerBill <bill@gingerbill.org>2019-12-22 12:03:48 +0000
commitd1c9fd4e012e16cee73e9ef0af716caf34430d81 (patch)
tree048a9dd6ed2294d685761e31081620a924ee6ef9 /src/parser.cpp
parent45937306321df28266c793b7225eb10ad3d741e2 (diff)
Implement `#complete switch` by default, replace with `#partial switch` #511
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index fbbb9e1cb..0e9b20e52 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -766,6 +766,7 @@ Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) {
result->SwitchStmt.init = init;
result->SwitchStmt.tag = tag;
result->SwitchStmt.body = body;
+ result->SwitchStmt.partial = false;
return result;
}
@@ -775,6 +776,7 @@ Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) {
result->TypeSwitchStmt.token = token;
result->TypeSwitchStmt.tag = tag;
result->TypeSwitchStmt.body = body;
+ result->TypeSwitchStmt.partial = false;
return result;
}
@@ -4060,16 +4062,32 @@ Ast *parse_stmt(AstFile *f) {
s = parse_stmt(f);
switch (s->kind) {
case Ast_SwitchStmt:
- s->SwitchStmt.complete = true;
+ s->SwitchStmt.partial = false;
+ syntax_warning(token, "#complete is now the default and has been replaced with its opposite: #partial");
break;
case Ast_TypeSwitchStmt:
- s->TypeSwitchStmt.complete = true;
+ s->TypeSwitchStmt.partial = false;
+ syntax_warning(token, "#complete is now the default and has been replaced with its opposite: #partial");
break;
default:
syntax_error(token, "#complete can only be applied to a switch statement");
break;
}
return s;
+ } else if (tag == "partial") {
+ s = parse_stmt(f);
+ switch (s->kind) {
+ case Ast_SwitchStmt:
+ s->SwitchStmt.partial = true;
+ break;
+ case Ast_TypeSwitchStmt:
+ s->TypeSwitchStmt.partial = true;
+ break;
+ default:
+ syntax_error(token, "#partial can only be applied to a switch statement");
+ break;
+ }
+ return s;
} else if (tag == "assert") {
Ast *t = ast_basic_directive(f, hash_token, tag);
return ast_expr_stmt(f, parse_call_expr(f, t));