src/Pure/General/source.ML
changeset 37903 b7ae269c0d68
parent 29606 fedb8be05f24
child 38253 3d4e521014f7
equal deleted inserted replaced
37902:4e7864f3643d 37903:b7ae269c0d68
    14   val get_single: ('a, 'b) source -> ('a * ('a, 'b) source) option
    14   val get_single: ('a, 'b) source -> ('a * ('a, 'b) source) option
    15   val exhaust: ('a, 'b) source -> 'a list
    15   val exhaust: ('a, 'b) source -> 'a list
    16   val map_filter: ('a -> 'b option) -> ('a, 'c) source -> ('b, ('a, 'c) source) source
    16   val map_filter: ('a -> 'b option) -> ('a, 'c) source -> ('b, ('a, 'c) source) source
    17   val filter: ('a -> bool) -> ('a, 'b) source -> ('a, ('a, 'b) source) source
    17   val filter: ('a -> bool) -> ('a, 'b) source -> ('a, ('a, 'b) source) source
    18   val of_list: 'a list -> ('a, 'a list) source
    18   val of_list: 'a list -> ('a, 'a list) source
    19   val of_list_limited: int -> 'a list -> ('a, 'a list) source
    19   val exhausted: ('a, 'b) source -> ('a, 'a list) source
    20   val of_string: string -> (string, string list) source
    20   val of_string: string -> (string, string list) source
    21   val exhausted: ('a, 'b) source -> ('a, 'a list) source
    21   val of_string_limited: int -> string -> (string, substring) source
    22   val tty: (string, unit) source
    22   val tty: (string, unit) source
    23   val source': 'a -> 'b Scan.stopper -> ('a * 'b list -> 'c list * ('a * 'b list)) ->
    23   val source': 'a -> 'b Scan.stopper -> ('a * 'b list -> 'c list * ('a * 'b list)) ->
    24     (bool * (string -> 'a * 'b list -> 'c list * ('a * 'b list))) option ->
    24     (bool * (string -> 'a * 'b list -> 'c list * ('a * 'b list))) option ->
    25     ('b, 'e) source -> ('c, 'a * ('b, 'e) source) source
    25     ('b, 'e) source -> ('c, 'a * ('b, 'e) source) source
    26   val source: 'a Scan.stopper -> ('a list -> 'b list * 'a list) ->
    26   val source: 'a Scan.stopper -> ('a list -> 'b list * 'a list) ->
    99 (** build sources **)
    99 (** build sources **)
   100 
   100 
   101 (* list source *)
   101 (* list source *)
   102 
   102 
   103 fun of_list xs = make_source [] xs default_prompt (fn _ => fn xs => (xs, []));
   103 fun of_list xs = make_source [] xs default_prompt (fn _ => fn xs => (xs, []));
   104 fun of_list_limited n xs = make_source [] xs default_prompt (fn _ => chop n);
   104 
       
   105 fun exhausted src = of_list (exhaust src);
       
   106 
       
   107 
       
   108 (* string source *)
   105 
   109 
   106 val of_string = of_list o explode;
   110 val of_string = of_list o explode;
   107 
   111 
   108 fun exhausted src = of_list (exhaust src);
   112 fun of_string_limited limit str =
       
   113   make_source [] (Substring.full str) default_prompt
       
   114     (fn _ => fn s =>
       
   115       let
       
   116         val (s1, s2) = Substring.splitAt (s, Int.min (Substring.size s, limit));
       
   117         val cs = map String.str (Substring.explode s1);
       
   118       in (cs, s2) end);
   109 
   119 
   110 
   120 
   111 (* stream source *)
   121 (* stream source *)
   112 
   122 
   113 fun slurp_input instream =
   123 fun slurp_input instream =