Browse Source

Fix Compiler does not complain about missing semicolon #433

gingerBill 6 years ago
parent
commit
d54255505a
1 changed files with 10 additions and 5 deletions
  1. 10 5
      src/parser.cpp

+ 10 - 5
src/parser.cpp

@@ -1370,10 +1370,6 @@ void expect_semicolon(AstFile *f, Ast *s) {
 		return;
 		return;
 	}
 	}
 
 
-	switch (f->curr_token.kind) {
-	case Token_EOF:
-		return;
-	}
 
 
 	if (s != nullptr) {
 	if (s != nullptr) {
 		if (prev_token.pos.line != f->curr_token.pos.line) {
 		if (prev_token.pos.line != f->curr_token.pos.line) {
@@ -1386,12 +1382,21 @@ void expect_semicolon(AstFile *f, Ast *s) {
 			case Token_CloseParen:
 			case Token_CloseParen:
 			case Token_else:
 			case Token_else:
 				return;
 				return;
+			case Token_EOF:
+				if (is_semicolon_optional_for_node(f, s)) {
+					return;
+				}
+				break;
 			}
 			}
 		}
 		}
 		String node_string = ast_strings[s->kind];
 		String node_string = ast_strings[s->kind];
 		syntax_error(prev_token, "Expected ';' after %.*s, got %.*s",
 		syntax_error(prev_token, "Expected ';' after %.*s, got %.*s",
-		             LIT(node_string), LIT(token_strings[prev_token.kind]));
+		             LIT(node_string), LIT(token_strings[f->curr_token.kind]));
 	} else {
 	} else {
+		switch (f->curr_token.kind) {
+		case Token_EOF:
+			return;
+		}
 		syntax_error(prev_token, "Expected ';'");
 		syntax_error(prev_token, "Expected ';'");
 	}
 	}
 	fix_advance_to_next_stmt(f);
 	fix_advance_to_next_stmt(f);