Commits

Sébastien Ferré  committed efa6d6f

Add of checks (when clause in isolation).
Change of syntax for cuts to avoid parse error.

  • Participants
  • Parent commits fba87cc

Comments (0)

Files changed (1)

File dcg/pa_dcg.ml

 
   seq:
       [ [ "->"; e = expr ->
-        let p = <:expr< Dcg.eps >> in
-	let f = <:expr< fun _ -> $e$ >> in
-	<:expr< Dcg.map $p$ $f$ >>
-      | (x1,p1) = atom; "!"; p2 = seq2; "|"; p3 = alt ->
-	  let f = <:expr< fun $pat:x1$ -> $p2$ >> in
-	  <:expr< Dcg.cut $p1$ $f$ $p3$ >>
-      | (x1,p1) = atom; f2 = seq1 ->
-          f2 (x1,p1)
-      ] ];
+            let p = <:expr< Dcg.eps >> in
+	    let f = <:expr< fun _ -> $e$ >> in
+	    <:expr< Dcg.map $p$ $f$ >>
+        | (x1,p1) = atom; ";"; "!"; ";"; p2 = seq2; "|"; p3 = alt ->
+	    let f = <:expr< fun $pat:x1$ -> $p2$ >> in
+	    <:expr< Dcg.cut $p1$ $f$ $p3$ >>
+        | (x1,p1) = atom; f2 = seq1 ->
+            f2 (x1,p1)
+        ] ];
 
   seq1:
     [ [ "->"; e = expr ->
         <:patt< _ >>, <:expr< Dcg.eps >>
       | "EOF" ->
         <:patt< _ >>, <:expr< Matcher.eof >>
+      | "when"; s = str; e = expr LEVEL "top" ->
+	  let f = <:expr< fun () -> $e$ >> in
+	  <:patt< _ >>, <:expr< Dcg.check $s$ $f$ >>
       | s = str ->
         <:patt< _ >>, <:expr< Matcher.look $s$ >>
       | x = ipatt; "="; p = quantif; eo = OPT [ "when"; s = str; e = expr LEVEL "top" -> (s,e) ] -> 
     [ [ "OPT"; p = par; "ELSE"; x = expr LEVEL "top" -> <:expr< Dcg.opt $p$ $x$ >>
       | "MANY"; p = par -> <:expr< Dcg.many $p$ >>
       | "SOME"; p = par -> <:expr< Dcg.some $p$ >>
+      | "LIST0"; p = par; "SEP"; s = sep -> <:expr< Dcg.list0 $p$ $s$ >>
+      | "LIST1"; p = par; "SEP"; s = sep -> <:expr< Dcg.list1 $p$ $s$ >> ]
+(*
       | "LIST0"; p = par; "SEP"; s = expr LEVEL "simple" -> let sep = <:expr< Matcher.look $s$ >> in <:expr< Dcg.list0 $p$ $sep$ >>
       | "LIST1"; p = par; "SEP"; s = expr LEVEL "simple" -> let sep = <:expr< Matcher.look $s$ >> in <:expr< Dcg.list1 $p$ $sep$ >> ]
+*)
     | [ p = par -> p
       ] ];
 
       | p = expr LEVEL "top" -> p
       ] ];
 
+  sep:
+    [ [ s = str -> <:expr< Matcher.look $s$ >>
+      | p = par -> p
+      ] ];
+
   str:
     [ [ s = a_STRING -> <:expr< $str:s$ >>
       | "'"; e = expr LEVEL "simple" -> <:expr< $e$ >>