浏览代码

[parser] don't require `}` for switches in display mode

closes #8217
Simon Krajewski 6 年之前
父节点
当前提交
1ce52fa9e1
共有 2 个文件被更改,包括 30 次插入1 次删除
  1. 8 1
      src/syntax/grammar.mly
  2. 22 0
      tests/display/src/cases/Issue8217.hx

+ 8 - 1
src/syntax/grammar.mly

@@ -1287,7 +1287,14 @@ and expr = parser
 		end
 		end
 	| [< '(Kwd Switch,p1); e = secure_expr; s >] ->
 	| [< '(Kwd Switch,p1); e = secure_expr; s >] ->
 		begin match s with parser
 		begin match s with parser
-			| [< '(BrOpen,_); cases , def = parse_switch_cases e []; '(BrClose,p2); s >] -> (ESwitch (e,cases,def),punion p1 p2)
+			| [< '(BrOpen,_); cases , def = parse_switch_cases e [] >] ->
+				let p2 = match s with parser
+					| [< '(BrClose,p2) >] -> p2
+					| [< >] ->
+						(* Ignore missing } if we are resuming and "guess" the last position. *)
+						syntax_error (Expected ["}"]) s (pos (next_token s))
+				in
+				(ESwitch (e,cases,def),punion p1 p2)
 			| [< >] ->
 			| [< >] ->
 				syntax_error (Expected ["{"]) s (ESwitch(e,[],None),punion p1 (pos e))
 				syntax_error (Expected ["{"]) s (ESwitch(e,[],None),punion p1 (pos e))
 		end
 		end

+ 22 - 0
tests/display/src/cases/Issue8217.hx

@@ -0,0 +1,22 @@
+package cases;
+
+class Issue8217 extends DisplayTestCase {
+	/**
+		class Main {
+			static function foo( cmd : String ) {
+				switch( cmd ) {
+				case "user/login":
+					var o = {
+						x : 55,
+						str : "hello".{-1-}
+						z : 66,
+					};
+				}
+			}
+
+		}
+	**/
+	function test() {
+		eq(true, hasField(fields(pos(1)), "length", "Int"));
+	}
+}