src/Pure/General/input.ML
author wenzelm
Fri, 17 Mar 2017 20:33:27 +0100
changeset 65292 e3bd1e7ddd23
parent 62759 d16b2ec535ba
child 67213 01576aebc398
permissions -rw-r--r--
more robust JDBC initialization, e.g. required for Isabelle/jEdit startup;
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
59117
caddfa6ca534 tuned signature;
wenzelm
parents: 59066
diff changeset
    15
  val string: string -> source
62759
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    16
  val reset_pos: source -> source
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    17
  val source_explode: source -> Symbol_Pos.T list
59066
45ab32a542fe tuned signature;
wenzelm
parents: 59064
diff changeset
    18
  val source_content: source -> string
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59117
diff changeset
    19
  val equal_content: source * source -> bool
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    20
end;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    21
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    22
structure Input: INPUT =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    23
struct
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    24
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    25
abstype source = Source of {delimited: bool, text: Symbol_Pos.text, range: Position.range}
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    26
with
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    27
62759
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    28
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    29
(* source *)
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    30
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    31
fun is_delimited (Source {delimited, ...}) = delimited;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    32
fun text_of (Source {text, ...}) = text;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    33
fun pos_of (Source {range = (pos, _), ...}) = pos;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    34
fun range_of (Source {range, ...}) = range;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    35
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    36
fun source delimited text range =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    37
  Source {delimited = delimited, text = text, range = range};
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    38
59117
caddfa6ca534 tuned signature;
wenzelm
parents: 59066
diff changeset
    39
fun string text = source true text Position.no_range;
caddfa6ca534 tuned signature;
wenzelm
parents: 59066
diff changeset
    40
62759
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    41
fun reset_pos (Source {delimited, text, ...}) = source delimited text Position.no_range;
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    42
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    43
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    44
(* content *)
d16b2ec535ba more operations;
wenzelm
parents: 62752
diff changeset
    45
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    46
fun source_explode (Source {text, range = (pos, _), ...}) =
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    47
  Symbol_Pos.explode (text, pos);
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    48
59066
45ab32a542fe tuned signature;
wenzelm
parents: 59064
diff changeset
    49
val source_content = source_explode #> Symbol_Pos.content;
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    50
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59117
diff changeset
    51
val equal_content = (op =) o apply2 source_content;
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 59117
diff changeset
    52
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    53
end;
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    54
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents:
diff changeset
    55
end;