src/Pure/Thy/document_antiquotations.ML
changeset 67474 90def2b06305
parent 67471 bddfa23a4ea9
child 67495 90d760fa8f34
equal deleted inserted replaced
67473:aad088768872 67474:90def2b06305
   148 
   148 
   149 (* quasi-formal text (unchecked) *)
   149 (* quasi-formal text (unchecked) *)
   150 
   150 
   151 local
   151 local
   152 
   152 
       
   153 fun report_text ctxt text =
       
   154   Context_Position.report ctxt (Input.pos_of text)
       
   155     (Markup.language_text (Input.is_delimited text));
       
   156 
       
   157 fun prepare_text ctxt =
       
   158   Input.source_content #> Document_Antiquotation.prepare_lines ctxt;
       
   159 
   153 fun text_antiquotation name =
   160 fun text_antiquotation name =
   154   Thy_Output.antiquotation_raw name (Scan.lift Args.text_input)
   161   Thy_Output.antiquotation_raw name (Scan.lift Args.text_input)
   155     (fn ctxt => fn text =>
   162     (fn ctxt => fn text =>
   156       let
   163       let
       
   164         val _ = report_text ctxt text;
       
   165       in
       
   166         prepare_text ctxt text
       
   167         |> Thy_Output.output_source ctxt
       
   168         |> Thy_Output.isabelle ctxt
       
   169       end);
       
   170 
       
   171 val theory_text_antiquotation =
       
   172   Thy_Output.antiquotation_raw \<^binding>\<open>theory_text\<close> (Scan.lift Args.text_input)
       
   173     (fn ctxt => fn text =>
       
   174       let
       
   175         val keywords = Thy_Header.get_keywords' ctxt;
       
   176 
       
   177         val _ = report_text ctxt text;
   157         val _ =
   178         val _ =
   158           Context_Position.report ctxt (Input.pos_of text)
   179           Input.source_explode text
   159             (Markup.language_text (Input.is_delimited text));
   180           |> Source.of_list
   160       in Thy_Output.pretty ctxt [Thy_Output.pretty_text ctxt (Input.source_content text)] end);
   181           |> Token.source' true keywords
       
   182           |> Source.exhaust
       
   183           |> maps (Token.reports keywords)
       
   184           |> Context_Position.reports_text ctxt;
       
   185       in
       
   186         prepare_text ctxt text
       
   187         |> Token.explode keywords Position.none
       
   188         |> maps (Thy_Output.output_token ctxt)
       
   189         |> Thy_Output.isabelle ctxt
       
   190       end);
   161 
   191 
   162 in
   192 in
   163 
   193 
   164 val _ =
   194 val _ =
   165   Theory.setup
   195   Theory.setup
   166    (text_antiquotation \<^binding>\<open>text\<close> #>
   196    (text_antiquotation \<^binding>\<open>text\<close> #>
   167     text_antiquotation \<^binding>\<open>cartouche\<close>);
   197     text_antiquotation \<^binding>\<open>cartouche\<close> #>
   168 
   198     theory_text_antiquotation);
   169 end;
   199 
   170 
   200 end;
   171 
   201 
   172 (* theory text with tokens (unchecked) *)
   202 
   173 
       
   174 val _ =
       
   175   Theory.setup
       
   176     (Thy_Output.antiquotation_raw \<^binding>\<open>theory_text\<close> (Scan.lift Args.text_input)
       
   177       (fn ctxt => fn text =>
       
   178         let
       
   179           val keywords = Thy_Header.get_keywords' ctxt;
       
   180 
       
   181           val _ =
       
   182             Context_Position.report ctxt (Input.pos_of text)
       
   183               (Markup.language_Isar (Input.is_delimited text));
       
   184           val _ =
       
   185             Input.source_explode text
       
   186             |> Source.of_list
       
   187             |> Token.source' true keywords
       
   188             |> Source.exhaust
       
   189             |> maps (Token.reports keywords)
       
   190             |> Context_Position.reports_text ctxt;
       
   191 
       
   192           val toks =
       
   193             Input.source_content text
       
   194             |> Document_Antiquotation.trim_lines ctxt
       
   195             |> Document_Antiquotation.indent_lines ctxt
       
   196             |> Token.explode keywords Position.none;
       
   197         in Thy_Output.isabelle ctxt (maps (Thy_Output.output_token ctxt) toks) end));
       
   198 
   203 
   199 
   204 
   200 (* goal state *)
   205 (* goal state *)
   201 
   206 
   202 local
   207 local