| 59064 |      1 | (*  Title:      Pure/General/input.ML
 | 
|  |      2 |     Author:     Makarius
 | 
|  |      3 | 
 | 
|  |      4 | Generic input with position information.
 | 
|  |      5 | *)
 | 
|  |      6 | 
 | 
|  |      7 | signature INPUT =
 | 
|  |      8 | sig
 | 
|  |      9 |   type source
 | 
|  |     10 |   val is_delimited: source -> bool
 | 
|  |     11 |   val text_of: source -> Symbol_Pos.text
 | 
|  |     12 |   val pos_of: source -> Position.T
 | 
|  |     13 |   val range_of: source -> Position.range
 | 
|  |     14 |   val source: bool -> Symbol_Pos.text -> Position.range -> source
 | 
| 67213 |     15 |   val empty: source
 | 
| 59117 |     16 |   val string: string -> source
 | 
| 67567 |     17 |   val cartouche_content: Symbol_Pos.T list -> source
 | 
| 62759 |     18 |   val reset_pos: source -> source
 | 
| 59064 |     19 |   val source_explode: source -> Symbol_Pos.T list
 | 
| 59066 |     20 |   val source_content: source -> string
 | 
| 62752 |     21 |   val equal_content: source * source -> bool
 | 
| 59064 |     22 | end;
 | 
|  |     23 | 
 | 
|  |     24 | structure Input: INPUT =
 | 
|  |     25 | struct
 | 
|  |     26 | 
 | 
|  |     27 | abstype source = Source of {delimited: bool, text: Symbol_Pos.text, range: Position.range}
 | 
|  |     28 | with
 | 
|  |     29 | 
 | 
| 62759 |     30 | 
 | 
|  |     31 | (* source *)
 | 
|  |     32 | 
 | 
| 59064 |     33 | fun is_delimited (Source {delimited, ...}) = delimited;
 | 
|  |     34 | fun text_of (Source {text, ...}) = text;
 | 
|  |     35 | fun pos_of (Source {range = (pos, _), ...}) = pos;
 | 
|  |     36 | fun range_of (Source {range, ...}) = range;
 | 
|  |     37 | 
 | 
|  |     38 | fun source delimited text range =
 | 
|  |     39 |   Source {delimited = delimited, text = text, range = range};
 | 
|  |     40 | 
 | 
| 67213 |     41 | val empty = source false "" Position.no_range;
 | 
|  |     42 | 
 | 
| 59117 |     43 | fun string text = source true text Position.no_range;
 | 
|  |     44 | 
 | 
| 67567 |     45 | fun cartouche_content syms =
 | 
|  |     46 |   let
 | 
|  |     47 |     val range = Symbol_Pos.range syms;
 | 
|  |     48 |     val (text, _) = Symbol_Pos.implode_range range (Symbol_Pos.cartouche_content syms);
 | 
|  |     49 |   in source true text range end;
 | 
|  |     50 | 
 | 
| 62759 |     51 | fun reset_pos (Source {delimited, text, ...}) = source delimited text Position.no_range;
 | 
|  |     52 | 
 | 
|  |     53 | 
 | 
|  |     54 | (* content *)
 | 
|  |     55 | 
 | 
| 59064 |     56 | fun source_explode (Source {text, range = (pos, _), ...}) =
 | 
|  |     57 |   Symbol_Pos.explode (text, pos);
 | 
|  |     58 | 
 | 
| 59066 |     59 | val source_content = source_explode #> Symbol_Pos.content;
 | 
| 59064 |     60 | 
 | 
| 62752 |     61 | val equal_content = (op =) o apply2 source_content;
 | 
|  |     62 | 
 | 
| 59064 |     63 | end;
 | 
|  |     64 | 
 | 
|  |     65 | end;
 |