| author | steckerm | 
| Sat, 20 Sep 2014 10:42:08 +0200 | |
| changeset 58401 | b8ca69d9897b | 
| parent 56165 | dd89ce51d2c8 | 
| child 58465 | bd06c6479748 | 
| permissions | -rw-r--r-- | 
| 55030 | 1 | (* Title: Pure/Tools/rail.ML | 
| 42504 | 2 | Author: Michael Kerscher, TU München | 
| 3 | Author: Makarius | |
| 4 | ||
| 5 | Railroad diagrams in LaTeX. | |
| 6 | *) | |
| 7 | ||
| 8 | structure Rail: sig end = | |
| 9 | struct | |
| 10 | ||
| 11 | (** lexical syntax **) | |
| 12 | ||
| 56165 | 13 | (* singleton keywords *) | 
| 14 | ||
| 15 | val keywords = | |
| 16 | Symtab.make [ | |
| 17 |     ("|", Markup.keyword3),
 | |
| 18 |     ("*", Markup.keyword3),
 | |
| 19 |     ("+", Markup.keyword3),
 | |
| 20 |     ("?", Markup.keyword3),
 | |
| 21 |     ("(", Markup.empty),
 | |
| 22 |     (")", Markup.empty),
 | |
| 23 |     ("\<newline>", Markup.keyword2),
 | |
| 24 |     (";", Markup.keyword2),
 | |
| 25 |     (":", Markup.keyword2),
 | |
| 26 |     ("@", Markup.keyword1)];
 | |
| 27 | ||
| 28 | ||
| 42504 | 29 | (* datatype token *) | 
| 30 | ||
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 31 | datatype kind = | 
| 55526 | 32 | Keyword | Ident | String | Antiq of Antiquote.antiq | EOF; | 
| 42504 | 33 | |
| 34 | datatype token = Token of Position.range * (kind * string); | |
| 35 | ||
| 36 | fun pos_of (Token ((pos, _), _)) = pos; | |
| 37 | fun end_pos_of (Token ((_, pos), _)) = pos; | |
| 38 | ||
| 39 | fun kind_of (Token (_, (k, _))) = k; | |
| 40 | fun content_of (Token (_, (_, x))) = x; | |
| 41 | ||
| 42 | ||
| 43 | (* diagnostics *) | |
| 44 | ||
| 45 | val print_kind = | |
| 46 | fn Keyword => "rail keyword" | |
| 47 | | Ident => "identifier" | |
| 48 | | String => "single-quoted string" | |
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 49 | | Antiq _ => "antiquotation" | 
| 48911 
5debc3e4fa81
tuned messages: end-of-input rarely means physical end-of-file from the past;
 wenzelm parents: 
