src/Pure/General/antiquote.ML
changeset 55511 984e210d412e
parent 55107 1a29ea173bf9
child 55512 75c68e05f9ea
equal deleted inserted replaced
55510:1585a65aad64 55511:984e210d412e
     1 (*  Title:      Pure/General/antiquote.ML
     1 (*  Title:      Pure/General/antiquote.ML
     2     Author:     Markus Wenzel, TU Muenchen
     2     Author:     Makarius
     3 
     3 
     4 Text with antiquotations of inner items (types, terms, theorems etc.).
     4 Antiquotations within plain text.
     5 *)
     5 *)
     6 
     6 
     7 signature ANTIQUOTE =
     7 signature ANTIQUOTE =
     8 sig
     8 sig
     9   datatype 'a antiquote =
     9   datatype 'a antiquote =
    43 local
    43 local
    44 
    44 
    45 val err_prefix = "Antiquotation lexical error: ";
    45 val err_prefix = "Antiquotation lexical error: ";
    46 
    46 
    47 val scan_txt =
    47 val scan_txt =
    48   $$$ "@" --| Scan.ahead (~$$ "{") ||
    48   Scan.repeat1 ($$$ "@" --| Scan.ahead (~$$ "{") ||
    49   Scan.one (fn (s, _) => s <> "@" andalso Symbol.is_regular s) >> single;
    49     Scan.many1 (fn (s, _) => s <> "@" andalso Symbol.is_regular s)) >> flat;
    50 
    50 
    51 val scan_ant =
    51 val scan_ant =
    52   Scan.trace (Symbol_Pos.scan_string_qq err_prefix || Symbol_Pos.scan_string_bq err_prefix) >> #2 ||
    52   Scan.trace (Symbol_Pos.scan_string_qq err_prefix || Symbol_Pos.scan_string_bq err_prefix) >> #2 ||
    53   Scan.trace (Symbol_Pos.scan_cartouche err_prefix) >> #2 ||
    53   Scan.trace (Symbol_Pos.scan_cartouche err_prefix) >> #2 ||
    54   Scan.one (fn (s, _) => s <> "}" andalso Symbol.is_regular s) >> single;
    54   Scan.one (fn (s, _) => s <> "}" andalso Symbol.is_regular s) >> single;
    59   Symbol_Pos.scan_pos -- ($$ "@" |-- $$ "{" |--
    59   Symbol_Pos.scan_pos -- ($$ "@" |-- $$ "{" |--
    60     Symbol_Pos.!!! (fn () => err_prefix ^ "missing closing brace")
    60     Symbol_Pos.!!! (fn () => err_prefix ^ "missing closing brace")
    61       (Scan.repeat scan_ant -- ($$ "}" |-- Symbol_Pos.scan_pos)))
    61       (Scan.repeat scan_ant -- ($$ "}" |-- Symbol_Pos.scan_pos)))
    62   >> (fn (pos1, (body, pos2)) => (flat body, Position.range pos1 pos2));
    62   >> (fn (pos1, (body, pos2)) => (flat body, Position.range pos1 pos2));
    63 
    63 
    64 val scan_text = scan_antiq >> Antiq || Scan.repeat1 scan_txt >> (Text o flat);
    64 val scan_text = scan_antiq >> Antiq || scan_txt >> Text;
    65 
    65 
    66 end;
    66 end;
    67 
    67 
    68 
    68 
    69 (* read *)
    69 (* read *)