浏览代码

fixed --interp
added errors for some unsupported macros

Nicolas Cannasse 14 年之前
父节点
当前提交
109480675a
共有 2 个文件被更改,包括 17 次插入6 次删除
  1. 14 6
      interp.ml
  2. 3 0
      main.ml

+ 14 - 6
interp.ml

@@ -1375,7 +1375,7 @@ let reg_lib =
 					| c -> failwith ("Unsupported regexp option '" ^ String.make 1 c ^ "'")
 				) (ExtString.String.explode opt);
 				let buf = Buffer.create 0 in
-				let rec loop esc = function
+				let rec loop prev esc = function
 					| [] -> ()
 					| c :: l when esc ->
 						(match c with
@@ -1388,19 +1388,23 @@ let reg_lib =
 							Buffer.add_char buf '\\';
 							Buffer.add_char buf c;
 						| _ -> failwith ("Unsupported escaped char '" ^ String.make 1 c ^ "'"));
-						loop false l
+						loop c false l
 					| c :: l ->
 						match c with
-						| '\\' -> loop true l
+						| '\\' -> loop prev true l
 						| '(' | '|' | ')' ->
 							Buffer.add_char buf '\\';
 							Buffer.add_char buf c;
-							loop false l
+							loop c false l
+						| '?' when prev = '(' && (match l with ':' :: _ -> true | _ -> false) ->
+							failwith "Non capturing groups '(?:' are not supported in macros"
+						| '?' when prev = '*' ->
+							failwith "Ungreedy *? are not supported in macros"
 						| _ ->
 							Buffer.add_char buf c;
-							loop false l
+							loop c false l
 				in
-				loop false (ExtString.String.explode str);
+				loop '\000' false (ExtString.String.explode str);
 				let str = Buffer.contents buf in
 				let r = {
 					r = Str.regexp str;
@@ -2230,6 +2234,10 @@ let add_types ctx types =
 	let e = (EBlock (Genneko.build ctx.gen types), null_pos) in
 	ignore(catch_errors ctx (fun() -> ignore(eval ctx e)))
 
+let eval_expr ctx e =
+	let e = Genneko.gen_expr ctx.gen e in
+	catch_errors ctx (fun() -> eval ctx e)
+
 let get_path ctx path p =
 	let rec loop = function
 		| [] -> assert false

+ 3 - 0
main.ml

@@ -575,6 +575,9 @@ try
 			if !interp then begin
 				let ctx = Interp.create com (Typer.make_macro_api ctx Ast.null_pos) in
 				Interp.add_types ctx com.types;
+				(match com.main with
+				| None -> ()
+				| Some e -> ignore(Interp.eval_expr ctx e));
 			end;
 		| Flash | Flash9 when !gen_as3 ->
 			if com.verbose then print_endline ("Generating AS3 in : " ^ com.file);