48764diff
changeset | 50 | | EOF => "end-of-input"; | 
| 42504 | 51 | |
| 52 | fun print (Token ((pos, _), (k, x))) = | |
| 53 | (if k = EOF then print_kind k else print_kind k ^ " " ^ quote x) ^ | |
| 48992 | 54 | Position.here pos; | 
| 42504 | 55 | |
| 56 | fun print_keyword x = print_kind Keyword ^ " " ^ quote x; | |
| 57 | ||
| 55613 | 58 | fun reports_of_token (Token ((pos, _), (String, _))) = [(pos, Markup.inner_string)] | 
| 56163 | 59 | | reports_of_token (Token ((pos, _), (Keyword, x))) = | 
| 56165 | 60 | map (pair pos) (the_list (Symtab.lookup keywords x) @ Completion.suppress_abbrevs x) | 
| 55613 | 61 | | reports_of_token (Token (_, (Antiq antiq, _))) = Antiquote.antiq_reports antiq | 
| 62 | | reports_of_token _ = []; | |
| 63 | ||
| 42504 | 64 | |
| 65 | (* stopper *) | |
| 66 | ||
| 67 | fun mk_eof pos = Token ((pos, Position.none), (EOF, "")); | |
| 68 | val eof = mk_eof Position.none; | |
| 69 | ||
| 70 | fun is_eof (Token (_, (EOF, _))) = true | |
| 71 | | is_eof _ = false; | |
| 72 | ||
| 73 | val stopper = | |
| 74 | Scan.stopper (fn [] => eof | toks => mk_eof (end_pos_of (List.last toks))) is_eof; | |
| 75 | ||
| 76 | ||
| 77 | (* tokenize *) | |
| 78 | ||
| 79 | local | |
| 80 | ||
| 81 | fun token k ss = [Token (Symbol_Pos.range ss, (k, Symbol_Pos.content ss))]; | |
| 82 | ||
| 83 | val scan_space = Scan.many1 (Symbol.is_blank o Symbol_Pos.symbol); | |
| 84 | ||
| 85 | val scan_keyword = | |
| 56165 | 86 | Scan.one (Symtab.defined keywords o Symbol_Pos.symbol); | 
| 42504 | 87 | |
| 48764 | 88 | val err_prefix = "Rail lexical error: "; | 
| 89 | ||
| 42504 | 90 | val scan_token = | 
| 91 | scan_space >> K [] || | |
| 42516 | 92 | Antiquote.scan_antiq >> (fn antiq as (ss, _) => token (Antiq antiq) ss) || | 
| 42504 | 93 | scan_keyword >> (token Keyword o single) || | 
| 94 | Lexicon.scan_id >> token Ident || | |
| 55613 | 95 | Symbol_Pos.scan_string_q err_prefix >> (fn (pos1, (ss, pos2)) => | 
| 96 | [Token (Position.range pos1 pos2, (String, Symbol_Pos.content ss))]); | |
| 42504 | 97 | |
| 42506 
876887b07e8d
more robust error handling (NB: Source.source requires total scanner or recover);
 wenzelm parents: 
42504diff
changeset | 98 | val scan = | 
| 
876887b07e8d
more robust error handling (NB: Source.source requires total scanner or recover);
 wenzelm parents: 
42504diff
changeset | 99 | (Scan.repeat scan_token >> flat) --| | 
| 48764 | 100 | Symbol_Pos.!!! (fn () => err_prefix ^ "bad input") | 
| 42506 
876887b07e8d
more robust error handling (NB: Source.source requires total scanner or recover);
 wenzelm parents: 
42504diff
changeset | 101 | (Scan.ahead (Scan.one Symbol_Pos.is_eof)); | 
| 
876887b07e8d
more robust error handling (NB: Source.source requires total scanner or recover);
 wenzelm parents: 
42504diff
changeset | 102 | |
| 42504 | 103 | in | 
| 104 | ||
| 55613 | 105 | val tokenize = #1 o Scan.error (Scan.finite Symbol_Pos.stopper scan); | 
| 42504 | 106 | |
| 107 | end; | |
| 108 | ||
| 109 | ||
| 110 | ||
| 111 | (** parsing **) | |
| 112 | ||
| 113 | fun !!! scan = | |
| 114 | let | |
| 115 | val prefix = "Rail syntax error"; | |
| 116 | ||
| 48911 
5debc3e4fa81
tuned messages: end-of-input rarely means physical end-of-file from the past;
 wenzelm parents: 
48764diff
changeset | 117 | fun get_pos [] = " (end-of-input)" | 
| 48992 | 118 | | get_pos (tok :: _) = Position.here (pos_of tok); | 
| 42504 | 119 | |
| 43947 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 120 | fun err (toks, NONE) = (fn () => prefix ^ get_pos toks) | 
| 42504 | 121 | | err (toks, SOME msg) = | 
| 43947 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 122 | (fn () => | 
| 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 123 | let val s = msg () in | 
| 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 124 | if String.isPrefix prefix s then s | 
| 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 125 | else prefix ^ get_pos toks ^ ": " ^ s | 
| 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 126 | end); | 
| 42504 | 127 | in Scan.!! err scan end; | 
| 128 | ||
| 129 | fun $$$ x = | |
| 130 | Scan.one (fn tok => kind_of tok = Keyword andalso content_of tok = x) || | |
| 131 | Scan.fail_with | |
| 48911 
5debc3e4fa81
tuned messages: end-of-input rarely means physical end-of-file from the past;
 wenzelm parents: 
