Source

ocaml-lib / dcg / pa_dcg.ml

Diff from to

File dcg/pa_dcg.ml

   expr: LEVEL "top"
       [ [ "dcg"; eo = OPT [ s = str -> s ]; p = rule ->
 	( match eo with
-	| None -> <:expr< fun str -> $p$ str >>
-	| Some e -> <:expr< fun str -> if !Dcg.trace then begin prerr_string "dcg > "; prerr_endline $e$; flush stderr; let res = $p$ str in begin prerr_string "dcg < "; prerr_endline $e$; flush stderr; res end end else $p$ str >>) ] ];
+	| 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 >>) ] ];
 
   rule:
       [ [ "["; OPT "|"; p = alt; "]" -> p ] ];
       | "when"; s = str; e = expr LEVEL "top" ->
 	  let f = <:expr< fun () -> $e$ >> in
 	  <:patt< _ >>, <:expr< Dcg.check $s$ $f$ >>
+      | "?"; x = ipatt ->
+	  x, <:expr< Dcg.get_context >>
+      | "!"; e = expr LEVEL "top" ->
+	  <:patt< _ >>, <:expr< Dcg.set_context $e$ >>
       | s = str ->
         <:patt< _ >>, <:expr< Matcher.look $s$ >>
       | x = ipatt; ff = binding ->