Commits

camlspotter committed 0f2fa17

fix

  • Participants
  • Parent commits ac714f2

Comments (0)

Files changed (3)

   | _ -> false)
 
 module Token = struct
-  type token =
+  type t =
     | Int of int
     | Char of char
     | String of string
     | LIdent of string
     | UIdent of string
 
+  type token = t
+  module Stream = Stream.Simple(struct type t = token end)
+
   let lex : token option P.t =
     let open P in
     (plus_ whitespace >>= fun _ -> return None)
-    <|> ((
-      (Literal.char >>= fun c -> return (Char c))
-      <|> (Literal.string >>= fun s -> return (String s))
-	<|> (Literal.nat_int >>= fun i -> return (Int i))
-	  <|> (Identifier.lowercase >>= fun s -> return (LIdent s))
-	    <|> (Identifier.uppercase >>= fun s -> return (UIdent s))
-	      <|> error "Unexpected token"
-    ) >>= fun v -> return (Some v))
+	<|> ((
+	  (Literal.char >>= fun c -> return (Char c))
+	  <|> (Literal.string >>= fun s -> return (String s))
+	    <|> (Literal.nat_int >>= fun i -> return (Int i))
+	      <|> (Identifier.lowercase >>= fun s -> return (LIdent s))
+		<|> (Identifier.uppercase >>= fun s -> return (UIdent s))
+		  <|> error "Unexpected token"
+	) >>= fun v -> return (Some v))
+    
+  let stream st = Stream.create (P.stream_gen lex st)
+end
 
-  module Stream = Stream.Simple(struct type t = token end)
-
-  let rec tokens s = 
-    let open P in
-    (lex >>= function
-      | None -> tokens
-      | Some tok -> 
-	  tokens >>= fun toks -> return (tok :: toks)) s
-
-  type t = token
-end
-;;
-
-let f = 1
-
+include P
 
 module Identifier : sig
   open P
+
   val lowercase : string t
   val uppercase : string t
 end
 val whitespace : char P.t
 
 module Token : sig
-  type token =
+  type t =
     | Int of int
     | Char of char
     | String of string
     | LIdent of string
     | UIdent of string
 
-  val lex : token option P.t
+  val lex : t option P.t
 
-  val tokens : token list P.t
-
-  type t = token
+  module Stream : Stream.S 
+    with type pos = Sbuffer.pos
+    and type elem = t
+  val stream : Sbuffer.t -> Stream.t
 end
 open Plang
-open Plang.P
 
 let test t str =
   let stream = Sbuffer.from_string str in