48764diff
changeset | 132 | (fn [] => (fn () => print_keyword x ^ " expected,\nbut end-of-input was found") | 
| 43947 
9b00f09f7721
defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
 wenzelm parents: 
43564diff
changeset | 133 | | tok :: _ => (fn () => print_keyword x ^ " expected,\nbut " ^ print tok ^ " was found")); | 
| 42504 | 134 | |
| 135 | fun enum1 sep scan = scan ::: Scan.repeat ($$$ sep |-- !!! scan); | |
| 136 | fun enum sep scan = enum1 sep scan || Scan.succeed []; | |
| 137 | ||
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 138 | val ident = Scan.some (fn tok => if kind_of tok = Ident then SOME (content_of tok) else NONE); | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 139 | val string = Scan.some (fn tok => if kind_of tok = String then SOME (content_of tok) else NONE); | 
| 42504 | 140 | |
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 141 | val antiq = Scan.some (fn tok => (case kind_of tok of Antiq a => SOME a | _ => NONE)); | 
| 42504 | 142 | |
| 143 | ||
| 144 | ||
| 145 | (** rail expressions **) | |
| 146 | ||
| 147 | (* datatype *) | |
| 148 | ||
| 149 | datatype rails = | |
| 150 | Cat of int * rail list | |
| 151 | and rail = | |
| 152 | Bar of rails list | | |
| 153 | Plus of rails * rails | | |
| 154 | Newline of int | | |
| 155 | Nonterminal of string | | |
| 42516 | 156 | Terminal of bool * string | | 
| 55526 | 157 | Antiquote of bool * Antiquote.antiq; | 
| 42504 | 158 | |
| 159 | fun reverse_cat (Cat (y, rails)) = Cat (y, rev (map reverse rails)) | |
| 160 | and reverse (Bar cats) = Bar (map reverse_cat cats) | |
| 161 | | reverse (Plus (cat1, cat2)) = Plus (reverse_cat cat1, reverse_cat cat2) | |
| 162 | | reverse x = x; | |
| 163 | ||
| 164 | fun cat rails = Cat (0, rails); | |
| 165 | ||
| 166 | val empty = cat []; | |
| 167 | fun is_empty (Cat (_, [])) = true | is_empty _ = false; | |
| 168 | ||
| 169 | fun is_newline (Newline _) = true | is_newline _ = false; | |
| 170 | ||
| 171 | fun bar [Cat (_, [rail])] = rail | |
| 172 | | bar cats = Bar cats; | |
| 173 | ||
| 174 | fun plus cat1 cat2 = Plus (cat1, reverse_cat cat2); | |
| 175 | ||
| 176 | fun star cat1 cat2 = | |
| 177 | if is_empty cat2 then plus empty cat1 | |
| 178 | else bar [empty, cat [plus cat1 cat2]]; | |
| 179 | ||
| 180 | fun maybe rail = bar [empty, cat [rail]]; | |
| 181 | ||
| 182 | ||
| 183 | (* read *) | |
| 184 | ||
| 185 | local | |
| 186 | ||
| 42516 | 187 | val at_mode = Scan.option ($$$ "@") >> (fn NONE => false | _ => true); | 
| 188 | ||
| 42504 | 189 | fun body x = (enum1 "|" body1 >> bar) x | 
| 190 | and body0 x = (enum "|" body1 >> bar) x | |
| 191 | and body1 x = | |
| 192 | (body2 :|-- (fn a => | |
| 193 | $$$ "*" |-- !!! body4e >> (cat o single o star a) || | |
| 194 | $$$ "+" |-- !!! body4e >> (cat o single o plus a) || | |
| 195 | Scan.succeed a)) x | |
| 196 | and body2 x = (Scan.repeat1 body3 >> cat) x | |
| 197 | and body3 x = (body4 :|-- (fn a => $$$ "?" >> K (maybe a) || Scan.succeed a)) x | |
| 198 | and body4 x = | |
| 199 |  ($$$ "(" |-- !!! (body0 --| $$$ ")") ||
 | |
| 55030 | 200 | $$$ "\<newline>" >> K (Newline 0) || | 
| 42504 | 201 | ident >> Nonterminal || | 
| 42516 | 202 | at_mode -- string >> Terminal || | 
| 203 | at_mode -- antiq >> Antiquote) x | |
| 42504 | 204 | and body4e x = (Scan.option body4 >> (cat o the_list)) x; | 
| 205 | ||
| 42516 | 206 | val rule_name = ident >> Antiquote.Text || antiq >> Antiquote.Antiq; | 
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 207 | val rule = rule_name -- ($$$ ":" |-- !!! body) || body >> pair (Antiquote.Text ""); | 
| 42504 | 208 | val rules = enum1 ";" (Scan.option rule) >> map_filter I; | 
| 209 | ||
| 210 | in | |
| 211 | ||
| 55828 
42ac3cfb89f6
clarified language markup: added "delimited" property;
 wenzelm parents: 
