(************************************************************************* * 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 *************************************************************************) chapter\Term Antiquotations\ text\Terms are represented by "Inner Syntax" parsed by an Earley parser in Isabelle. For historical reasons, \<^emph>\term antiquotations\ are called therefore somewhat misleadingly "Inner Syntax Antiquotations". \ theory Concept_TermAntiquotations imports "Isabelle_DOF_Unit_Tests_document" "Isabelle_DOF-Ontologies.Conceptual" TestKit begin section\Context\ text\Since the syntax chosen for values of doc-class attributes is HOL-syntax --- requiring a fast read on the ``What's in Main''-documentation, but not additional knowledge on, say, SML --- an own syntax for references to types, terms, theorems, etc. are necessary. These are the ``Term Antiquotations'' (in earlier papers also called: ``Inner Syntax Antiquotations''). They are the key-mechanism to denote \<^item> Ontological Links, i.e. attributes refering to document classes defined by the ontology \<^item> Ontological F-Links, i.e. attributes referring to formal entities inside Isabelle (such as thm's) This file contains a number of examples resulting from the @{theory "Isabelle_DOF-Ontologies.Conceptual"} - ontology; the emphasis of this presentation is to present the expressivity of ODL on a paradigmatical example. \ section\Test Purpose.\ text\Testing Standard Term-Antiquotations and Code-Term-Antiquotations. \ text\Just a check of the status DOF core: observe that no new classes have been defined.\ print_doc_classes print_doc_items section\Term-Antiquotations Referring to \<^verbatim>\thm\‘s\ text\Some sample lemma:\ lemma*[l::E] murks : "Example = @{thm ''refl''}" oops text-assert-error\... @{E "l"}\\Undefined instance:\ \ \oops retracts the ENTIRE system state, thus also the creation of an instance of E\ lemma*[l::E] local_sample_lemma : "@{thm \refl\} = @{thm ''refl''}" by simp \ \un-evaluated references are similar to uninterpreted constants. Not much is known about them, but that doesn't mean that we can't prove some basics over them...\ lemma*[l2::E] local_sample_lemma2 : "@{thm ''local_sample_lemma''} = @{thm ''local_sample_lemma''}" by simp value*\@{thm ''local_sample_lemma''}\ value-assert-error\ @{thm \Conxept_TermAntiquotations.local_sample_lemma\}\\Undefined fact\ section\Testing the Standard ("Built-in") Term-Antiquotations\ text\Example for a meta-attribute of ODL-type @{typ "file"} with an appropriate ISA for the file @{file "Concept_TermAntiquotations.thy"}\ text*[xcv1::A, x=5]\Lorem ipsum ...\ text*[xcv3::A, x=7]\Lorem ipsum ...\ text\Example for a meta-attribute of ODL-type @{typ "typ"} with an appropriate ISA for the theorem @{thm "refl"}\ text*[xcv2::C, g="@{thm ''HOL.refl''}"]\Lorem ipsum ...\ text\A warning about the usage of the \docitem\ TA: The \docitem\ TA offers a way to check the reference of class instances without checking the instances type. So one will be able to reference \docitem\s (class instances) and have them checked, without the burden of the type checking required otherwise. But it may give rise to unwanted behaviors, due to its polymorphic type. It must not be used for certification. \ section\Other Built-In Term Antiquotations\ text-assert-error[ae::text_element]\@{file "non-existing.thy"}\\No such file: \ text\A text-antiquotation from Main: @{file "TestKit.thy"}\ value-assert-error\@{file \non-existing.thy\}\\No such file: \ value*\@{file \TestKit.thy\}\ text*[xcv::F, u="@{file ''TestKit.thy''}"]\Lorem ipsum ...\ value*\@{term \aa + bb\}\ value*\@{typ \'a list\}\ section\Putting everything together\ text\Major sample: test-item of doc-class \F\ with a relational link between class instances, and links to formal Isabelle items like \typ\, \term\ and \thm\. \ declare[[ML_print_depth = 10000]] text*[xcv4::F, r="[@{thm ''HOL.refl''}, @{thm \Concept_TermAntiquotations.local_sample_lemma\}]", (* long names required *) b="{(@{A ''xcv1''},@{C \xcv2\})}", (* notations \...\ vs. ''...'' *) s="[@{typ \int list\}]", properties = "[@{term \H \ H\}]" (* notation \...\ required for UTF8*) ]\Lorem ipsum ...\ declare[[ML_print_depth = 20]] text*[xcv5::G, g="@{thm \HOL.sym\}"]\Lorem ipsum ...\ text\... and here we add a relation between @{docitem \xcv3\} and @{docitem \xcv2\} into the relation \verb+b+ of @{docitem \xcv5\}. Note that in the link-relation, a @{typ "C"}-type is required, so if a @{typ "G"}-type is offered, it is considered illegal in \verb+Isa_DOF+ despite the sub-class relation between those classes: \ update_instance-assert-error[xcv4::F, b+="{(@{docitem ''xcv3''},@{docitem ''xcv5''})}"] \Type unification failed\ text\And here is the results of some ML-term antiquotations:\ ML\ @{docitem_attribute b::xcv4} \ ML\ @{docitem xcv4} \ ML\ @{docitem_name xcv4} \ text\Now we might need to reference a class instance in a term command and we would like Isabelle to check that this instance is indeed an instance of this class. Here, we want to reference the instance @{docitem_name "xcv4"} previously defined. We can use the term* command which extends the classic term command and does the appropriate checking.\ term*\@{F \xcv4\}\ text\We can also reference an attribute of the instance. Here we reference the attribute r of the class F which has the type @{typ \thm list\}.\ term*\r @{F \xcv4\}\ text\We declare a new text element. Note that the class name contains an underscore "\_".\ text*[te::text_element]\Lorem ipsum...\ term*\@{text_element \te\}\ text\Terms containing term antiquotations can be checked and evaluated using \<^theory_text>\term_\ and \<^theory_text>\value_\ text antiquotations respectively: We can print the term @{term_ \r @{F \xcv4\}\} with \@{term_ \r @{F \xcv4\}\}\ or get the value of the \<^const>\F.r\ attribute of @{docitem \xcv4\} with \@{value_ \r @{F \xcv4\}\}\ \<^theory_text>\value_\ may have an optional argument between square brackets to specify the evaluator but this argument must be specified after a default optional argument already defined by the text antiquotation implementation. So one must use the following syntax if he does not want to specify the first optional argument: \@{value_ [] [nbe] \r @{F \xcv4\}\}\. Note the empty brackets. \ text\There also are \<^theory_text>\term_\ and \<^theory_text>\value_\ ML antiquotations: \<^ML>\@{term_ \r @{F \xcv4\}\}\ will return the ML representation of the term \<^term_>\r @{F \xcv4\}\, and \<^ML>\@{value_ \r @{F \xcv4\}\}\ will return the ML representation of the value of the \<^const>\F.r\ attribute of @{docitem \xcv4\}. \<^theory_text>\value_\ may have an optional argument between square brackets to specify the evaluator: \ ML\ val t = @{term_ \r @{F \xcv4\}\} val tt = @{value_ [nbe] \r @{F \xcv4\}\} \ end