| author | wenzelm | 
| Sun, 02 Mar 2014 21:02:27 +0100 | |
| changeset 55841 | a232c0ff3c20 | 
| parent 55653 | 528de9a20054 | 
| child 58854 | b979c781c2db | 
| permissions | -rw-r--r-- | 
| 30587 
ad19c99529eb
moved Isar/antiquote.ML to General/antiquote.ML, which is loaded early;
 wenzelm parents: 
30573diff
changeset | 1 | (* Title: Pure/General/antiquote.ML | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: 
55107diff
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: 
55107diff
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: 
30613diff
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: 
48764diff
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: 
30635diff
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: 
30613diff
changeset | 28 | fun is_text (Text _) = true | 
| 
a7d175c48228
replaced Antiquote.is_antiq by Antiquote.is_text;
 wenzelm parents: 
30613diff
changeset | 29 | | is_text _ = false; | 
| 27342 | 30 | |
| 31 | ||
| 44736 | 32 | (* reports *) | 
| 30641 
72980f8d7ee8
export report -- version that actually covers all cases;
 wenzelm parents: 
30635diff
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: 
55612diff
changeset | 35 | [(start, Markup.antiquote), (stop, Markup.antiquote), | 
| 
528de9a20054
more markup -- complete symbols within antiquotation, notably with broken arguments;
 wenzelm parents: 
55612diff
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: 
30589diff
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: 
55107diff
changeset | 51 |   Scan.repeat1 ($$$ "@" --| Scan.ahead (~$$ "{") ||
 | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: 
55107diff
changeset | 52 | Scan.many1 (fn (s, _) => s <> "@" andalso Symbol.is_regular 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 || | 
| 27767 | 57 | Scan.one (fn (s, _) => s <> "}" andalso Symbol.is_regular 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: 
42503diff
changeset | 59 | in | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42503diff
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: 
30589diff
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: 
30635diff
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; |