| 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
 | 
| 59117 |     15 |   val string: string -> source
 | 
| 59064 |     16 |   val source_explode: source -> Symbol_Pos.T list
 | 
| 59066 |     17 |   val source_content: source -> string
 | 
| 59064 |     18 | end;
 | 
|  |     19 | 
 | 
|  |     20 | structure Input: INPUT =
 | 
|  |     21 | struct
 | 
|  |     22 | 
 | 
|  |     23 | abstype source = Source of {delimited: bool, text: Symbol_Pos.text, range: Position.range}
 | 
|  |     24 | with
 | 
|  |     25 | 
 | 
|  |     26 | fun is_delimited (Source {delimited, ...}) = delimited;
 | 
|  |     27 | fun text_of (Source {text, ...}) = text;
 | 
|  |     28 | fun pos_of (Source {range = (pos, _), ...}) = pos;
 | 
|  |     29 | fun range_of (Source {range, ...}) = range;
 | 
|  |     30 | 
 | 
|  |     31 | fun source delimited text range =
 | 
|  |     32 |   Source {delimited = delimited, text = text, range = range};
 | 
|  |     33 | 
 | 
| 59117 |     34 | fun string text = source true text Position.no_range;
 | 
|  |     35 | 
 | 
| 59064 |     36 | fun source_explode (Source {text, range = (pos, _), ...}) =
 | 
|  |     37 |   Symbol_Pos.explode (text, pos);
 | 
|  |     38 | 
 | 
| 59066 |     39 | val source_content = source_explode #> Symbol_Pos.content;
 | 
| 59064 |     40 | 
 | 
|  |     41 | end;
 | 
|  |     42 | 
 | 
|  |     43 | end;
 | 
|  |     44 | 
 |