author | wenzelm |
Tue, 27 Nov 2018 21:07:39 +0100 | |
changeset 69349 | 7cef9e386ffe |
parent 67567 | 52e6ffa61e9c |
child 69443 | 61396b9713d8 |
permissions | -rw-r--r-- |
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 |
69349
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
20 |
val source_content_range: source -> string * Position.range |
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
21 |
val source_content: source -> string * Position.T |
62752 | 22 |
val equal_content: source * source -> bool |
59064 | 23 |
end; |
24 |
||
25 |
structure Input: INPUT = |
|
26 |
struct |
|
27 |
||
28 |
abstype source = Source of {delimited: bool, text: Symbol_Pos.text, range: Position.range} |
|
29 |
with |
|
30 |
||
62759 | 31 |
|
32 |
(* source *) |
|
33 |
||
59064 | 34 |
fun is_delimited (Source {delimited, ...}) = delimited; |
35 |
fun text_of (Source {text, ...}) = text; |
|
36 |
fun pos_of (Source {range = (pos, _), ...}) = pos; |
|
37 |
fun range_of (Source {range, ...}) = range; |
|
38 |
||
39 |
fun source delimited text range = |
|
40 |
Source {delimited = delimited, text = text, range = range}; |
|
41 |
||
67213 | 42 |
val empty = source false "" Position.no_range; |
43 |
||
59117 | 44 |
fun string text = source true text Position.no_range; |
45 |
||
67567 | 46 |
fun cartouche_content syms = |
47 |
let |
|
48 |
val range = Symbol_Pos.range syms; |
|
49 |
val (text, _) = Symbol_Pos.implode_range range (Symbol_Pos.cartouche_content syms); |
|
50 |
in source true text range end; |
|
51 |
||
62759 | 52 |
fun reset_pos (Source {delimited, text, ...}) = source delimited text Position.no_range; |
53 |
||
54 |
||
55 |
(* content *) |
|
56 |
||
59064 | 57 |
fun source_explode (Source {text, range = (pos, _), ...}) = |
58 |
Symbol_Pos.explode (text, pos); |
|
59 |
||
69349
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
60 |
fun source_content_range source = |
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
61 |
let val syms = source_explode source |
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
62 |
in (Symbol_Pos.content syms, Symbol_Pos.range syms) end; |
59064 | 63 |
|
69349
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
64 |
val source_content = source_content_range #> apsnd #1; |
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
65 |
|
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
67567
diff
changeset
|
66 |
val equal_content = (op =) o apply2 (source_explode #> Symbol_Pos.content); |
62752 | 67 |
|
59064 | 68 |
end; |
69 |
||
70 |
end; |