src/Pure/General/symbol_pos.ML
author wenzelm
Sat, 30 Apr 2011 18:16:40 +0200
changeset 42503 27514b6fbe93
parent 41416 a2208d3e2bd6
child 43709 717e96cf9527
permissions -rw-r--r--
more uniform variations of scan_string;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/symbol_pos.ML
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     3
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     4
Symbols with explicit position information.
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     5
*)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     6
36957
cdb9e83abfbe tuned signature;
wenzelm
parents: 32784
diff changeset
     7
signature SYMBOL_POS =
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     8
sig
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
     9
  type T = Symbol.symbol * Position.T
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    10
  val symbol: T -> Symbol.symbol
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    11
  val $$$ : Symbol.symbol -> T list -> T list * T list
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    12
  val ~$$$ : Symbol.symbol -> T list -> T list * T list
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
    13
  val content: T list -> string
27852
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    14
  val untabify_content: T list -> string
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    15
  val is_eof: T -> bool
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    16
  val stopper: T Scan.stopper
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    17
  val !!! : string -> (T list -> 'a) -> T list -> 'a
30586
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    18
  val change_prompt: ('a -> 'b) -> 'a -> 'b
27778
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
    19
  val scan_pos: T list -> Position.T * T list
42503
27514b6fbe93 more uniform variations of scan_string;
wenzelm
parents: 41416
diff changeset
    20
  val scan_string_q: T list -> (Position.T * (T list * Position.T)) * T list
27514b6fbe93 more uniform variations of scan_string;
wenzelm
parents: 41416
diff changeset
    21
  val scan_string_qq: T list -> (Position.T * (T list * Position.T)) * T list
27514b6fbe93 more uniform variations of scan_string;
wenzelm
parents: 41416
diff changeset
    22
  val scan_string_bq: T list -> (Position.T * (T list * Position.T)) * T list
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    23
  val scan_comment: (string -> (T list -> T list * T list) -> T list -> T list * T list) ->
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    24
    T list -> T list * T list
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    25
  val scan_comment_body: (string -> (T list -> T list * T list) -> T list -> T list * T list) ->
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    26
    T list -> T list * T list
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    27
  val source: Position.T -> (Symbol.symbol, 'a) Source.source ->
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    28
    (T, Position.T * (Symbol.symbol, 'a) Source.source) Source.source
27778
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
    29
  type text = string
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
    30
  val implode: T list -> text
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
    31
  val range: T list -> Position.range
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
    32
  val implode_range: Position.T -> Position.T -> T list -> text * Position.range
27778
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
    33
  val explode: text * Position.T -> T list
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    34
end;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    35
30573
49899f26fbd1 de-camelized Symbol_Pos;
wenzelm
parents: 29606
diff changeset
    36
structure Symbol_Pos: SYMBOL_POS =
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    37
struct
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    38
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    39
(* type T *)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    40
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    41
type T = Symbol.symbol * Position.T;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    42
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    43
fun symbol ((s, _): T) = s;
27852
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    44
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    45
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    46
(* content *)
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    47
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
    48
val content = implode o map symbol;
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    49
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    50
27864
827730aea9e8 made SML/NJ happy;
wenzelm
parents: 27852
diff changeset
    51
val tab_width = (8: int);
27852
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    52
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    53
fun untabify ("\t", pos) =
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    54
      (case Position.column_of pos of
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    55
        SOME n => Symbol.spaces (tab_width - ((n - 1) mod tab_width))
27984
b4dd58cff97c untabify: silently turn tab into space if column information is unavailable;
wenzelm
parents: 27864
diff changeset
    56
      | NONE => Symbol.space)
27852
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    57
  | untabify (s, _) = s;
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    58
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    59
val untabify_content = implode o map untabify;
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    60
6454fef6a293 added untabify_content;
wenzelm
parents: 27797
diff changeset
    61
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    62
(* stopper *)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    63
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    64
fun mk_eof pos = (Symbol.eof, pos);
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    65
val eof = mk_eof Position.none;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    66
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    67
val is_eof = Symbol.is_eof o symbol;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    68
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    69
val stopper =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    70
  Scan.stopper (fn [] => eof | inp => mk_eof (List.last inp |-> Position.advance)) is_eof;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    71
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    72
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    73
(* basic scanners *)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    74
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    75
fun !!! text scan =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    76
  let
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    77
    fun get_pos [] = " (past end-of-text!)"
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    78
      | get_pos ((_, pos) :: _) = Position.str_of pos;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    79
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    80
    fun err (syms, msg) =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    81
      text ^ get_pos syms ^ " at " ^ Symbol.beginning 10 (map symbol syms) ^
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    82
      (case msg of NONE => "" | SOME s => "\n" ^ s);
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    83
  in Scan.!! err scan end;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    84
30586
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    85
fun change_prompt scan = Scan.prompt "# " scan;
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    86
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    87
fun $$$ s = Scan.one (fn x => symbol x = s) >> single;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    88
fun ~$$$ s = Scan.one (fn x => symbol x <> s) >> single;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    89
27778
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
    90
val scan_pos = Scan.ahead (Scan.one (K true)) >> (fn (_, pos): T => pos);
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    91
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
    92
30586
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    93
(* Isabelle strings *)
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    94
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    95
local
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    96
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    97
val char_code =
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    98
  Scan.one (Symbol.is_ascii_digit o symbol) --
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
    99
  Scan.one (Symbol.is_ascii_digit o symbol) --
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   100
  Scan.one (Symbol.is_ascii_digit o symbol) :|--
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   101
  (fn (((a, pos), (b, _)), (c, _)) =>
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   102
    let val (n, _) = Library.read_int [a, b, c]
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   103
    in if n <= 255 then Scan.succeed [(chr n, pos)] else Scan.fail end);
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   104
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   105
fun scan_str q =
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   106
  $$$ "\\" |-- !!! "bad escape character in string" ($$$ q || $$$ "\\" || char_code) ||
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   107
  Scan.one (fn (s, _) => s <> q andalso s <> "\\" andalso Symbol.is_regular s) >> single;
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   108
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   109
fun scan_strs q =
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   110
  (scan_pos --| $$$ q) -- !!! "missing quote at end of string"
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   111
    (change_prompt ((Scan.repeat (scan_str q) >> flat) -- ($$$ q |-- scan_pos)));
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   112
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   113
in
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   114
42503
27514b6fbe93 more uniform variations of scan_string;
wenzelm
parents: 41416
diff changeset
   115
val scan_string_q = scan_strs "'";
27514b6fbe93 more uniform variations of scan_string;
wenzelm
parents: 41416
diff changeset
   116
val scan_string_qq = scan_strs "\"";
27514b6fbe93 more uniform variations of scan_string;
wenzelm
parents: 41416
diff changeset
   117
val scan_string_bq = scan_strs "`";
30586
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   118
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   119
end;
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   120
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   121
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   122
(* ML-style comments *)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   123
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   124
local
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   125
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   126
val scan_cmt =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   127
  Scan.depend (fn (d: int) => $$$ "(" @@@ $$$ "*" >> pair (d + 1)) ||
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   128
  Scan.depend (fn 0 => Scan.fail | d => $$$ "*" @@@ $$$ ")" >> pair (d - 1)) ||
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   129
  Scan.lift ($$$ "*" --| Scan.ahead (~$$$ ")")) ||
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   130
  Scan.lift (Scan.one (fn (s, _) => s <> "*" andalso Symbol.is_regular s)) >> single;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   131
30586
9674f64a0702 moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents: 30573
diff changeset
   132
val scan_body = change_prompt (Scan.pass 0 (Scan.repeat scan_cmt >> flat));
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   133
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   134
in
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   135
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   136
fun scan_comment cut =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   137
  $$$ "(" @@@ $$$ "*" @@@ cut "missing end of comment" (scan_body @@@ $$$ "*" @@@ $$$ ")");
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   138
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   139
fun scan_comment_body cut =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   140
  $$$ "(" |-- $$$ "*" |-- cut "missing end of comment" (scan_body --| $$$ "*" --| $$$ ")");
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   141
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   142
end;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   143
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   144
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   145
(* source *)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   146
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   147
fun source pos =
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   148
  Source.source' pos Symbol.stopper (Scan.bulk (Scan.depend (fn pos =>
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   149
    Scan.one Symbol.not_eof >> (fn s => (Position.advance s pos, (s, pos)))))) NONE;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   150
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   151
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   152
(* compact representation -- with Symbol.DEL padding *)
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   153
27778
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
   154
type text = string;
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
   155
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   156
fun pad [] = []
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   157
  | pad [(s, _)] = [s]
32784
1a5dde5079ac eliminated redundant bindings;
wenzelm
parents: 30586
diff changeset
   158
  | pad ((s1, pos1) :: (rest as (_, pos2) :: _)) =
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   159
      let
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   160
        val end_pos1 = Position.advance s1 pos1;
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   161
        val d = Int.max (0, Position.distance_of end_pos1 pos2);
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   162
      in s1 :: replicate d Symbol.DEL @ pad rest end;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   163
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   164
val implode = implode o pad;
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   165
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   166
fun range (syms as (_, pos) :: _) =
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   167
      let val pos' = List.last syms |-> Position.advance
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   168
      in Position.range pos pos' end
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   169
  | range [] = Position.no_range;
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   170
27797
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   171
fun implode_range pos1 pos2 syms =
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   172
  let val syms' = (("", pos1) :: syms @ [("", pos2)])
9861b39a2fd5 added content;
wenzelm
parents: 27778
diff changeset
   173
  in (implode syms', range syms') end;
27778
3ec7a4d9ef18 renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents: 27763
diff changeset
   174
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   175
fun explode (str, pos) =
41416
a2208d3e2bd6 more scalable Symbol_Pos.explode;
wenzelm
parents: 40525
diff changeset
   176
  let
a2208d3e2bd6 more scalable Symbol_Pos.explode;
wenzelm
parents: 40525
diff changeset
   177
    val (res, _) =
a2208d3e2bd6 more scalable Symbol_Pos.explode;
wenzelm
parents: 40525
diff changeset
   178
      fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p))
a2208d3e2bd6 more scalable Symbol_Pos.explode;
wenzelm
parents: 40525
diff changeset
   179
        (Symbol.explode str) ([], Position.reset_range pos);
a2208d3e2bd6 more scalable Symbol_Pos.explode;
wenzelm
parents: 40525
diff changeset
   180
  in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end;
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   181
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   182
end;
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   183
36957
cdb9e83abfbe tuned signature;
wenzelm
parents: 32784
diff changeset
   184
structure Basic_Symbol_Pos =   (*not open by default*)
cdb9e83abfbe tuned signature;
wenzelm
parents: 32784
diff changeset
   185
struct
cdb9e83abfbe tuned signature;
wenzelm
parents: 32784
diff changeset
   186
  val $$$ = Symbol_Pos.$$$;
cdb9e83abfbe tuned signature;
wenzelm
parents: 32784
diff changeset
   187
  val ~$$$ = Symbol_Pos.~$$$;
cdb9e83abfbe tuned signature;
wenzelm
parents: 32784
diff changeset
   188
end;
27763
f49f6275cefa Symbols with explicit position information.
wenzelm
parents:
diff changeset
   189