Commits

Sébastien Ferré committed 7514e8a

New syntax for cut.

Comments (0)

Files changed (1)

       [ [ "dcg"; eo = OPT [ s = str -> s ]; p = rule ->
 	( match eo with
 	| None -> <:expr< fun ctx str -> $p$ ctx str >>
-	| Some e -> <:expr< fun ctx str -> if !Dcg.trace then begin prerr_string "dcg > "; prerr_endline $e$; flush stderr; let res = $p$ ctx str in begin prerr_string "dcg < "; prerr_endline $e$; flush stderr; res end end else $p$ ctx str >>) ] ];
+	| Some e -> <:expr< fun ctx str -> $p$ ctx str >>) ] ];
+(*
+	    if !Dcg.trace then begin
+	      prerr_string "dcg > "; prerr_endline $e$; flush stderr;
+	      let res = $p$ ctx str in
+	      prerr_string "dcg < "; prerr_endline $e$; flush stderr;
+	      res end
+	    else $p$ ctx str >>) ] ];
+*)
 
   rule:
       [ [ "["; OPT "|"; p = alt; "]" -> p ] ];
   seq:
       [ [ "->"; e = expr ->
 	    <:expr< Dcg.ret $e$ >>
-        | (x1,p1) = atom; ";"; "!"; ";"; p2 = seq2; "|"; p3 = alt ->
+        | (x1,p1) = atom; "then"; p2 = seq2; "|"; p3 = alt ->
 	    let f = <:expr< fun $pat:x1$ -> $p2$ >> in
 	    <:expr< Dcg.cut $p1$ $f$ $p3$ >>
         | (x1,p1) = atom; f2 = seq1 ->
   par:
     [ [ p = rule -> p
       | "match"; regexp = expr LEVEL "top"; name_opt = OPT [ "as"; n = str -> n ] ->
-	  let name = match name_opt with Some n -> n | None -> regexp in
+	  let name =
+	    match name_opt with
+	    | Some n -> n
+	    | None -> <:expr< ("regexp \"" ^ String.escaped $regexp$ ^ "\"") >> in
 	  <:expr< Matcher.get $name$ (Str.regexp $regexp$) Matcher.Token.repr >>
       | p = expr LEVEL "top" -> p
       ] ];