Commits

Anonymous committed df9f375

Change some function names (parse -> expr_parse, x_of_seq -> expr_of_seq,
x_of_string -> expr_of_string). Add parse and parsex functions. Fix bugs
in the OCamlDoc text.

  • Participants
  • Parent commits 05ff35e

Comments (0)

Files changed (2)

File cf/cf_regex.ml

     in
     p_escape_ (List.rev_append esc_chx_list_ esc_expr_list_)
 
-let parse =
+let expr_parse =
     let symbol =
         let f = function
             | '\x00'..'\x1f' | '?' | '*' | '+' | '(' | ')' | '|'
     in
     expr DFA.nil
 
-let x_of_seq z =
-    match parse z with
+let expr_of_seq z =
+    match expr_parse z with
     | Some (v, z) -> v
     | _ -> raise (Error (Cf_seq.to_string z))
 
-let x_of_string s = x_of_seq (Cf_seq.of_string s)
+let expr_of_string s = expr_of_seq (Cf_seq.of_string s)
 
 let quote =
     let esc_ =
 type t = int DFA.t
 
 let of_expression x = DFA.create (x $@ (fun n z -> Some (n, Cf_seq.shift n z)))
-let of_seq z = of_expression (x_of_seq z)
-let of_string s = of_expression (x_of_string s)
+let of_seq z = of_expression (expr_of_seq z)
+let of_string s = of_expression (expr_of_string s)
 
 let test r s =
     let z = Cf_seq.of_string s in
     fun r s ->
         loop r s 0 [] (Cf_seq.of_string s)
 
+let parse r z =
+    match r z with
+    | Some (n, tl) -> Some (Cf_seq.to_string (Cf_seq.limit n z), tl)
+    | None -> None
+
+let parsex r = P.to_extended (parse r)
+
 (*--- End of File [ cf_regex.ml ] ---*)

File cf/cf_regex.mli

     - [`DDD   ] Matches the character with decimal code [DDD], where DDD is a
         three digit number between [000] and [255].
     - [`c_    ] Matches the control character corresponding to the subsequent
-        printable character, e.g. [`cA] is CONTROL-A, and [`c[] is ESCAPE.
+        printable character, e.g. [`cA] is CONTROL-A, and [`c\[] is ESCAPE.
     - [.      ] Matches any character except newline.
     - [*      ] (postfix) Matches the preceding expression, zero, one or
         several times in sequence.
     - [(..|..)] Alternatives.  Matches one of the expressions between the
         parentheses, which are separated by vertical bar characters.
     - [`_     ] Escaped special character.  The special characters are ['`'],
-        ['.'], ['*'], ['+'], ['?'], ['('], ['|'], [')'], ['['].
+        ['.'], ['*'], ['+'], ['?'], ['('], ['|'], [')'], ['\['].
 *)
 
 (** {6 Modules} *)
 (** A parser combinator on character streams that recognizes a regular
     expression and produces a DFA expression for it.
 *)
-val parse: (char, DFA.x) Cf_parser.t
+val expr_parse: (char, DFA.x) Cf_parser.t
+
+(** Use [expr_of_seq z] to evaluate the character sequence [z] as a regular
+    expression and produce the corresponding DFA expression.  Raises [Error] if
+    the sequence is not a valid expression.
+*)
+val expr_of_seq: char Cf_seq.t -> DFA.x
+
+(** Use [expr_of_string s] to evaluate the string [s] as a regular expression
+    and produce the corresponding DFA expression.  Raises [Error] if the string
+    is not a valid expression.
+*)
+val expr_of_string: string -> DFA.x
 
 (** A character flow that quotes all the special characters in the input so
     that the output may be used in a regular expression to match the input
 *)
 val split: t -> string -> string list
 
-(**/**)
+(** Use [parse r] to produce a parser that matches the input stream to the
+    regular expression [r] and returns the corresponding string value.
+*)
+val parse: t -> (char, string) Cf_parser.t
 
-(** {6 Internal Functions}
-    
-    The [x_of_seq] and [x_of_string] functions are used in {Cf_lex} to
-    implement the [( !~ )] and [( !$ )] operators.
+(** Use [parse r] to produce a parser that matches the input stream to the
+    regular expression [r] and returns the corresponding string value.
 *)
-
-val x_of_seq: char Cf_seq.t -> DFA.x
-val x_of_string: string -> DFA.x
+val parsex: t -> ('c, char, string) Cf_parser.X.t
 
 (*--- End of File [ cf_regex.mli ] ---*)