aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorjon lipstate <52809771+jon-lipstate@users.noreply.github.com>2023-05-30 08:23:28 -0700
committerGitHub <noreply@github.com>2023-05-30 08:23:28 -0700
commitb223bc0302b54bb0629bd94d0b16e0f0720b6682 (patch)
treeeaa5de636a3fd8f5b008270fbaff268f40769f8c /src/parser.cpp
parentf5dcbf517b88d7479fa12d5f3b59183a447cae6f (diff)
parent3562a38f8cdd43792b6cdfd3327d16b65d25e5d0 (diff)
Merge branch 'odin-lang:master' into attr_error
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index f33a44f31..afdb1078d 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -115,7 +115,7 @@ gb_internal Ast *clone_ast(Ast *node, AstFile *f) {
n->Ident.entity = nullptr;
break;
case Ast_Implicit: break;
- case Ast_Undef: break;
+ case Ast_Uninit: break;
case Ast_BasicLit: break;
case Ast_BasicDirective: break;
@@ -646,9 +646,9 @@ gb_internal Ast *ast_implicit(AstFile *f, Token token) {
result->Implicit = token;
return result;
}
-gb_internal Ast *ast_undef(AstFile *f, Token token) {
- Ast *result = alloc_ast_node(f, Ast_Undef);
- result->Undef = token;
+gb_internal Ast *ast_uninit(AstFile *f, Token token) {
+ Ast *result = alloc_ast_node(f, Ast_Uninit);
+ result->Uninit = token;
return result;
}
@@ -2092,8 +2092,8 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
case Token_Ident:
return parse_ident(f);
- case Token_Undef:
- return ast_undef(f, expect_token(f, Token_Undef));
+ case Token_Uninit:
+ return ast_uninit(f, expect_token(f, Token_Uninit));
case Token_context:
return ast_implicit(f, expect_token(f, Token_context));
@@ -2292,7 +2292,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
skip_possible_newline_for_literal(f);
- if (allow_token(f, Token_Undef)) {
+ if (allow_token(f, Token_Uninit)) {
if (where_token.kind != Token_Invalid) {
syntax_error(where_token, "'where' clauses are not allowed on procedure literals without a defined body (replaced with ---)");
}
@@ -2462,7 +2462,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
}
is_raw_union = true;
} else if (tag.string == "no_copy") {
- if (is_packed) {
+ if (no_copy) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
no_copy = true;
@@ -3744,8 +3744,18 @@ gb_internal bool allow_field_separator(AstFile *f) {
if (allow_token(f, Token_Comma)) {
return true;
}
- if (ALLOW_NEWLINE && token.kind == Token_Semicolon) {
- if (!token_is_newline(token)) {
+ if (token.kind == Token_Semicolon) {
+ bool ok = false;
+ if (ALLOW_NEWLINE && token_is_newline(token)) {
+ TokenKind next = peek_token(f).kind;
+ switch (next) {
+ case Token_CloseBrace:
+ case Token_CloseParen:
+ ok = true;
+ break;
+ }
+ }
+ if (!ok) {
String p = token_to_string(token);
syntax_error(token_end_of_line(f, f->prev_token), "Expected a comma, got a %.*s", LIT(p));
}
@@ -4749,6 +4759,17 @@ gb_internal Ast *parse_stmt(AstFile *f) {
return stmt;
} else if (tag == "unroll") {
return parse_unrolled_for_loop(f, name);
+ } else if (tag == "reverse") {
+ Ast *for_stmt = parse_for_stmt(f);
+ if (for_stmt->kind == Ast_RangeStmt) {
+ if (for_stmt->RangeStmt.reverse) {
+ syntax_error(token, "#reverse already applied to a 'for in' statement");
+ }
+ for_stmt->RangeStmt.reverse = true;
+ } else {
+ syntax_error(token, "#reverse can only be applied to a 'for in' statement");
+ }
+ return for_stmt;
} else if (tag == "include") {
syntax_error(token, "#include is not a valid import declaration kind. Did you mean 'import'?");
s = ast_bad_stmt(f, token, f->curr_token);