doc-src/IsarRef/Thy/Spec.thy
changeset 28762 f5d79aeffd81
parent 28761 9ec4482c9201
child 28767 f09ceb800d00
equal deleted inserted replaced
28761:9ec4482c9201 28762:f5d79aeffd81
   146     @{command_def "axiomatization"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!)\\
   146     @{command_def "axiomatization"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!)\\
   147     @{command_def "definition"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
   147     @{command_def "definition"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
   148     @{attribute_def "defn"} & : & @{text attribute} \\
   148     @{attribute_def "defn"} & : & @{text attribute} \\
   149     @{command_def "abbreviation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
   149     @{command_def "abbreviation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
   150     @{command_def "print_abbrevs"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow> "} \\
   150     @{command_def "print_abbrevs"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow> "} \\
   151     @{command_def "notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   152     @{command_def "no_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
       
   153   \end{matharray}
   151   \end{matharray}
   154 
   152 
   155   These specification mechanisms provide a slightly more abstract view
   153   These specification mechanisms provide a slightly more abstract view
   156   than the underlying primitives of @{command "consts"}, @{command
   154   than the underlying primitives of @{command "consts"}, @{command
   157   "defs"} (see \secref{sec:consts}), and @{command "axioms"} (see
   155   "defs"} (see \secref{sec:consts}), and @{command "axioms"} (see
   162     'axiomatization' target? fixes? ('where' specs)?
   160     'axiomatization' target? fixes? ('where' specs)?
   163     ;
   161     ;
   164     'definition' target? (decl 'where')? thmdecl? prop
   162     'definition' target? (decl 'where')? thmdecl? prop
   165     ;
   163     ;
   166     'abbreviation' target? mode? (decl 'where')? prop
   164     'abbreviation' target? mode? (decl 'where')? prop
   167     ;
       
   168     ('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and')
       
   169     ;
   165     ;
   170 
   166 
   171     fixes: ((name ('::' type)? mixfix? | vars) + 'and')
   167     fixes: ((name ('::' type)? mixfix? | vars) + 'and')
   172     ;
   168     ;
   173     specs: (thmdecl? props + 'and')
   169     specs: (thmdecl? props + 'and')
   221   \secref{sec:syn-trans}.
   217   \secref{sec:syn-trans}.
   222   
   218   
   223   \item @{command "print_abbrevs"} prints all constant abbreviations
   219   \item @{command "print_abbrevs"} prints all constant abbreviations
   224   of the current context.
   220   of the current context.
   225   
   221   
   226   \item @{command "notation"}~@{text "c (mx)"} associates mixfix
   222   \end{description}
   227   syntax with an existing constant or fixed variable.  This is a
       
   228   robust interface to the underlying @{command "syntax"} primitive
       
   229   (\secref{sec:syn-trans}).  Type declaration and internal syntactic
       
   230   representation of the given entity is retrieved from the context.
       
   231   
       
   232   \item @{command "no_notation"} is similar to @{command "notation"},
       
   233   but removes the specified syntax annotation from the present
       
   234   context.
       
   235 
       
   236   \end{description}
       
   237 
       
   238   All of these specifications support local theory targets (cf.\
       
   239   \secref{sec:target}).
       
   240 *}
   223 *}
   241 
   224 
   242 
   225 
   243 section {* Generic declarations *}
   226 section {* Generic declarations *}
   244 
   227 
   922 
   905 
   923 text {*
   906 text {*
   924   \begin{matharray}{rcll}
   907   \begin{matharray}{rcll}
   925     @{command_def "types"} & : & @{text "theory \<rightarrow> theory"} \\
   908     @{command_def "types"} & : & @{text "theory \<rightarrow> theory"} \\
   926     @{command_def "typedecl"} & : & @{text "theory \<rightarrow> theory"} \\
   909     @{command_def "typedecl"} & : & @{text "theory \<rightarrow> theory"} \\
   927     @{command_def "nonterminals"} & : & @{text "theory \<rightarrow> theory"} \\
       
   928     @{command_def "arities"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\
   910     @{command_def "arities"} & : & @{text "theory \<rightarrow> theory"} & (axiomatic!) \\
   929   \end{matharray}
   911   \end{matharray}
   930 
   912 
   931   \begin{rail}
   913   \begin{rail}
   932     'types' (typespec '=' type infix? +)
   914     'types' (typespec '=' type infix? +)
   933     ;
   915     ;
   934     'typedecl' typespec infix?
   916     'typedecl' typespec infix?
   935     ;
       
   936     'nonterminals' (name +)
       
   937     ;
   917     ;
   938     'arities' (nameref '::' arity +)
   918     'arities' (nameref '::' arity +)
   939     ;
   919     ;
   940   \end{rail}
   920   \end{rail}
   941 
   921 
   949   synonyms are fully expanded.
   929   synonyms are fully expanded.
   950   
   930   
   951   \item @{command "typedecl"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} declares a new
   931   \item @{command "typedecl"}~@{text "(\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n) t"} declares a new
   952   type constructor @{text t}, intended as an actual logical type (of
   932   type constructor @{text t}, intended as an actual logical type (of
   953   the object-logic, if available).
   933   the object-logic, if available).
   954 
       
   955   \item @{command "nonterminals"}~@{text c} declares type constructors
       
   956   @{text c} (without arguments) to act as purely syntactic types,
       
   957   i.e.\ nonterminal symbols of Isabelle's inner syntax of terms or
       
   958   types.
       
   959 
   934 
   960   \item @{command "arities"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n) s"} augments
   935   \item @{command "arities"}~@{text "t :: (s\<^sub>1, \<dots>, s\<^sub>n) s"} augments
   961   Isabelle's order-sorted signature of types by new type constructor
   936   Isabelle's order-sorted signature of types by new type constructor
   962   arities.  This is done axiomatically!  The @{command_ref "instance"}
   937   arities.  This is done axiomatically!  The @{command_ref "instance"}
   963   command (see \S\ref{sec:axclass}) provides a way to introduce proven
   938   command (see \S\ref{sec:axclass}) provides a way to introduce proven
  1204   ``@{text "??"}'' prefixed to the full internal name.
  1179   ``@{text "??"}'' prefixed to the full internal name.
  1205 
  1180 
  1206   \end{description}
  1181   \end{description}
  1207 *}
  1182 *}
  1208 
  1183 
  1209 
       
  1210 section {* Syntax and translations \label{sec:syn-trans} *}
       
  1211 
       
  1212 text {*
       
  1213   \begin{matharray}{rcl}
       
  1214     @{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1215     @{command_def "no_syntax"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1216     @{command_def "translations"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1217     @{command_def "no_translations"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1218   \end{matharray}
       
  1219 
       
  1220   \begin{rail}
       
  1221     ('syntax' | 'no\_syntax') mode? (constdecl +)
       
  1222     ;
       
  1223     ('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +)
       
  1224     ;
       
  1225 
       
  1226     mode: ('(' ( name | 'output' | name 'output' ) ')')
       
  1227     ;
       
  1228     transpat: ('(' nameref ')')? string
       
  1229     ;
       
  1230   \end{rail}
       
  1231 
       
  1232   \begin{description}
       
  1233   
       
  1234   \item @{command "syntax"}~@{text "(mode) decls"} is similar to
       
  1235   @{command "consts"}~@{text decls}, except that the actual logical
       
  1236   signature extension is omitted.  Thus the context free grammar of
       
  1237   Isabelle's inner syntax may be augmented in arbitrary ways,
       
  1238   independently of the logic.  The @{text mode} argument refers to the
       
  1239   print mode that the grammar rules belong; unless the @{keyword_ref
       
  1240   "output"} indicator is given, all productions are added both to the
       
  1241   input and output grammar.
       
  1242   
       
  1243   \item @{command "no_syntax"}~@{text "(mode) decls"} removes grammar
       
  1244   declarations (and translations) resulting from @{text decls}, which
       
  1245   are interpreted in the same manner as for @{command "syntax"} above.
       
  1246   
       
  1247   \item @{command "translations"}~@{text rules} specifies syntactic
       
  1248   translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}),
       
  1249   parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}).
       
  1250   Translation patterns may be prefixed by the syntactic category to be
       
  1251   used for parsing; the default is @{text logic}.
       
  1252   
       
  1253   \item @{command "no_translations"}~@{text rules} removes syntactic
       
  1254   translation rules, which are interpreted in the same manner as for
       
  1255   @{command "translations"} above.
       
  1256 
       
  1257   \end{description}
       
  1258 *}
       
  1259 
       
  1260 
       
  1261 section {* Syntax translation functions *}
       
  1262 
       
  1263 text {*
       
  1264   \begin{matharray}{rcl}
       
  1265     @{command_def "parse_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1266     @{command_def "parse_translation"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1267     @{command_def "print_translation"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1268     @{command_def "typed_print_translation"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1269     @{command_def "print_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\
       
  1270   \end{matharray}
       
  1271 
       
  1272   \begin{rail}
       
  1273   ( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' |
       
  1274     'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text
       
  1275   ;
       
  1276   \end{rail}
       
  1277 
       
  1278   Syntax translation functions written in ML admit almost arbitrary
       
  1279   manipulations of Isabelle's inner syntax.  Any of the above commands
       
  1280   have a single \railqtok{text} argument that refers to an ML
       
  1281   expression of appropriate type, which are as follows by default:
       
  1282 
       
  1283 %FIXME proper antiquotations
       
  1284 \begin{ttbox}
       
  1285 val parse_ast_translation   : (string * (ast list -> ast)) list
       
  1286 val parse_translation       : (string * (term list -> term)) list
       
  1287 val print_translation       : (string * (term list -> term)) list
       
  1288 val typed_print_translation :
       
  1289   (string * (bool -> typ -> term list -> term)) list
       
  1290 val print_ast_translation   : (string * (ast list -> ast)) list
       
  1291 \end{ttbox}
       
  1292 
       
  1293   If the @{text "(advanced)"} option is given, the corresponding
       
  1294   translation functions may depend on the current theory or proof
       
  1295   context.  This allows to implement advanced syntax mechanisms, as
       
  1296   translations functions may refer to specific theory declarations or
       
  1297   auxiliary proof data.
       
  1298 
       
  1299   See also \cite[\S8]{isabelle-ref} for more information on the
       
  1300   general concept of syntax transformations in Isabelle.
       
  1301 
       
  1302 %FIXME proper antiquotations
       
  1303 \begin{ttbox}
       
  1304 val parse_ast_translation:
       
  1305   (string * (Proof.context -> ast list -> ast)) list
       
  1306 val parse_translation:
       
  1307   (string * (Proof.context -> term list -> term)) list
       
  1308 val print_translation:
       
  1309   (string * (Proof.context -> term list -> term)) list
       
  1310 val typed_print_translation:
       
  1311   (string * (Proof.context -> bool -> typ -> term list -> term)) list
       
  1312 val print_ast_translation:
       
  1313   (string * (Proof.context -> ast list -> ast)) list
       
  1314 \end{ttbox}
       
  1315 *}
       
  1316 
       
  1317 end
  1184 end