2023-03-01 19:47:28 +00:00
|
|
|
(*************************************************************************
|
|
|
|
* Copyright (C)
|
|
|
|
* 2019-2023 The University of Exeter
|
|
|
|
* 2018-2023 The University of Paris-Saclay
|
|
|
|
* 2018 The University of Sheffield
|
|
|
|
*
|
|
|
|
* License:
|
|
|
|
* This program can be redistributed and/or modified under the terms
|
|
|
|
* of the 2-clause BSD-style license.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*************************************************************************)
|
|
|
|
|
2023-03-21 13:33:21 +00:00
|
|
|
chapter\<open>The Isabelle/DOF TestKit\<close>
|
|
|
|
|
2023-03-01 19:47:28 +00:00
|
|
|
theory
|
|
|
|
TestKit
|
|
|
|
imports
|
2023-04-27 05:21:00 +00:00
|
|
|
"Isabelle_DOF_Unit_Tests_document"
|
2023-03-01 19:47:28 +00:00
|
|
|
"Isabelle_DOF-Ontologies.Conceptual"
|
2023-03-04 12:55:32 +00:00
|
|
|
keywords "text-" "text-latex" :: document_body
|
|
|
|
and "text-assert-error" :: document_body
|
|
|
|
and "update_instance-assert-error" :: document_body
|
|
|
|
and "declare_reference-assert-error" :: document_body
|
2023-03-08 07:50:19 +00:00
|
|
|
and "value-assert-error" :: document_body
|
2023-02-21 16:38:45 +00:00
|
|
|
and "definition-assert-error" :: document_body
|
|
|
|
and "doc_class-assert-error" :: document_body
|
2023-03-01 19:47:28 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
|
2023-03-24 11:59:54 +00:00
|
|
|
section\<open>Testing Commands (exec-catch-verify - versions of DOF commands)\<close>
|
2023-03-01 19:47:28 +00:00
|
|
|
|
|
|
|
ML\<open>
|
|
|
|
|
|
|
|
fun gen_enriched_document_command2 name {body} cid_transform attr_transform markdown
|
2023-03-06 11:20:58 +00:00
|
|
|
((meta_args,
|
2023-03-01 19:47:28 +00:00
|
|
|
xstring_opt:(xstring * Position.T) option),
|
|
|
|
toks_list:Input.source list)
|
|
|
|
: theory -> theory =
|
2023-08-29 07:09:28 +00:00
|
|
|
let val ((binding,cid_pos), doc_attrs) = meta_args
|
2023-07-20 08:11:48 +00:00
|
|
|
val oid = Binding.name_of binding
|
2023-03-06 11:20:58 +00:00
|
|
|
val oid' = if meta_args = ODL_Meta_Args_Parser.empty_meta_args
|
|
|
|
then "output"
|
|
|
|
else oid
|
2023-03-01 19:47:28 +00:00
|
|
|
(* as side-effect, generates markup *)
|
2023-03-05 10:29:16 +00:00
|
|
|
fun check_n_tex_text thy toks = let val ctxt = Toplevel.presentation_context (Toplevel.make_state (SOME thy))
|
2023-03-01 19:47:28 +00:00
|
|
|
val pos = Input.pos_of toks;
|
|
|
|
val _ = Context_Position.reports ctxt
|
|
|
|
[(pos, Markup.language_document (Input.is_delimited toks)),
|
|
|
|
(pos, Markup.plain_text)];
|
|
|
|
fun markup xml = let val m = if body then Markup.latex_body
|
|
|
|
else Markup.latex_heading
|
|
|
|
in [XML.Elem (m (Latex.output_name name),
|
|
|
|
xml)] end;
|
|
|
|
|
|
|
|
val text = Document_Output.output_document
|
|
|
|
(Proof_Context.init_global thy)
|
|
|
|
markdown toks
|
|
|
|
(* type file = {path: Path.T, pos: Position.T, content: string} *)
|
|
|
|
|
|
|
|
val strg = XML.string_of (hd (Latex.output text))
|
2023-03-06 11:20:58 +00:00
|
|
|
val file = {path = Path.make [oid' ^ "_snippet.tex"],
|
2023-03-01 19:47:28 +00:00
|
|
|
pos = @{here},
|
|
|
|
content = Bytes.string strg}
|
2023-03-06 22:23:23 +00:00
|
|
|
val dir = Path.append (Resources.master_directory thy) (Path.make ["latex_test"])
|
|
|
|
val _ = Generated_Files.write_file dir file
|
2023-03-01 19:47:28 +00:00
|
|
|
val _ = writeln (strg)
|
|
|
|
in () end \<comment> \<open>important observation: thy is not modified.
|
|
|
|
This implies that several text block can be
|
|
|
|
processed in parallel in a future, as long
|
|
|
|
as they are associated to one meta arg.\<close>
|
2023-03-24 16:20:45 +00:00
|
|
|
val handle_margs_opt = (if meta_args = ODL_Meta_Args_Parser.empty_meta_args
|
2023-03-06 11:20:58 +00:00
|
|
|
then I
|
|
|
|
else
|
|
|
|
Value_Command.Docitem_Parser.create_and_check_docitem
|
2023-03-01 19:47:28 +00:00
|
|
|
{is_monitor = false} {is_inline = false} {define = true}
|
2023-07-20 08:11:48 +00:00
|
|
|
binding (cid_transform cid_pos) (attr_transform doc_attrs))
|
2023-03-24 16:20:45 +00:00
|
|
|
(* ... generating the level-attribute syntax *)
|
|
|
|
in handle_margs_opt #> (fn thy => (app (check_n_tex_text thy) toks_list; thy))
|
2023-03-01 19:47:28 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
val _ =
|
|
|
|
Outer_Syntax.command ("text-", @{here}) "formal comment macro"
|
|
|
|
(ODL_Meta_Args_Parser.attributes -- Parse.opt_target -- Scan.repeat1 Parse.document_source
|
|
|
|
>> (Toplevel.theory o (gen_enriched_document_command2 "TTT" {body=true} I I {markdown = true} )));
|
|
|
|
|
|
|
|
(* copied from Pure_syn for experiments *)
|
|
|
|
|
|
|
|
fun output_document2 state markdown txt =
|
|
|
|
let
|
|
|
|
val ctxt = Toplevel.presentation_context state;
|
|
|
|
val pos = Input.pos_of txt;
|
|
|
|
val _ =
|
|
|
|
Context_Position.reports ctxt
|
|
|
|
[(pos, Markup.language_document (Input.is_delimited txt)),
|
|
|
|
(pos, Markup.plain_text)];
|
|
|
|
val txt' = Document_Output.output_document ctxt markdown txt
|
|
|
|
val strg = XML.string_of (hd (Latex.output txt'))
|
|
|
|
|
|
|
|
val _ = writeln (strg)
|
|
|
|
in Document_Output.output_document ctxt markdown txt end;
|
|
|
|
|
|
|
|
fun document_command2 markdown (loc, txt) =
|
2023-03-24 11:59:54 +00:00
|
|
|
let fun doc2 state = (case loc of
|
2023-03-01 19:47:28 +00:00
|
|
|
NONE => ignore (output_document2 state markdown txt)
|
|
|
|
| SOME (_, pos) =>(ISA_core.err
|
|
|
|
"Illegal target specification -- not a theory context"
|
2023-03-24 11:59:54 +00:00
|
|
|
pos))
|
|
|
|
fun out2 state = output_document2 state markdown txt
|
|
|
|
in Toplevel.keep doc2 o Toplevel.present_local_theory loc out2
|
|
|
|
end
|
2023-03-01 19:47:28 +00:00
|
|
|
|
2023-03-04 08:57:14 +00:00
|
|
|
fun gen_enriched_document_command3 assert name body trans at md (margs, src_list) thy
|
|
|
|
= (gen_enriched_document_command2 name body trans at md (margs, src_list) thy)
|
2023-03-06 07:15:29 +00:00
|
|
|
handle ERROR msg => (if assert src_list msg then (writeln ("Correct error: "^msg^": reported.");thy)
|
2023-03-01 19:47:28 +00:00
|
|
|
else error"Wrong error reported")
|
|
|
|
|
2023-03-08 11:08:33 +00:00
|
|
|
fun error_match src msg = (String.isPrefix (Input.string_of src) msg)
|
2023-03-04 08:57:14 +00:00
|
|
|
|
|
|
|
fun error_match2 [_, src] msg = error_match src msg
|
|
|
|
| error_match2 _ _ = error "Wrong text-assertion-error. Argument format <arg><match> required."
|
2023-03-01 19:47:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
val _ =
|
|
|
|
Outer_Syntax.command ("text-assert-error", @{here}) "formal comment macro"
|
2023-03-06 11:20:58 +00:00
|
|
|
(ODL_Meta_Args_Parser.opt_attributes -- Parse.opt_target -- Scan.repeat1 Parse.document_source
|
2023-03-04 08:57:14 +00:00
|
|
|
>> (Toplevel.theory o (gen_enriched_document_command3 error_match2 "TTT" {body=true}
|
2023-03-13 09:27:31 +00:00
|
|
|
I I {markdown = true} )));
|
2023-03-01 19:47:28 +00:00
|
|
|
|
2023-03-04 08:57:14 +00:00
|
|
|
fun update_instance_command (args,src) thy =
|
|
|
|
(Monitor_Command_Parser.update_instance_command args thy
|
|
|
|
handle ERROR msg => (if error_match src msg
|
2023-03-06 07:15:29 +00:00
|
|
|
then (writeln ("Correct error: "^msg^": reported.");thy)
|
2023-03-04 08:57:14 +00:00
|
|
|
else error"Wrong error reported"))
|
|
|
|
val _ =
|
|
|
|
Outer_Syntax.command \<^command_keyword>\<open>update_instance-assert-error\<close>
|
|
|
|
"update meta-attributes of an instance of a document class"
|
|
|
|
(ODL_Meta_Args_Parser.attributes_upd -- Parse.document_source
|
|
|
|
>> (Toplevel.theory o update_instance_command));
|
2023-03-01 19:47:28 +00:00
|
|
|
|
2023-03-04 12:55:32 +00:00
|
|
|
val _ =
|
2023-07-20 08:11:48 +00:00
|
|
|
let fun create_and_check_docitem (((binding,cid_pos),doc_attrs),src) thy =
|
2023-03-04 12:55:32 +00:00
|
|
|
(Value_Command.Docitem_Parser.create_and_check_docitem
|
|
|
|
{is_monitor = false} {is_inline=true}
|
2023-07-20 08:11:48 +00:00
|
|
|
{define = false} binding (cid_pos) (doc_attrs) thy)
|
2023-03-04 12:55:32 +00:00
|
|
|
handle ERROR msg => (if error_match src msg
|
2023-03-06 07:15:29 +00:00
|
|
|
then (writeln ("Correct error: "^msg^": reported.");thy)
|
2023-03-04 12:55:32 +00:00
|
|
|
else error"Wrong error reported")
|
|
|
|
in Outer_Syntax.command \<^command_keyword>\<open>declare_reference-assert-error\<close>
|
2023-03-24 11:59:54 +00:00
|
|
|
"declare document reference"
|
|
|
|
(ODL_Meta_Args_Parser.attributes -- Parse.document_source
|
|
|
|
>> (Toplevel.theory o create_and_check_docitem))
|
2023-03-04 12:55:32 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2023-03-01 19:47:28 +00:00
|
|
|
val _ =
|
2023-02-21 16:38:45 +00:00
|
|
|
let fun pass_trans_to_value_cmd (args, (((name, modes), t),src)) trans =
|
|
|
|
let val pos = Toplevel.pos_of trans
|
|
|
|
in trans |> Toplevel.theory
|
|
|
|
(fn thy => Value_Command.value_cmd {assert=false} args name modes t pos thy
|
|
|
|
handle ERROR msg => (if error_match src msg
|
|
|
|
then (writeln ("Correct error: "^msg^": reported."); thy)
|
|
|
|
else error"Wrong error reported"))
|
|
|
|
end
|
2023-03-08 07:50:19 +00:00
|
|
|
in Outer_Syntax.command \<^command_keyword>\<open>value-assert-error\<close> "evaluate and print term"
|
|
|
|
(ODL_Meta_Args_Parser.opt_attributes --
|
2023-03-08 11:08:33 +00:00
|
|
|
(Value_Command.opt_evaluator
|
|
|
|
-- Value_Command.opt_modes
|
|
|
|
-- Parse.term
|
|
|
|
-- Parse.document_source)
|
2023-02-21 16:38:45 +00:00
|
|
|
>> (pass_trans_to_value_cmd))
|
|
|
|
end;
|
|
|
|
|
|
|
|
val _ =
|
|
|
|
let fun definition_cmd' meta_args_opt decl params prems spec src bool ctxt =
|
|
|
|
Local_Theory.background_theory (Value_Command.meta_args_exec meta_args_opt) ctxt
|
|
|
|
|> (fn ctxt => Definition_Star_Command.definition_cmd decl params prems spec bool ctxt
|
|
|
|
handle ERROR msg => if error_match src msg
|
|
|
|
then (writeln ("Correct error: "^msg^": reported.")
|
|
|
|
; pair "Bound 0" @{thm refl}
|
|
|
|
|> pair (Bound 0)
|
|
|
|
|> rpair ctxt)
|
|
|
|
else error"Wrong error reported")
|
|
|
|
in
|
|
|
|
Outer_Syntax.local_theory' \<^command_keyword>\<open>definition-assert-error\<close> "constant definition"
|
|
|
|
(ODL_Meta_Args_Parser.opt_attributes --
|
|
|
|
(Scan.option Parse_Spec.constdecl -- (Parse_Spec.opt_thm_name ":" -- Parse.prop) --
|
|
|
|
Parse_Spec.if_assumes -- Parse.for_fixes -- Parse.document_source)
|
|
|
|
>> (fn (meta_args_opt, ((((decl, spec), prems), params), src)) =>
|
|
|
|
#2 oo definition_cmd' meta_args_opt decl params prems spec src))
|
2023-03-08 07:50:19 +00:00
|
|
|
end;
|
|
|
|
|
2023-03-04 12:55:32 +00:00
|
|
|
|
2023-02-21 16:38:45 +00:00
|
|
|
val _ =
|
|
|
|
let fun add_doc_class_cmd' ((((overloaded, hdr), (parent, attrs)),((rejects,accept_rex),invars)), src) =
|
|
|
|
(fn thy => OntoParser.add_doc_class_cmd {overloaded = overloaded} hdr parent attrs rejects accept_rex invars thy
|
|
|
|
handle ERROR msg => (if error_match src msg
|
|
|
|
then (writeln ("Correct error: "^msg^": reported."); thy)
|
|
|
|
else error"Wrong error reported"))
|
|
|
|
in
|
|
|
|
Outer_Syntax.command \<^command_keyword>\<open>doc_class-assert-error\<close>
|
|
|
|
"define document class"
|
|
|
|
((OntoParser.parse_doc_class -- Parse.document_source)
|
|
|
|
>> (Toplevel.theory o add_doc_class_cmd'))
|
|
|
|
end
|
|
|
|
|
2023-03-01 19:47:28 +00:00
|
|
|
val _ =
|
|
|
|
Outer_Syntax.command ("text-latex", \<^here>) "formal comment (primary style)"
|
|
|
|
(Parse.opt_target -- Parse.document_source >> document_command2 {markdown = true});
|
|
|
|
|
|
|
|
\<close>
|
|
|
|
|
2023-03-24 11:59:54 +00:00
|
|
|
(* a little auto-test *)
|
2023-03-01 21:17:32 +00:00
|
|
|
text-latex\<open>dfg\<close>
|
2023-03-01 19:47:28 +00:00
|
|
|
|
|
|
|
text-assert-error[aaaa::A]\<open> @{A \<open>sdf\<close>}\<close>\<open>reference ontologically inconsistent\<close>
|
|
|
|
|
|
|
|
end
|