소스 검색

[parser] fix semicolon-else vs. not-xml

closes #8565
Simon Krajewski 6 년 전
부모
커밋
6591e1f157

+ 11 - 5
src/syntax/grammar.mly

@@ -1262,11 +1262,17 @@ and expr = parser
 		let e2 = (match s with parser
 			| [< '(Kwd Else,_); e2 = secure_expr; s >] -> Some e2
 			| [< >] ->
-				match Stream.npeek 2 s with
-				| [(Semicolon,_); (Kwd Else,_)] ->
-					Stream.junk s;
-					Stream.junk s;
-					Some (secure_expr s)
+				(* We check this in two steps to avoid the lexer missing tokens (#8565). *)
+				match Stream.npeek 1 s with
+				| [(Semicolon,_)] ->
+					begin match Stream.npeek 2 s with
+					| [(Semicolon,_);(Kwd Else,_)] ->
+						Stream.junk s;
+						Stream.junk s;
+						Some (secure_expr s)
+					| _ ->
+						None
+					end
 				| _ ->
 					None
 		) in

+ 6 - 0
tests/misc/projects/Issue8565/Main.hx

@@ -0,0 +1,6 @@
+class Main {
+	static function main() {
+		if (true) {}
+		<someMarkup />;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue8565/compile-fail.hxml

@@ -0,0 +1 @@
+-main Main

+ 1 - 0
tests/misc/projects/Issue8565/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:4: characters 3-17 : Markup literals must be processed by a macro