src/Pure/General/input.ML
author wenzelm
Tue, 21 Jun 2022 14:51:17 +0200
changeset 75571 ac5e633ad9b3
parent 72840 6b96464066a0
permissions -rw-r--r--
tuned signature: more operations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/input.ML
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     3
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     4
Generic input with position information.
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     5
*)
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     6
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     7
signature INPUT =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     8
sig
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
     9
  type source
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    10
  val is_delimited: source -> bool
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    11
  val text_of: source -> Symbol_Pos.text
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    12
  val pos_of: source -> Position.T
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    13
  val range_of: source -> Position.range
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    14
  val source: bool -> Symbol_Pos.text -> Position.range -> source
67213
01576aebc398 more operations;
wenzelm
parents: 62759
diff changeset
    15
  val empty: source
59117
caddfa6ca534 tuned signature;
wenzelm
parents: 59066
diff changeset
    16
  val string: string -> source
67567
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    17
  val cartouche_content: Symbol_Pos.T list -> source
62759
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    18
  val reset_pos: source -> source
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    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
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 69471
diff changeset
    22
  val string_of: source -> string
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59117
diff changeset
    23
  val equal_content: source * source -> bool
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    24
end;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    25
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    26
structure Input: INPUT =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    27
struct
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    28
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    29
abstype source = Source of {delimited: bool, text: Symbol_Pos.text, range: Position.range}
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    30
with
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    31
62759
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    32
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    33
(* source *)
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    34
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    35
fun is_delimited (Source {delimited, ...}) = delimited;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    36
fun text_of (Source {text, ...}) = text;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    37
fun pos_of (Source {range = (pos, _), ...}) = pos;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    38
fun range_of (Source {range, ...}) = range;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    39
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    40
fun source delimited text range =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    41
  Source {delimited = delimited, text = text, range = range};
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    42
67213
01576aebc398 more operations;
wenzelm
parents: 62759
diff changeset
    43
val empty = source false "" Position.no_range;
01576aebc398 more operations;
wenzelm
parents: 62759
diff changeset
    44
59117
caddfa6ca534 tuned signature;
wenzelm
parents: 59066
diff changeset
    45
fun string text = source true text Position.no_range;
caddfa6ca534 tuned signature;
wenzelm
parents: 59066
diff changeset
    46
67567
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    47
fun cartouche_content syms =
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    48
  let
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    49
    val range = Symbol_Pos.range syms;
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    50
    val (text, _) = Symbol_Pos.implode_range range (Symbol_Pos.cartouche_content syms);
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    51
  in source true text range end;
52e6ffa61e9c clarified overall range: include delimiters;
wenzelm
parents: 67213
diff changeset
    52
62759
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    53
fun reset_pos (Source {delimited, text, ...}) = source delimited text Position.no_range;
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    54
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    55
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    56
(* content *)
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    57
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    58
fun source_explode (Source {text, range = (pos, _), ...}) =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    59
  Symbol_Pos.explode (text, pos);
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    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
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    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
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 69471
diff changeset
    67
val string_of = source_explode #> Symbol_Pos.content;
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 69471
diff changeset
    68
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 69471
diff changeset
    69
val equal_content = (op =) o apply2 string_of;
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59117
diff changeset
    70
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    71
end;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    72
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    73
end;