aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-12-28 13:31:06 +0000
committergingerBill <bill@gingerbill.org>2018-12-28 13:31:06 +0000
commita240a3d14660f6b33f839a3ebf142e20aac3e80a (patch)
treea32aea3ab5929ca1bda8c54cf839a0a956bc5225 /src/parser.cpp
parent775f1e2c959e0db488615a44d30be3a59d371b08 (diff)
`static` variable declarations (Experimental)
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 85943fa00..9eeb6ea8c 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -3810,6 +3810,34 @@ Ast *parse_stmt(AstFile *f) {
return s;
}
+ case Token_static: {
+ CommentGroup *docs = f->lead_comment;
+ Token token = expect_token(f, Token_static);
+
+ Ast *decl = nullptr;
+ Array<Ast *> list = parse_lhs_expr_list(f);
+ if (list.count == 0) {
+ syntax_error(token, "Illegal use of 'static' statement");
+ expect_semicolon(f, nullptr);
+ return ast_bad_stmt(f, token, f->curr_token);
+ }
+
+ expect_token_after(f, Token_Colon, "identifier list");
+ decl = parse_value_decl(f, list, docs);
+
+ if (decl != nullptr && decl->kind == Ast_ValueDecl) {
+ if (decl->ValueDecl.is_mutable) {
+ decl->ValueDecl.is_static = true;
+ } else {
+ error(token, "'static' may only be currently used with variable declaration");
+ }
+ return decl;
+ }
+
+ syntax_error(token, "Illegal use of 'static' statement");
+ return ast_bad_stmt(f, token, f->curr_token);
+ } break;
+
case Token_using: {
CommentGroup *docs = f->lead_comment;
Token token = expect_token(f, Token_using);
@@ -3833,10 +3861,6 @@ Ast *parse_stmt(AstFile *f) {
decl = parse_value_decl(f, list, docs);
if (decl != nullptr && decl->kind == Ast_ValueDecl) {
- // if (!decl->ValueDecl.is_mutable) {
- // syntax_error(token, "'using' may only be applied to variable declarations");
- // return decl;
- // }
decl->ValueDecl.is_using = true;
return decl;
}