Browse Source

Merge branch 'master' into multi-pointers

gingerBill 4 years ago
parent
commit
0decdaed1a
2 changed files with 36 additions and 14 deletions
  1. 18 6
      core/odin/parser/parser.odin
  2. 18 8
      src/parser.cpp

+ 18 - 6
core/odin/parser/parser.odin

@@ -848,12 +848,24 @@ parse_for_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
 		if !is_range && parse_control_statement_semicolon_separator(p) {
 			init = cond;
 			cond = nil;
-			if p.curr_tok.kind != .Semicolon {
-				cond = parse_simple_stmt(p, nil);
-			}
-			expect_semicolon(p, cond);
-			if p.curr_tok.kind != .Open_Brace && p.curr_tok.kind != .Do {
-				post = parse_simple_stmt(p, nil);
+
+
+			if f.curr_tok.kind == .Open_Brace || f.curr_tok.kind == .Do {
+				error(p, f.curr_tok.pos, "Expected ';', followed by a condition expression and post statement, got %s", token.tokens[f.curr_tok.kind]);
+			} else {
+				if p.curr_tok.kind != .Semicolon {
+					cond = parse_simple_stmt(p, nil);
+				}
+
+				if p.curr_tok.text != ";" {
+					error(p, p.curr_tok.pos, "Expected ';', got %s", tokenizer.token_to_string(p.curr_tok));
+				} else {
+					expect_semicolon(p, nil);
+				}
+
+				if p.curr_tok.kind != .Open_Brace && p.curr_tok.kind != .Do {
+					post = parse_simple_stmt(p, nil);
+				}
 			}
 		}
 	}

+ 18 - 8
src/parser.cpp

@@ -4145,16 +4145,26 @@ Ast *parse_for_stmt(AstFile *f) {
 		if (!is_range && parse_control_statement_semicolon_separator(f)) {
 			init = cond;
 			cond = nullptr;
-			if (f->curr_token.kind != Token_Semicolon) {
-				cond = parse_simple_stmt(f, StmtAllowFlag_None);
-			}
-			expect_semicolon(f, cond);
-			if (f->curr_token.kind != Token_OpenBrace &&
-			    f->curr_token.kind != Token_do) {
-				post = parse_simple_stmt(f, StmtAllowFlag_None);
+
+			if (f->curr_token.kind == Token_OpenBrace || f->curr_token.kind == Token_do) {
+				syntax_error(f->curr_token, "Expected ';', followed by a condition expression and post statement, got %.*s", LIT(token_strings[f->curr_token.kind]));
+			} else {
+				if (f->curr_token.kind != Token_Semicolon) {
+					cond = parse_simple_stmt(f, StmtAllowFlag_None);
+				}
+
+				if (f->curr_token.string != ";") {
+					syntax_error(f->curr_token, "Expected ';', got %.*s", LIT(token_to_string(f->curr_token)));
+				} else {
+					expect_semicolon(f, nullptr);
+				}
+
+				if (f->curr_token.kind != Token_OpenBrace &&
+				    f->curr_token.kind != Token_do) {
+					post = parse_simple_stmt(f, StmtAllowFlag_None);
+				}
 			}
 		}
-
 	}