Commits

james woodyatt  committed 4fb136b

Rollback previous change. Add the Cf_llscan.phr and phr0 functions.

  • Participants
  • Parent commits 7c6c614
  • Branches sideline

Comments (0)

Files changed (2)

File cf/cf_llscan.ml

     in
     enter
 
-let rec seqf f a p s =
-    match p s with
-    | None -> Some (a, s)
-    | Some (r, s) -> seqf f (f a r) p s
-
-let seqf1 f a p s =
-    match p s with
-    | None -> None
-    | Some (r, s) -> seqf f (f a r) p s
-
 let rec alt ps s =
     match ps with
     | [] -> None
         | None -> altz tl s
         | Some _ as r -> r
 
+let rec phr0 f g a s =
+    match g a s with
+    | None -> Some (a, s)
+    | Some (r, s) -> phr0 f g (f a r) s
+
+let rec phr f g a s =
+    match g a s with
+    | None -> None
+    | Some (r, s) -> phr0 f g (f a r) s
+
 exception Error
 
 let err =

File cf/cf_llscan.mli

 val seqx1:
     ('a -> ('s, 'b) t) -> ('b -> 'a * 'c) -> 'a -> ('s, 'a * 'c * 'c list) t
 
-(** Use [seqf f a p] to create a scanner that recognizes any number of
-    instances of the pattern recognized by [p] and returns the result of
-    folding the application [f] into the outputs of each scanner using the
-    initial state [a].
-*)
-val seqf: ('a -> 'r -> 'a) -> 'a -> ('s, 'r) t -> ('s, 'a) t
-
-(** Use [seqf1 f a p] to create a scanner that recognizes one or more instances
-    of the pattern recognized by [p] and returns the result of folding the
-    application [f] into the outputs of each scanner using the initial state
-    [a].
-*)
-val seqf1: ('a -> 'r -> 'a) -> 'a -> ('s, 'r) t -> ('s, 'a) t
-
 (** Use [alt ps] to create a scanner that produces the output from the first
     scanner in the list [ps] that recognizes a pattern in the input.  If no
     scanner in the list recognizes a pattern, then the scanner constructed by
 *)
 val altz: ('s, 'r) t Cf_seq.t -> ('s, 'r) t
 
+(** The phrase scanner composer. Use [seqm f g u] to compose a
+    scanner that recognizes input by folding the initial phrase state [u]
+    through applications of [g] to obtain each scanner, and applying [f] to the
+    current state and the previous output. The output is the final state.
+*)
+val phr: ('a -> 'r -> 'a) -> ('a -> ('s, 'r) t) -> 'a -> ('s, 'a) t
+
+(** The optionally empty phrase scanner composer. Use [seqm f g u] to compose a
+    scanner that recognizes input by folding the initial phrase state [u]
+    through applications of [g] to obtain each scanner, and applying [f] to the
+    current state and the previous output. The output is the final state. If no
+    phrase is recognized, then the output is the initial state.
+*)
+val phr0: ('a -> 'r -> 'a) -> ('a -> ('s, 'r) t) -> 'a -> ('s, 'a) t
+
 (** Generic parser error with no parameters. *)
 exception Error