author | wenzelm |
Thu, 18 Jan 2018 21:42:03 +0100 | |
changeset 67464 | bc8a76d5839a |
parent 67426 | 6311cf9dc943 |
child 68177 | 6e40f5d43936 |
permissions | -rw-r--r-- |
27763 | 1 |
(* Title: Pure/General/symbol_pos.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Symbols with explicit position information. |
|
5 |
*) |
|
6 |
||
36957 | 7 |
signature SYMBOL_POS = |
27763 | 8 |
sig |
9 |
type T = Symbol.symbol * Position.T |
|
67426 | 10 |
type 'a scanner = T list -> 'a * T list |
27763 | 11 |
val symbol: T -> Symbol.symbol |
27797 | 12 |
val content: T list -> string |
55033 | 13 |
val range: T list -> Position.range |
27763 | 14 |
val is_eof: T -> bool |
15 |
val stopper: T Scan.stopper |
|
67426 | 16 |
val !!! : Scan.message -> 'a scanner -> 'a scanner |
17 |
val $$ : Symbol.symbol -> T scanner |
|
18 |
val ~$$ : Symbol.symbol -> T scanner |
|
19 |
val $$$ : Symbol.symbol -> T list scanner |
|
20 |
val ~$$$ : Symbol.symbol -> T list scanner |
|
21 |
val scan_pos: Position.T scanner |
|
22 |
val scan_string_q: string -> (Position.T * (T list * Position.T)) scanner |
|
23 |
val scan_string_qq: string -> (Position.T * (T list * Position.T)) scanner |
|
24 |
val scan_string_bq: string -> (Position.T * (T list * Position.T)) scanner |
|
25 |
val recover_string_q: T list scanner |
|
26 |
val recover_string_qq: T list scanner |
|
27 |
val recover_string_bq: T list scanner |
|
43773 | 28 |
val quote_string_q: string -> string |
29 |
val quote_string_qq: string -> string |
|
30 |
val quote_string_bq: string -> string |
|
62781 | 31 |
val cartouche_content: T list -> T list |
67426 | 32 |
val scan_cartouche: string -> T list scanner |
33 |
val scan_cartouche_content: string -> T list scanner |
|
34 |
val recover_cartouche: T list scanner |
|
35 |
val scan_comment: string -> T list scanner |
|
36 |
val scan_comment_body: string -> T list scanner |
|
37 |
val recover_comment: T list scanner |
|
27763 | 38 |
val source: Position.T -> (Symbol.symbol, 'a) Source.source -> |
39 |
(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
|
40 |
type text = string |
27797 | 41 |
val implode: T list -> text |
59112 | 42 |
val implode_range: Position.range -> T list -> text * Position.range |
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
43 |
val explode: text * Position.T -> T list |
62751 | 44 |
val explode0: string -> T list |
67426 | 45 |
val scan_ident: T list scanner |
50239 | 46 |
val is_identifier: string -> bool |
67426 | 47 |
val scan_nat: T list scanner |
48 |
val scan_float: T list scanner |
|
27763 | 49 |
end; |
50 |
||
30573 | 51 |
structure Symbol_Pos: SYMBOL_POS = |
27763 | 52 |
struct |
53 |
||
54 |
(* type T *) |
|
55 |
||
56 |
type T = Symbol.symbol * Position.T; |
|
67426 | 57 |
type 'a scanner = T list -> 'a * T list; |
27763 | 58 |
|
59 |
fun symbol ((s, _): T) = s; |
|
27852 | 60 |
|
27797 | 61 |
val content = implode o map symbol; |
27763 | 62 |
|
55033 | 63 |
fun range (syms as (_, pos) :: _) = |
64 |
let val pos' = List.last syms |-> Position.advance |
|
62797 | 65 |
in Position.range (pos, pos') end |
55033 | 66 |
| range [] = Position.no_range; |
67 |
||
61705
546e6494049f
trim lines for @{theory_text} similarly to @{text};
wenzelm
parents:
61502
diff
changeset
|
68 |
|
27763 | 69 |
(* stopper *) |
70 |
||
71 |
fun mk_eof pos = (Symbol.eof, pos); |
|
72 |
val eof = mk_eof Position.none; |
|
73 |
||
74 |
val is_eof = Symbol.is_eof o symbol; |
|
75 |
||
76 |
val stopper = |
|
77 |
Scan.stopper (fn [] => eof | inp => mk_eof (List.last inp |-> Position.advance)) is_eof; |
|
78 |
||
79 |
||
80 |
(* basic scanners *) |
|
81 |
||
67426 | 82 |
fun !!! text (scan: 'a scanner) = |
27763 | 83 |
let |
48911
5debc3e4fa81
tuned messages: end-of-input rarely means physical end-of-file from the past;
wenzelm
parents:
48770
diff
changeset
|
84 |
fun get_pos [] = " (end-of-input)" |
48992 | 85 |
| get_pos ((_, pos) :: _) = Position.here pos; |
27763 | 86 |
|
43947
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents:
43773
diff
changeset
|
87 |
fun err (syms, msg) = fn () => |
48770 | 88 |
text () ^ get_pos syms ^ |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48992
diff
changeset
|
89 |
Markup.markup Markup.no_report (" at " ^ Symbol.beginning 10 (map symbol syms)) ^ |
43947
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents:
43773
diff
changeset
|
90 |
(case msg of NONE => "" | SOME m => "\n" ^ m ()); |
27763 | 91 |
in Scan.!! err scan end; |
92 |
||
55033 | 93 |
fun $$ s = Scan.one (fn x => symbol x = s); |
55107 | 94 |
fun ~$$ s = Scan.one (fn x => symbol x <> s); |
95 |
||
27763 | 96 |
fun $$$ s = Scan.one (fn x => symbol x = s) >> single; |
97 |
fun ~$$$ s = Scan.one (fn x => symbol x <> s) >> single; |
|
98 |
||
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
99 |
val scan_pos = Scan.ahead (Scan.one (K true)) >> (fn (_, pos): T => pos); |
27763 | 100 |
|
101 |
||
43773 | 102 |
(* scan string literals *) |
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
103 |
|
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
104 |
local |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
105 |
|
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
106 |
val 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 (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
|
108 |
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
|
109 |
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
|
110 |
(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
|
111 |
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
|
112 |
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
|
113 |
|
48764 | 114 |
fun scan_str q err_prefix = |
115 |
$$$ "\\" |-- !!! (fn () => err_prefix ^ "bad escape character in string") |
|
116 |
($$$ q || $$$ "\\" || char_code) || |
|
58854 | 117 |
Scan.one (fn (s, _) => s <> q andalso s <> "\\" andalso Symbol.not_eof s) >> single; |
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
118 |
|
48764 | 119 |
fun scan_strs q err_prefix = |
55103 | 120 |
Scan.ahead ($$ q) |-- |
121 |
!!! (fn () => err_prefix ^ "unclosed string literal") |
|
61476 | 122 |
((scan_pos --| $$$ q) -- (Scan.repeats (scan_str q err_prefix) -- ($$$ q |-- scan_pos))); |
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
123 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
124 |
fun recover_strs q = |
61476 | 125 |
$$$ q @@@ Scan.repeats (Scan.permissive (scan_str q "")); |
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
126 |
|
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
127 |
in |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
128 |
|
42503 | 129 |
val scan_string_q = scan_strs "'"; |
130 |
val scan_string_qq = scan_strs "\""; |
|
131 |
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
|
132 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
133 |
val recover_string_q = recover_strs "'"; |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
134 |
val recover_string_qq = recover_strs "\""; |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
135 |
val recover_string_bq = recover_strs "`"; |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
136 |
|
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
137 |
end; |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
138 |
|
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
139 |
|
43773 | 140 |
(* quote string literals *) |
141 |
||
142 |
local |
|
143 |
||
144 |
fun char_code i = |
|
145 |
(if i < 10 then "00" else if i < 100 then "0" else "") ^ string_of_int i; |
|
146 |
||
147 |
fun quote_str q s = |
|
148 |
if Symbol.is_ascii_control s then "\\" ^ char_code (ord s) |
|
149 |
else if s = q orelse s = "\\" then "\\" ^ s |
|
150 |
else s; |
|
151 |
||
152 |
fun quote_string q = enclose q q o implode o map (quote_str q) o Symbol.explode; |
|
153 |
||
154 |
in |
|
155 |
||
156 |
val quote_string_q = quote_string "'"; |
|
157 |
val quote_string_qq = quote_string "\""; |
|
158 |
val quote_string_bq = quote_string "`"; |
|
159 |
||
160 |
end; |
|
161 |
||
162 |
||
55033 | 163 |
(* nested text cartouches *) |
164 |
||
62781 | 165 |
fun cartouche_content syms = |
166 |
let |
|
167 |
fun err () = |
|
168 |
error ("Malformed text cartouche: " |
|
169 |
^ quote (content syms) ^ Position.here (#1 (range syms))); |
|
170 |
in |
|
171 |
(case syms of |
|
172 |
("\<open>", _) :: rest => |
|
173 |
(case rev rest of |
|
174 |
("\<close>", _) :: rrest => rev rrest |
|
175 |
| _ => err ()) |
|
176 |
| _ => err ()) |
|
177 |
end; |
|
178 |
||
55104
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
179 |
val scan_cartouche_depth = |
61502
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
180 |
Scan.repeat1 (Scan.depend (fn (depth: int option) => |
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
181 |
(case depth of |
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
182 |
SOME d => |
62210 | 183 |
$$ Symbol.open_ >> pair (SOME (d + 1)) || |
61502
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
184 |
(if d > 0 then |
62210 | 185 |
Scan.one (fn (s, _) => s <> Symbol.close andalso Symbol.not_eof s) >> pair depth || |
186 |
$$ Symbol.close >> pair (if d = 1 then NONE else SOME (d - 1)) |
|
61502
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
187 |
else Scan.fail) |
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
188 |
| NONE => Scan.fail))); |
55033 | 189 |
|
55105 | 190 |
fun scan_cartouche err_prefix = |
62210 | 191 |
Scan.ahead ($$ Symbol.open_) |-- |
55105 | 192 |
!!! (fn () => err_prefix ^ "unclosed text cartouche") |
61502
760e21900b01
clarified scan_cartouche_depth (amending 8284c0d5bf52): finish after outermost cartouche;
wenzelm
parents:
61476
diff
changeset
|
193 |
(Scan.provide is_none (SOME 0) scan_cartouche_depth); |
55033 | 194 |
|
62781 | 195 |
fun scan_cartouche_content err_prefix = |
196 |
scan_cartouche err_prefix >> cartouche_content; |
|
55033 | 197 |
|
62781 | 198 |
val recover_cartouche = Scan.pass (SOME 0) scan_cartouche_depth; |
55033 | 199 |
|
67413 | 200 |
|
27763 | 201 |
(* ML-style comments *) |
202 |
||
203 |
local |
|
204 |
||
205 |
val scan_cmt = |
|
206 |
Scan.depend (fn (d: int) => $$$ "(" @@@ $$$ "*" >> pair (d + 1)) || |
|
207 |
Scan.depend (fn 0 => Scan.fail | d => $$$ "*" @@@ $$$ ")" >> pair (d - 1)) || |
|
208 |
Scan.lift ($$$ "*" --| Scan.ahead (~$$$ ")")) || |
|
58854 | 209 |
Scan.lift (Scan.one (fn (s, _) => s <> "*" andalso Symbol.not_eof s)) >> single; |
27763 | 210 |
|
61476 | 211 |
val scan_cmts = Scan.pass 0 (Scan.repeats scan_cmt); |
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
212 |
|
27763 | 213 |
in |
214 |
||
55105 | 215 |
fun scan_comment err_prefix = |
55106 | 216 |
Scan.ahead ($$ "(" -- $$ "*") |-- |
217 |
!!! (fn () => err_prefix ^ "unclosed comment") |
|
58850 | 218 |
($$$ "(" @@@ $$$ "*" @@@ scan_cmts @@@ $$$ "*" @@@ $$$ ")"); |
27763 | 219 |
|
55105 | 220 |
fun scan_comment_body err_prefix = |
55106 | 221 |
Scan.ahead ($$ "(" -- $$ "*") |-- |
222 |
!!! (fn () => err_prefix ^ "unclosed comment") |
|
58850 | 223 |
($$ "(" |-- $$ "*" |-- scan_cmts --| $$ "*" --| $$ ")"); |
27763 | 224 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
225 |
val recover_comment = |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
226 |
$$$ "(" @@@ $$$ "*" @@@ scan_cmts; |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
227 |
|
27763 | 228 |
end; |
229 |
||
230 |
||
231 |
(* source *) |
|
232 |
||
233 |
fun source pos = |
|
234 |
Source.source' pos Symbol.stopper (Scan.bulk (Scan.depend (fn pos => |
|
58864 | 235 |
Scan.one Symbol.not_eof >> (fn s => (Position.advance s pos, (s, pos)))))); |
27763 | 236 |
|
237 |
||
238 |
(* compact representation -- with Symbol.DEL padding *) |
|
239 |
||
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
240 |
type text = string; |
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
241 |
|
27763 | 242 |
fun pad [] = [] |
243 |
| pad [(s, _)] = [s] |
|
32784 | 244 |
| pad ((s1, pos1) :: (rest as (_, pos2) :: _)) = |
27763 | 245 |
let |
246 |
val end_pos1 = Position.advance s1 pos1; |
|
27797 | 247 |
val d = Int.max (0, Position.distance_of end_pos1 pos2); |
27763 | 248 |
in s1 :: replicate d Symbol.DEL @ pad rest end; |
249 |
||
27797 | 250 |
val implode = implode o pad; |
27763 | 251 |
|
59112 | 252 |
fun implode_range (pos1, pos2) syms = |
27797 | 253 |
let val syms' = (("", pos1) :: syms @ [("", pos2)]) |
254 |
in (implode syms', range syms') end; |
|
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
255 |
|
27763 | 256 |
fun explode (str, pos) = |
41416 | 257 |
let |
258 |
val (res, _) = |
|
259 |
fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p)) |
|
62800 | 260 |
(Symbol.explode str) ([], Position.no_range_position pos); |
41416 | 261 |
in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end; |
27763 | 262 |
|
62751 | 263 |
fun explode0 str = explode (str, Position.none); |
264 |
||
50239 | 265 |
|
266 |
(* identifiers *) |
|
267 |
||
50242
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
268 |
local |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
269 |
|
52616
3ac2878764f9
more robust identifier syntax: sub/superscript counts as modifier of LETDIG part instead of LETTER, both isub/isup and sub/sup are allowed;
wenzelm
parents:
50493
diff
changeset
|
270 |
val letter = Scan.one (symbol #> Symbol.is_letter); |
3ac2878764f9
more robust identifier syntax: sub/superscript counts as modifier of LETDIG part instead of LETTER, both isub/isup and sub/sup are allowed;
wenzelm
parents:
50493
diff
changeset
|
271 |
val letdigs1 = Scan.many1 (symbol #> Symbol.is_letdig); |
53016
fa9c38891cf2
disable old identifier syntax by default, legacy_isub_isup := true may be used temporarily as fall-back;
wenzelm
parents:
52920
diff
changeset
|
272 |
|
62529
8b7bdfc09f3b
clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents:
62239
diff
changeset
|
273 |
val sub = Scan.one (symbol #> (fn s => s = "\<^sub>")); |
50242
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
274 |
|
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
275 |
in |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
276 |
|
61476 | 277 |
val scan_ident = letter ::: Scan.repeats (letdigs1 || sub ::: letdigs1); |
50242
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
278 |
|
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
279 |
end; |
56b9c792a98b
support for sub-structured identifier syntax (inactive);
wenzelm
parents:
50239
diff
changeset
|
280 |
|
50239 | 281 |
fun is_identifier s = |
50295
3d6a4135a54f
eliminated redundant is_ident -- more official is_identifier;
wenzelm
parents:
50253
diff
changeset
|
282 |
Symbol.is_ascii_identifier s orelse |
62751 | 283 |
(case try (Scan.finite stopper scan_ident) (explode0 s) of |
50295
3d6a4135a54f
eliminated redundant is_ident -- more official is_identifier;
wenzelm
parents:
50253
diff
changeset
|
284 |
SOME (_, []) => true |
3d6a4135a54f
eliminated redundant is_ident -- more official is_identifier;
wenzelm
parents:
50253
diff
changeset
|
285 |
| _ => false); |
50239 | 286 |
|
62782 | 287 |
|
288 |
(* numerals *) |
|
289 |
||
290 |
val scan_nat = Scan.many1 (Symbol.is_digit o symbol); |
|
291 |
val scan_float = scan_nat @@@ $$$ "." @@@ scan_nat; |
|
292 |
||
27763 | 293 |
end; |
294 |
||
36957 | 295 |
structure Basic_Symbol_Pos = (*not open by default*) |
296 |
struct |
|
55103 | 297 |
val $$ = Symbol_Pos.$$; |
55107 | 298 |
val ~$$ = Symbol_Pos.~$$; |
36957 | 299 |
val $$$ = Symbol_Pos.$$$; |
300 |
val ~$$$ = Symbol_Pos.~$$$; |
|
301 |
end; |
|
67426 | 302 |
|
303 |
type 'a scanner = 'a Symbol_Pos.scanner; |