55613diff
changeset | 212 | fun read ctxt (source: Symbol_Pos.source) = | 
| 55613 | 213 | let | 
| 55828 
42ac3cfb89f6
clarified language markup: added "delimited" property;
 wenzelm parents: 
55613diff
changeset | 214 |     val {text, pos, ...} = source;
 | 
| 55613 | 215 | val _ = Context_Position.report ctxt pos Markup.language_rail; | 
| 55828 
42ac3cfb89f6
clarified language markup: added "delimited" property;
 wenzelm parents: 
55613diff
changeset | 216 | val toks = tokenize (Symbol_Pos.explode (text, pos)); | 
| 55613 | 217 | val _ = Context_Position.reports ctxt (maps reports_of_token toks); | 
| 218 | in #1 (Scan.error (Scan.finite stopper (rules --| !!! (Scan.ahead (Scan.one is_eof)))) toks) end; | |
| 42504 | 219 | |
| 220 | end; | |
| 221 | ||
| 222 | ||
| 223 | (* latex output *) | |
| 224 | ||
| 225 | local | |
| 226 | ||
| 227 | fun vertical_range_cat (Cat (_, rails)) y = | |
| 228 | let val (rails', (_, y')) = | |
| 229 | fold_map (fn rail => fn (y0, y') => | |
| 230 | if is_newline rail then (Newline (y' + 1), (y' + 1, y' + 2)) | |
| 231 | else | |
| 232 | let val (rail', y0') = vertical_range rail y0; | |
| 233 | in (rail', (y0, Int.max (y0', y'))) end) rails (y, y + 1) | |
| 234 | in (Cat (y, rails'), y') end | |
| 235 | ||
| 236 | and vertical_range (Bar cats) y = | |
| 237 | let val (cats', y') = fold_map vertical_range_cat cats y | |
| 238 | in (Bar cats', Int.max (y + 1, y')) end | |
| 239 | | vertical_range (Plus (cat1, cat2)) y = | |
| 240 | let val ([cat1', cat2'], y') = fold_map vertical_range_cat [cat1, cat2] y; | |
| 241 | in (Plus (cat1', cat2'), Int.max (y + 1, y')) end | |
| 242 | | vertical_range (Newline _) y = (Newline (y + 2), y + 3) | |
| 243 | | vertical_range atom y = (atom, y + 1); | |
| 244 | ||
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 245 | fun output_rules state rules = | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 246 | let | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 247 | val output_antiq = Thy_Output.eval_antiq (#1 (Keyword.get_lexicons ())) state; | 
| 42516 | 248 | fun output_text b s = | 
| 249 | Output.output s | |
| 250 |       |> b ? enclose "\\isakeyword{" "}"
 | |
| 251 |       |> enclose "\\isa{" "}";
 | |
| 42504 | 252 | |
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 253 | fun output_cat c (Cat (_, rails)) = outputs c rails | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 254 | and outputs c [rail] = output c rail | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 255 | | outputs _ rails = implode (map (output "") rails) | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 256 | and output _ (Bar []) = "" | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 257 | | output c (Bar [cat]) = output_cat c cat | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 258 | | output _ (Bar (cat :: cats)) = | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 259 | "\\rail@bar\n" ^ output_cat "" cat ^ | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 260 | implode (map (fn Cat (y, rails) => | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 261 |               "\\rail@nextbar{" ^ string_of_int y ^ "}\n" ^ outputs "" rails) cats) ^
 | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 262 | "\\rail@endbar\n" | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 263 | | output c (Plus (cat, Cat (y, rails))) = | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 264 | "\\rail@plus\n" ^ output_cat c cat ^ | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 265 |           "\\rail@nextplus{" ^ string_of_int y ^ "}\n" ^ outputs "c" rails ^
 | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 266 | "\\rail@endplus\n" | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 267 |       | output _ (Newline y) = "\\rail@cr{" ^ string_of_int y ^ "}\n"
 | 
| 42516 | 268 |       | output c (Nonterminal s) = "\\rail@" ^ c ^ "nont{" ^ output_text false s ^ "}[]\n"
 | 
| 269 |       | output c (Terminal (b, s)) = "\\rail@" ^ c ^ "term{" ^ output_text b s ^ "}[]\n"
 | |
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 270 | | output c (Antiquote (b, a)) = | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 271 |           "\\rail@" ^ c ^ (if b then "term{" else "nont{") ^ output_antiq a ^ "}[]\n";
 | 
| 42504 | 272 | |
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 273 | fun output_rule (name, rail) = | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 274 | let | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 275 | val (rail', y') = vertical_range rail 0; | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 276 | val out_name = | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 277 | (case name of | 
| 42661 
824d3f1d8de6
proper treatment of empty name -- avoid excessive vertical space;
 wenzelm parents: 
42657diff
changeset | 278 | Antiquote.Text "" => "" | 
| 
824d3f1d8de6
proper treatment of empty name -- avoid excessive vertical space;
 wenzelm parents: 
42657diff
changeset | 279 | | Antiquote.Text s => output_text false s | 
| 42508 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 280 | | Antiquote.Antiq a => output_antiq a); | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 281 | in | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 282 |         "\\rail@begin{" ^ string_of_int y' ^ "}{" ^ out_name ^ "}\n" ^
 | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 283 | output "" rail' ^ | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 284 | "\\rail@end\n" | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 285 | end; | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 286 | in | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 287 |     "\\begin{railoutput}\n" ^
 | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 288 | implode (map output_rule rules) ^ | 
| 
e21362bf1d93
allow nested @{antiq} (nonterminal) and @@{antiq} terminal;
 wenzelm parents: 
42507diff
changeset | 289 |     "\\end{railoutput}\n"
 | 
| 42504 | 290 | end; | 
| 291 | ||
| 292 | in | |
| 293 | ||
| 53171 | 294 | val _ = Theory.setup | 
| 55030 | 295 |   (Thy_Output.antiquotation @{binding rail}
 | 
| 55112 
b1a5d603fd12
prefer rail cartouche -- avoid back-slashed quotes;
 wenzelm parents: 
55030diff
changeset | 296 | (Scan.lift (Parse.source_position (Parse.string || Parse.cartouche))) | 
| 55613 | 297 |     (fn {state, context, ...} => output_rules state o read context));
 | 
| 42504 | 298 | |
| 299 | end; | |
| 300 | ||
| 301 | end; | |
| 302 |