aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2020-12-18 14:19:03 +0100
committerGitHub <noreply@github.com>2020-12-18 14:19:03 +0100
commitbd6ead32f8d05a9662c7fa6fde867b71da0e79c9 (patch)
treee610f06a230cca9d89bf075ec55e520dae83ad8e /src/parser.cpp
parent934809397f1f5f567c0ec668de72d2ac28e85f74 (diff)
parent3558848da818dc330d139ff5d756bb9b9498b1d4 (diff)
Merge pull request #1 from odin-lang/master
update from master
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 46af47c2d..59d02090e 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1284,8 +1284,7 @@ bool skip_possible_newline(AstFile *f) {
if ((f->tokenizer.flags & TokenizerFlag_InsertSemicolon) == 0) {
return false;
}
- Token *prev = &f->curr_token;
- if (prev->kind == Token_Semicolon && prev->string == "\n") {
+ if (token_is_newline(f->curr_token)) {
advance_token(f);
return true;
}
@@ -1296,10 +1295,10 @@ bool skip_possible_newline_for_literal(AstFile *f) {
if ((f->tokenizer.flags & TokenizerFlag_InsertSemicolon) == 0) {
return false;
}
- TokenPos curr_pos = f->curr_token.pos;
- if (token_is_newline(f->curr_token)) {
+ Token curr = f->curr_token;
+ if (token_is_newline(curr)) {
Token next = peek_token(f);
- if (curr_pos.line+1 >= next.pos.line) {
+ if (curr.pos.line+1 >= next.pos.line) {
switch (next.kind) {
case Token_OpenBrace:
case Token_else:
@@ -3182,6 +3181,7 @@ Ast *parse_simple_stmt(AstFile *f, u32 flags) {
Ast *parse_block_stmt(AstFile *f, b32 is_when) {
+ skip_possible_newline_for_literal(f);
if (!is_when && f->curr_proc == nullptr) {
syntax_error(f->curr_token, "You cannot use a block statement in the file scope");
return ast_bad_stmt(f, f->curr_token, f->curr_token);
@@ -3796,9 +3796,9 @@ Ast *parse_if_stmt(AstFile *f) {
}
} else {
body = parse_block_stmt(f, false);
- skip_possible_newline_for_literal(f);
}
+ skip_possible_newline_for_literal(f);
if (allow_token(f, Token_else)) {
switch (f->curr_token.kind) {
case Token_if:
@@ -3852,9 +3852,9 @@ Ast *parse_when_stmt(AstFile *f) {
}
} else {
body = parse_block_stmt(f, true);
- skip_possible_newline_for_literal(f);
}
+ skip_possible_newline_for_literal(f);
if (allow_token(f, Token_else)) {
switch (f->curr_token.kind) {
case Token_when:
@@ -3958,7 +3958,6 @@ Ast *parse_for_stmt(AstFile *f) {
}
} else {
body = parse_block_stmt(f, false);
- skip_possible_newline_for_literal(f);
}
return ast_range_stmt(f, token, nullptr, nullptr, in_token, rhs, body);
}
@@ -3994,7 +3993,6 @@ Ast *parse_for_stmt(AstFile *f) {
}
} else {
body = parse_block_stmt(f, false);
- skip_possible_newline_for_literal(f);
}
if (is_range) {
@@ -4346,7 +4344,6 @@ Ast *parse_stmt(AstFile *f) {
}
} else {
body = parse_block_stmt(f, false);
- skip_possible_newline_for_literal(f);
}
if (bad_stmt) {
return ast_bad_stmt(f, inline_token, f->curr_token);