author | wenzelm |
Fri, 31 Oct 2014 22:02:49 +0100 | |
changeset 58854 | b979c781c2db |
parent 55653 | 528de9a20054 |
child 59065 | 8ce02aafc363 |
permissions | -rw-r--r-- |
30587
ad19c99529eb
moved Isar/antiquote.ML to General/antiquote.ML, which is loaded early;
wenzelm
parents:
30573
diff
changeset
|
1 |
(* Title: Pure/General/antiquote.ML |
55511
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
wenzelm
parents:
55107
diff
changeset
|
2 |
Author: Makarius |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
3 |
|
55511
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
wenzelm
parents:
55107
diff
changeset
|
4 |
Antiquotations within plain text. |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
5 |
*) |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
6 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
7 |
signature ANTIQUOTE = |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
8 |
sig |
55526 | 9 |
type antiq = Symbol_Pos.T list * {start: Position.T, stop: Position.T, range: Position.range} |
10 |
datatype 'a antiquote = Text of 'a | Antiq of antiq |
|
30635
a7d175c48228
replaced Antiquote.is_antiq by Antiquote.is_text;
wenzelm
parents:
30613
diff
changeset
|
11 |
val is_text: 'a antiquote -> bool |
55612 | 12 |
val antiq_reports: antiq -> Position.report list |
13 |
val antiquote_reports: ('a -> Position.report_text list) -> |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48764
diff
changeset
|
14 |
'a antiquote list -> Position.report_text list |
55526 | 15 |
val scan_antiq: Symbol_Pos.T list -> antiq * Symbol_Pos.T list |
55512 | 16 |
val scan_antiquote: Symbol_Pos.T list -> Symbol_Pos.T list antiquote * Symbol_Pos.T list |
30641
72980f8d7ee8
export report -- version that actually covers all cases;
wenzelm
parents:
30635
diff
changeset
|
17 |
val read: Symbol_Pos.T list * Position.T -> Symbol_Pos.T list antiquote list |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
18 |
end; |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
19 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
20 |
structure Antiquote: ANTIQUOTE = |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
21 |
struct |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
22 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
23 |
(* datatype antiquote *) |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
24 |
|
55526 | 25 |
type antiq = Symbol_Pos.T list * {start: Position.T, stop: Position.T, range: Position.range}; |
26 |
datatype 'a antiquote = Text of 'a | Antiq of antiq; |
|
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
27 |
|
30635
a7d175c48228
replaced Antiquote.is_antiq by Antiquote.is_text;
wenzelm
parents:
30613
diff
changeset
|
28 |
fun is_text (Text _) = true |
a7d175c48228
replaced Antiquote.is_antiq by Antiquote.is_text;
wenzelm
parents:
30613
diff
changeset
|
29 |
| is_text _ = false; |
27342 | 30 |
|
31 |
||
44736 | 32 |
(* reports *) |
30641
72980f8d7ee8
export report -- version that actually covers all cases;
wenzelm
parents:
30635
diff
changeset
|
33 |
|
55612 | 34 |
fun antiq_reports ((_, {start, stop, range = (pos, _)}): antiq) = |
55653
528de9a20054
more markup -- complete symbols within antiquotation, notably with broken arguments;
wenzelm
parents:
55612
diff
changeset
|
35 |
[(start, Markup.antiquote), (stop, Markup.antiquote), |
528de9a20054
more markup -- complete symbols within antiquotation, notably with broken arguments;
wenzelm
parents:
55612
diff
changeset
|
36 |
(pos, Markup.antiquoted), (pos, Markup.language_antiquotation)]; |
55526 | 37 |
|
55612 | 38 |
fun antiquote_reports text = |
39 |
maps (fn Text x => text x | Antiq antiq => map (rpair "") (antiq_reports antiq)); |
|
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
40 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
41 |
|
30590
1d9c9fcf8513
parameterized datatype antiquote and read operation;
wenzelm
parents:
30589
diff
changeset
|
42 |
(* scan *) |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
43 |
|
30573 | 44 |
open Basic_Symbol_Pos; |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
45 |
|
22114 | 46 |
local |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
47 |
|
48764 | 48 |
val err_prefix = "Antiquotation lexical error: "; |
49 |
||
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
50 |
val scan_txt = |
55511
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
wenzelm
parents:
55107
diff
changeset
|
51 |
Scan.repeat1 ($$$ "@" --| Scan.ahead (~$$ "{") || |
58854 | 52 |
Scan.many1 (fn (s, _) => s <> "@" andalso Symbol.not_eof s)) >> flat; |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
53 |
|
55512 | 54 |
val scan_antiq_body = |
48764 | 55 |
Scan.trace (Symbol_Pos.scan_string_qq err_prefix || Symbol_Pos.scan_string_bq err_prefix) >> #2 || |
55105 | 56 |
Scan.trace (Symbol_Pos.scan_cartouche err_prefix) >> #2 || |
58854 | 57 |
Scan.one (fn (s, _) => s <> "}" andalso Symbol.not_eof s) >> single; |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
58 |
|
42508
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
wenzelm
parents:
42503
diff
changeset
|
59 |
in |
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
wenzelm
parents:
42503
diff
changeset
|
60 |
|
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
61 |
val scan_antiq = |
55526 | 62 |
Symbol_Pos.scan_pos -- ($$ "@" |-- $$ "{" |-- Symbol_Pos.scan_pos -- |
48764 | 63 |
Symbol_Pos.!!! (fn () => err_prefix ^ "missing closing brace") |
55526 | 64 |
(Scan.repeat scan_antiq_body -- Symbol_Pos.scan_pos -- ($$ "}" |-- Symbol_Pos.scan_pos))) |
65 |
>> (fn (pos1, (pos2, ((body, pos3), pos4))) => |
|
66 |
(flat body, |
|
67 |
{start = Position.set_range (pos1, pos2), |
|
68 |
stop = Position.set_range (pos3, pos4), |
|
69 |
range = Position.range pos1 pos4})); |
|
30590
1d9c9fcf8513
parameterized datatype antiquote and read operation;
wenzelm
parents:
30589
diff
changeset
|
70 |
|
55512 | 71 |
val scan_antiquote = scan_antiq >> Antiq || scan_txt >> Text; |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
72 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
73 |
end; |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
74 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
75 |
|
27767 | 76 |
(* read *) |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
77 |
|
30641
72980f8d7ee8
export report -- version that actually covers all cases;
wenzelm
parents:
30635
diff
changeset
|
78 |
fun read (syms, pos) = |
55512 | 79 |
(case Scan.read Symbol_Pos.stopper (Scan.repeat scan_antiquote) syms of |
55612 | 80 |
SOME xs => (Position.reports_text (antiquote_reports (K []) xs); xs) |
48992 | 81 |
| NONE => error ("Malformed quotation/antiquotation source" ^ Position.here pos)); |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
82 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
83 |
end; |