Commits

camlspotter committed e3023f2

rex printer fix

Comments (0)

Files changed (2)

   let char c = Buffer.add_char buf c in
   let string s = Buffer.add_string buf s in
   let greedy = function
-    | true -> char '?'
-    | false -> ()
+    | false -> char '?'
+    | true -> ()
   in
 
   let rec token = function
 	List.iter token tkns;
 	char ')'
     | Escaped s ->
-	char '\\';
+	string "\\\\";
 	string s
     | Quoted s ->
-	string "\\Q";
+	string "\\\\Q";
 	string s;
-	string "\\E"
+	string "\\\\E"
     | Quantifier (b, 0, -1, tk) ->
 	token tk;
 	char '*';
 	char '-';
 	token t2
     | ClassQuoted s ->
-	string "\\Q";
+	string "\\\\Q";
 	string s;
-	string "\\E"
+	string "\\\\E"
   in
   
   List.iter token tkns;
 
   module Top = Pa_top.Register(Syntax)
 
-  let build_rex _loc s typ flags =
+  let build_rex _loc (* s *) tokens typ flags =
     let group_binder = build_group_binder _loc typ in
-    let str = ExStr (_loc, s) in
+    (* let str = ExStr (_loc, s) in *)
+    let str = ExStr(_loc, Lexrex.string_of_tokens typ tokens) in
     let rex = 
       <:expr<
 	(* This enforces linking with Orakuda library *)
 
   let parse_rex_quotation _loc q =
     let loc = Loc.join (Loc.move `start q.q_shift _loc) in
-    let rex, tokens, flags = Lexrex.from_string q.q_contents in
+    let _rex, tokens, flags = Lexrex.from_string q.q_contents in
     let parse_flag = function
       | 'i' -> <:expr<`CASELESS>>
       | 'm' -> <:expr<`MULTLINE>>
 	<:expr<$sw$ :: $acc$>>) <:expr<[]>> (iter [] 0)
     in
     let typ = Lexrex.type_regexp tokens in
-    build_rex loc rex typ flags
+    build_rex loc (*rex*) tokens typ flags
   ;;
 
   let parse_rex_replace_quotation _loc q =
     let loc = Loc.join (Loc.move `start q.q_shift _loc) in
-    let rex, tokens, replace_ = Lexrex.replace_from_string q.q_contents in
+    let _rex, tokens, replace_ = Lexrex.replace_from_string q.q_contents in
     let replace, flags_ = Pa_format.parse ['/'] _loc None replace_ in
     let flags = match flags_ with
       | None -> ""
 	<:expr<$sw$ :: $acc$>>) <:expr<[]>> (iter [] 0)
     in
     let typ = Lexrex.type_regexp tokens in
-    let rex = build_rex loc rex typ flags in
+    let rex = build_rex loc (*rex*) tokens typ flags in
     (* CR jfuruse: we can unify these to substitute_substrings(_first) *)
     match replace with
     | `Const replace ->