author | wenzelm |
Tue, 11 Nov 2014 18:16:25 +0100 | |
changeset 58978 | e42da880c61e |
parent 58864 | 505a8150368a |
child 59064 | a8bcb5a446c8 |
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 |
|
10 |
val symbol: T -> Symbol.symbol |
|
55103 | 11 |
val $$ : Symbol.symbol -> T list -> T * T list |
55107 | 12 |
val ~$$ : Symbol.symbol -> T list -> T * T list |
27763 | 13 |
val $$$ : Symbol.symbol -> T list -> T list * T list |
14 |
val ~$$$ : Symbol.symbol -> T list -> T list * T list |
|
27797 | 15 |
val content: T list -> string |
55033 | 16 |
val range: T list -> Position.range |
27763 | 17 |
val is_eof: T -> bool |
18 |
val stopper: T Scan.stopper |
|
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
|
19 |
val !!! : Scan.message -> (T list -> 'a) -> T list -> 'a |
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
20 |
val scan_pos: T list -> Position.T * T list |
48764 | 21 |
val scan_string_q: string -> T list -> (Position.T * (T list * Position.T)) * T list |
22 |
val scan_string_qq: string -> T list -> (Position.T * (T list * Position.T)) * T list |
|
23 |
val scan_string_bq: string -> T list -> (Position.T * (T list * Position.T)) * T list |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
24 |
val recover_string_q: T list -> T list * T list |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
25 |
val recover_string_qq: T list -> T list * T list |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
26 |
val recover_string_bq: T list -> T list * T list |
43773 | 27 |
val quote_string_q: string -> string |
28 |
val quote_string_qq: string -> string |
|
29 |
val quote_string_bq: string -> string |
|
55105 | 30 |
val scan_cartouche: string -> T list -> T list * T list |
55033 | 31 |
val recover_cartouche: T list -> T list * T list |
32 |
val cartouche_content: T list -> T list |
|
55105 | 33 |
val scan_comment: string -> T list -> T list * T list |
34 |
val scan_comment_body: string -> T list -> T list * T list |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
35 |
val recover_comment: T list -> T list * T list |
27763 | 36 |
val source: Position.T -> (Symbol.symbol, 'a) Source.source -> |
37 |
(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
|
38 |
type text = string |
27797 | 39 |
val implode: T list -> text |
40 |
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
|
41 |
val explode: text * Position.T -> T list |
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58864
diff
changeset
|
42 |
type source = {delimited: bool, text: text, range: Position.range} |
58047
9f3826352b52
tuned signature -- prefer quasi-abstract Symbol_Pos.source;
wenzelm
parents:
55829
diff
changeset
|
43 |
val source_explode: source -> T list |
55829 | 44 |
val source_content: source -> string * Position.T |
50239 | 45 |
val scan_ident: T list -> T list * T list |
46 |
val is_identifier: string -> bool |
|
27763 | 47 |
end; |
48 |
||
30573 | 49 |
structure Symbol_Pos: SYMBOL_POS = |
27763 | 50 |
struct |
51 |
||
52 |
(* type T *) |
|
53 |
||
54 |
type T = Symbol.symbol * Position.T; |
|
55 |
||
56 |
fun symbol ((s, _): T) = s; |
|
27852 | 57 |
|
27797 | 58 |
val content = implode o map symbol; |
27763 | 59 |
|
55033 | 60 |
fun range (syms as (_, pos) :: _) = |
61 |
let val pos' = List.last syms |-> Position.advance |
|
62 |
in Position.range pos pos' end |
|
63 |
| range [] = Position.no_range; |
|
64 |
||
27763 | 65 |
|
66 |
(* stopper *) |
|
67 |
||
68 |
fun mk_eof pos = (Symbol.eof, pos); |
|
69 |
val eof = mk_eof Position.none; |
|
70 |
||
71 |
val is_eof = Symbol.is_eof o symbol; |
|
72 |
||
73 |
val stopper = |
|
74 |
Scan.stopper (fn [] => eof | inp => mk_eof (List.last inp |-> Position.advance)) is_eof; |
|
75 |
||
76 |
||
77 |
(* basic scanners *) |
|
78 |
||
79 |
fun !!! text scan = |
|
80 |
let |
|
48911
5debc3e4fa81
tuned messages: end-of-input rarely means physical end-of-file from the past;
wenzelm
parents:
48770
diff
changeset
|
81 |
fun get_pos [] = " (end-of-input)" |
48992 | 82 |
| get_pos ((_, pos) :: _) = Position.here pos; |
27763 | 83 |
|
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
|
84 |
fun err (syms, msg) = fn () => |
48770 | 85 |
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
|
86 |
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
|
87 |
(case msg of NONE => "" | SOME m => "\n" ^ m ()); |
27763 | 88 |
in Scan.!! err scan end; |
89 |
||
55033 | 90 |
fun $$ s = Scan.one (fn x => symbol x = s); |
55107 | 91 |
fun ~$$ s = Scan.one (fn x => symbol x <> s); |
92 |
||
27763 | 93 |
fun $$$ s = Scan.one (fn x => symbol x = s) >> single; |
94 |
fun ~$$$ s = Scan.one (fn x => symbol x <> s) >> single; |
|
95 |
||
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
96 |
val scan_pos = Scan.ahead (Scan.one (K true)) >> (fn (_, pos): T => pos); |
27763 | 97 |
|
98 |
||
43773 | 99 |
(* 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
|
100 |
|
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
101 |
local |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
102 |
|
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
103 |
val char_code = |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
(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
|
108 |
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
|
109 |
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
|
110 |
|
48764 | 111 |
fun scan_str q err_prefix = |
112 |
$$$ "\\" |-- !!! (fn () => err_prefix ^ "bad escape character in string") |
|
113 |
($$$ q || $$$ "\\" || char_code) || |
|
58854 | 114 |
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
|
115 |
|
48764 | 116 |
fun scan_strs q err_prefix = |
55103 | 117 |
Scan.ahead ($$ q) |-- |
118 |
!!! (fn () => err_prefix ^ "unclosed string literal") |
|
119 |
((scan_pos --| $$$ q) -- |
|
58850 | 120 |
((Scan.repeat (scan_str q err_prefix) >> flat) -- ($$$ 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
|
121 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
122 |
fun recover_strs q = |
48764 | 123 |
$$$ q @@@ (Scan.repeat (Scan.permissive (scan_str q "")) >> flat); |
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
124 |
|
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
125 |
in |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
126 |
|
42503 | 127 |
val scan_string_q = scan_strs "'"; |
128 |
val scan_string_qq = scan_strs "\""; |
|
129 |
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
|
130 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
|
30586
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
135 |
end; |
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
136 |
|
9674f64a0702
moved basic change_prompt, scan_string, scan_alt_string, scan_quoted to symbol_pos.ML;
wenzelm
parents:
30573
diff
changeset
|
137 |
|
43773 | 138 |
(* quote string literals *) |
139 |
||
140 |
local |
|
141 |
||
142 |
fun char_code i = |
|
143 |
(if i < 10 then "00" else if i < 100 then "0" else "") ^ string_of_int i; |
|
144 |
||
145 |
fun quote_str q s = |
|
146 |
if Symbol.is_ascii_control s then "\\" ^ char_code (ord s) |
|
147 |
else if s = q orelse s = "\\" then "\\" ^ s |
|
148 |
else s; |
|
149 |
||
150 |
fun quote_string q = enclose q q o implode o map (quote_str q) o Symbol.explode; |
|
151 |
||
152 |
in |
|
153 |
||
154 |
val quote_string_q = quote_string "'"; |
|
155 |
val quote_string_qq = quote_string "\""; |
|
156 |
val quote_string_bq = quote_string "`"; |
|
157 |
||
158 |
end; |
|
159 |
||
160 |
||
55033 | 161 |
(* nested text cartouches *) |
162 |
||
55104
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
163 |
val scan_cartouche_depth = |
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
164 |
Scan.repeat1 (Scan.depend (fn (d: int) => |
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
165 |
$$ "\\<open>" >> pair (d + 1) || |
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
166 |
(if d > 0 then |
58854 | 167 |
Scan.one (fn (s, _) => s <> "\\<close>" andalso Symbol.not_eof s) >> pair d || |
55104
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
168 |
$$ "\\<close>" >> pair (d - 1) |
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
169 |
else Scan.fail))); |
55033 | 170 |
|
55105 | 171 |
fun scan_cartouche err_prefix = |
55104
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
172 |
Scan.ahead ($$ "\\<open>") |-- |
55105 | 173 |
!!! (fn () => err_prefix ^ "unclosed text cartouche") |
58850 | 174 |
(Scan.provide (fn d => d = 0) 0 scan_cartouche_depth); |
55033 | 175 |
|
55104
8284c0d5bf52
clarified scan_cartouche_depth, according to Scala version;
wenzelm
parents:
55103
diff
changeset
|
176 |
val recover_cartouche = Scan.pass 0 scan_cartouche_depth; |
55033 | 177 |
|
178 |
fun cartouche_content syms = |
|
179 |
let |
|
180 |
fun err () = |
|
55709
4e5a83a46ded
clarified Token.range_of in accordance to Symbol_Pos.range;
wenzelm
parents:
55107
diff
changeset
|
181 |
error ("Malformed text cartouche: " |
4e5a83a46ded
clarified Token.range_of in accordance to Symbol_Pos.range;
wenzelm
parents:
55107
diff
changeset
|
182 |
^ quote (content syms) ^ Position.here (#1 (range syms))); |
55033 | 183 |
in |
184 |
(case syms of |
|
185 |
("\\<open>", _) :: rest => |
|
186 |
(case rev rest of |
|
187 |
("\\<close>", _) :: rrest => rev rrest |
|
188 |
| _ => err ()) |
|
189 |
| _ => err ()) |
|
190 |
end; |
|
191 |
||
192 |
||
27763 | 193 |
(* ML-style comments *) |
194 |
||
195 |
local |
|
196 |
||
197 |
val scan_cmt = |
|
198 |
Scan.depend (fn (d: int) => $$$ "(" @@@ $$$ "*" >> pair (d + 1)) || |
|
199 |
Scan.depend (fn 0 => Scan.fail | d => $$$ "*" @@@ $$$ ")" >> pair (d - 1)) || |
|
200 |
Scan.lift ($$$ "*" --| Scan.ahead (~$$$ ")")) || |
|
58854 | 201 |
Scan.lift (Scan.one (fn (s, _) => s <> "*" andalso Symbol.not_eof s)) >> single; |
27763 | 202 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
203 |
val scan_cmts = Scan.pass 0 (Scan.repeat scan_cmt >> flat); |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
204 |
|
27763 | 205 |
in |
206 |
||
55105 | 207 |
fun scan_comment err_prefix = |
55106 | 208 |
Scan.ahead ($$ "(" -- $$ "*") |-- |
209 |
!!! (fn () => err_prefix ^ "unclosed comment") |
|
58850 | 210 |
($$$ "(" @@@ $$$ "*" @@@ scan_cmts @@@ $$$ "*" @@@ $$$ ")"); |
27763 | 211 |
|
55105 | 212 |
fun scan_comment_body err_prefix = |
55106 | 213 |
Scan.ahead ($$ "(" -- $$ "*") |-- |
214 |
!!! (fn () => err_prefix ^ "unclosed comment") |
|
58850 | 215 |
($$ "(" |-- $$ "*" |-- scan_cmts --| $$ "*" --| $$ ")"); |
27763 | 216 |
|
48743
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
217 |
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
|
218 |
$$$ "(" @@@ $$$ "*" @@@ scan_cmts; |
a72f8ffecf31
refined recovery of scan errors: longest prefix of delimited token after failure, otherwise just one symbol;
wenzelm
parents:
43947
diff
changeset
|
219 |
|
27763 | 220 |
end; |
221 |
||
222 |
||
223 |
(* source *) |
|
224 |
||
225 |
fun source pos = |
|
226 |
Source.source' pos Symbol.stopper (Scan.bulk (Scan.depend (fn pos => |
|
58864 | 227 |
Scan.one Symbol.not_eof >> (fn s => (Position.advance s pos, (s, pos)))))); |
27763 | 228 |
|
229 |
||
230 |
(* compact representation -- with Symbol.DEL padding *) |
|
231 |
||
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
232 |
type text = string; |
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
233 |
|
27763 | 234 |
fun pad [] = [] |
235 |
| pad [(s, _)] = [s] |
|
32784 | 236 |
| pad ((s1, pos1) :: (rest as (_, pos2) :: _)) = |
27763 | 237 |
let |
238 |
val end_pos1 = Position.advance s1 pos1; |
|
27797 | 239 |
val d = Int.max (0, Position.distance_of end_pos1 pos2); |
27763 | 240 |
in s1 :: replicate d Symbol.DEL @ pad rest end; |
241 |
||
27797 | 242 |
val implode = implode o pad; |
27763 | 243 |
|
27797 | 244 |
fun implode_range pos1 pos2 syms = |
245 |
let val syms' = (("", pos1) :: syms @ [("", pos2)]) |
|
246 |
in (implode syms', range syms') end; |
|
27778
3ec7a4d9ef18
renamed SymbolPos.scan_position to SymbolPos.scan_pos;
wenzelm
parents:
27763
diff
changeset
|
247 |
|
27763 | 248 |
fun explode (str, pos) = |
41416 | 249 |
let |
250 |
val (res, _) = |
|
251 |
fold (fn s => fn (res, p) => ((s, p) :: res, Position.advance s p)) |
|
252 |
(Symbol.explode str) ([], Position.reset_range pos); |
|
253 |
in fold (fn (s, p) => if s = Symbol.DEL then I else cons (s, p)) res [] end; |
|
27763 | 254 |
|
50239 | 255 |
|
55829 | 256 |
(* full source information *) |
257 |
||
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58864
diff
changeset
|
258 |
type source = {delimited: bool, text: text, range: Position.range}; |
55829 | 259 |
|
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58864
diff
changeset
|
260 |
fun source_explode {delimited = _, text, range = (pos, _)} = explode (text, pos); |
58047
9f3826352b52
tuned signature -- prefer quasi-abstract Symbol_Pos.source;
wenzelm
parents:
55829
diff
changeset
|
261 |
|
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58864
diff
changeset
|
262 |
fun source_content {delimited = _, text, range = (pos, _)} = |
55829 | 263 |
let val syms = explode (text, pos) in (content syms, pos) end; |
264 |
||
265 |
||
50239 | 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 |
|
54732 | 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 |
|
52920
4539e4a06339
more strict identifier syntax: disallow superscripts, which tend to be used in notation such as \<^sup>\<omega>;
wenzelm
parents:
52616
diff
changeset
|
277 |
val scan_ident = letter ::: (Scan.repeat (letdigs1 || sub ::: letdigs1) >> flat); |
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 |
3d6a4135a54f
eliminated redundant is_ident -- more official is_identifier;
wenzelm
parents:
50253
diff
changeset
|
283 |
(case try (Scan.finite stopper scan_ident) (explode (s, Position.none)) of |
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 |
|
27763 | 287 |
end; |
288 |
||
36957 | 289 |
structure Basic_Symbol_Pos = (*not open by default*) |
290 |
struct |
|
55103 | 291 |
val $$ = Symbol_Pos.$$; |
55107 | 292 |
val ~$$ = Symbol_Pos.~$$; |
36957 | 293 |
val $$$ = Symbol_Pos.$$$; |
294 |
val ~$$$ = Symbol_Pos.~$$$; |
|
295 |
end; |
|
27763 | 296 |