author | wenzelm |
Sun, 30 Aug 2015 21:26:42 +0200 | |
changeset 61057 | 5f6a1e31f3ad |
parent 59112 | e670969f34df |
child 61434 | 46d6586eb04c |
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 |
|
55612 | 11 |
val antiq_reports: antiq -> Position.report list |
12 |
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
|
13 |
'a antiquote list -> Position.report_text list |
55526 | 14 |
val scan_antiq: Symbol_Pos.T list -> antiq * Symbol_Pos.T list |
55512 | 15 |
val scan_antiquote: Symbol_Pos.T list -> Symbol_Pos.T list antiquote * Symbol_Pos.T list |
59065 | 16 |
val read: Input.source -> Symbol_Pos.T list antiquote list |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
17 |
end; |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
18 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
19 |
structure Antiquote: ANTIQUOTE = |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
20 |
struct |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
21 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
22 |
(* datatype antiquote *) |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
23 |
|
55526 | 24 |
type antiq = Symbol_Pos.T list * {start: Position.T, stop: Position.T, range: Position.range}; |
25 |
datatype 'a antiquote = Text of 'a | Antiq of antiq; |
|
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
26 |
|
27342 | 27 |
|
44736 | 28 |
(* reports *) |
30641
72980f8d7ee8
export report -- version that actually covers all cases;
wenzelm
parents:
30635
diff
changeset
|
29 |
|
55612 | 30 |
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
|
31 |
[(start, Markup.antiquote), (stop, Markup.antiquote), |
528de9a20054
more markup -- complete symbols within antiquotation, notably with broken arguments;
wenzelm
parents:
55612
diff
changeset
|
32 |
(pos, Markup.antiquoted), (pos, Markup.language_antiquotation)]; |
55526 | 33 |
|
55612 | 34 |
fun antiquote_reports text = |
35 |
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
|
36 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
37 |
|
30590
1d9c9fcf8513
parameterized datatype antiquote and read operation;
wenzelm
parents:
30589
diff
changeset
|
38 |
(* scan *) |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
39 |
|
30573 | 40 |
open Basic_Symbol_Pos; |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
41 |
|
22114 | 42 |
local |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
43 |
|
48764 | 44 |
val err_prefix = "Antiquotation lexical error: "; |
45 |
||
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
46 |
val scan_txt = |
55511
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
wenzelm
parents:
55107
diff
changeset
|
47 |
Scan.repeat1 ($$$ "@" --| Scan.ahead (~$$ "{") || |
58854 | 48 |
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
|
49 |
|
55512 | 50 |
val scan_antiq_body = |
48764 | 51 |
Scan.trace (Symbol_Pos.scan_string_qq err_prefix || Symbol_Pos.scan_string_bq err_prefix) >> #2 || |
55105 | 52 |
Scan.trace (Symbol_Pos.scan_cartouche err_prefix) >> #2 || |
58854 | 53 |
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
|
54 |
|
42508
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
wenzelm
parents:
42503
diff
changeset
|
55 |
in |
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
wenzelm
parents:
42503
diff
changeset
|
56 |
|
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
57 |
val scan_antiq = |
55526 | 58 |
Symbol_Pos.scan_pos -- ($$ "@" |-- $$ "{" |-- Symbol_Pos.scan_pos -- |
48764 | 59 |
Symbol_Pos.!!! (fn () => err_prefix ^ "missing closing brace") |
55526 | 60 |
(Scan.repeat scan_antiq_body -- Symbol_Pos.scan_pos -- ($$ "}" |-- Symbol_Pos.scan_pos))) |
61 |
>> (fn (pos1, (pos2, ((body, pos3), pos4))) => |
|
62 |
(flat body, |
|
63 |
{start = Position.set_range (pos1, pos2), |
|
64 |
stop = Position.set_range (pos3, pos4), |
|
65 |
range = Position.range pos1 pos4})); |
|
30590
1d9c9fcf8513
parameterized datatype antiquote and read operation;
wenzelm
parents:
30589
diff
changeset
|
66 |
|
55512 | 67 |
val scan_antiquote = scan_antiq >> Antiq || scan_txt >> Text; |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
68 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
69 |
end; |
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
70 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
71 |
|
27767 | 72 |
(* read *) |
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
73 |
|
59065 | 74 |
fun read source = |
75 |
(case Scan.read Symbol_Pos.stopper (Scan.repeat scan_antiquote) (Input.source_explode source) of |
|
55612 | 76 |
SOME xs => (Position.reports_text (antiquote_reports (K []) xs); xs) |
59065 | 77 |
| NONE => |
78 |
error ("Malformed quotation/antiquotation source" ^ Position.here (Input.pos_of source))); |
|
9138
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
79 |
|
6a4fae41a75f
Text with antiquotations of inner items (terms, types etc.).
wenzelm
parents:
diff
changeset
|
80 |
end; |