author | wenzelm |
Tue, 21 Jun 2022 14:51:17 +0200 | |
changeset 75571 | ac5e633ad9b3 |
parent 72840 | 6b96464066a0 |
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 |
72840 | 22 |
val string_of: source -> string |
62752 | 23 |
val equal_content: source * source -> bool |
59064 | 24 |
end; |
25 |
||
26 |
structure Input: INPUT = |
|
27 |
struct |
|
28 |
||
29 |
abstype source = Source of {delimited: bool, text: Symbol_Pos.text, range: Position.range} |
|
30 |
with |
|
31 |
||
62759 | 32 |
|
33 |
(* source *) |
|
34 |
||
59064 | 35 |
fun is_delimited (Source {delimited, ...}) = delimited; |
36 |
fun text_of (Source {text, ...}) = text; |
|
37 |
fun pos_of (Source {range = (pos, _), ...}) = pos; |
|
38 |
fun range_of (Source {range, ...}) = range; |
|
39 |
||
40 |
fun source delimited text range = |
|
41 |
Source {delimited = delimited, text = text, range = range}; |
|
42 |
||
67213 | 43 |
val empty = source false "" Position.no_range; |
44 |
||
59117 | 45 |
fun string text = source true text Position.no_range; |
46 |
||
67567 | 47 |
fun cartouche_content syms = |
48 |
let |
|
49 |
val range = Symbol_Pos.range syms; |
|
50 |
val (text, _) = Symbol_Pos.implode_range range (Symbol_Pos.cartouche_content syms); |
|
51 |
in source true text range end; |
|
52 |
||
62759 | 53 |
fun reset_pos (Source {delimited, text, ...}) = source delimited text Position.no_range; |
54 |
||
55 |
||
56 |
(* content *) |
|
57 |
||
59064 | 58 |
fun source_explode (Source {text, range = (pos, _), ...}) = |
59 |
Symbol_Pos.explode (text, pos); |
|
60 |
||
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
|
61 |
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
|
62 |
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
|
63 |
in (Symbol_Pos.content syms, Symbol_Pos.range syms) end; |
59064 | 64 |
|
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
|
65 |
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
|
66 |
|
72840 | 67 |
val string_of = source_explode #> Symbol_Pos.content; |
68 |
||
69 |
val equal_content = (op =) o apply2 string_of; |
|
62752 | 70 |
|
59064 | 71 |
end; |
72 |
||
73 |
end; |