src/Pure/General/symbol.ML
changeset 6640 d2e8342bf5c3
parent 6320 4df282137880
child 6692 05c56f41e661
equal deleted inserted replaced
6639:d399db16964c 6640:d2e8342bf5c3
    21   val is_blank: symbol -> bool
    21   val is_blank: symbol -> bool
    22   val is_printable: symbol -> bool
    22   val is_printable: symbol -> bool
    23   val length: symbol list -> int
    23   val length: symbol list -> int
    24   val beginning: symbol list -> string
    24   val beginning: symbol list -> string
    25   val scan: string list -> symbol * string list
    25   val scan: string list -> symbol * string list
       
    26   val scanner: string -> (symbol list -> 'a * symbol list) -> symbol list -> 'a
    26   val source: bool -> (string, 'a) Source.source ->
    27   val source: bool -> (string, 'a) Source.source ->
    27     (symbol, (string, 'a) Source.source) Source.source
    28     (symbol, (string, 'a) Source.source) Source.source
    28   val explode: string -> symbol list
    29   val explode: string -> symbol list
    29   val input: string -> string
    30   val input: string -> string
    30   val use: Path.T -> unit
       
    31   val add_mode: string -> (string -> string * real) -> unit
    31   val add_mode: string -> (string -> string * real) -> unit
    32   val output: string -> string
    32   val output: string -> string
    33   val output_width: string -> string * real
    33   val output_width: string -> string * real
    34 end;
    34 end;
    35 
    35 
   229     None => c
   229     None => c
   230   | Some s => "\\" ^ s);
   230   | Some s => "\\" ^ s);
   231 
   231 
   232 
   232 
   233 
   233 
       
   234 (** scanning though symbols **)
       
   235 
       
   236 fun scanner msg scan chs =
       
   237   let
       
   238     fun err_msg cs = msg ^ ": " ^ beginning cs;
       
   239     val fin_scan = Scan.error (Scan.finite stopper (!! (fn (cs, _) => err_msg cs) scan));
       
   240   in
       
   241     (case fin_scan chs of
       
   242       (result, []) => result
       
   243     | (_, rest) => error (err_msg rest))
       
   244   end;
       
   245 
       
   246 
       
   247 
   234 (** symbol input **)
   248 (** symbol input **)
   235 
   249 
   236 (* scan *)
   250 (* scan *)
   237 
   251 
   238 val scan_id = Scan.one is_letter ^^ (Scan.any is_letdig >> implode);
   252 val scan_id = Scan.one is_letter ^^ (Scan.any is_letdig >> implode);
   272     if forall (fn c => ord c < enc_start) chs then str
   286     if forall (fn c => ord c < enc_start) chs then str
   273     else implode (map symbol' chs)
   287     else implode (map symbol' chs)
   274   end;
   288   end;
   275 
   289 
   276 
   290 
   277 (* version of 'use' with input filtering *)
       
   278 
       
   279 val use =
       
   280   if not needs_filtered_use then File.use	(*ML system (wrongly!) accepts non-ASCII*)
       
   281   else
       
   282     fn path =>
       
   283       let
       
   284         val txt = File.read path;
       
   285         val txt_out = input txt;
       
   286       in
       
   287         if txt = txt_out then File.use path
       
   288         else
       
   289           let val tmp_path = File.tmp_path path in
       
   290             File.write tmp_path txt_out;
       
   291             File.use tmp_path handle exn => (File.rm tmp_path; raise exn);
       
   292             File.rm tmp_path
       
   293           end
       
   294       end;
       
   295 
       
   296 
       
   297 
   291 
   298 (** symbol output **)
   292 (** symbol output **)
   299 
   293 
   300 (* default_output *)
   294 (* default_output *)
   301 
   295