142 |
139 |
143 These configuration options control the detail of information that |
140 These configuration options control the detail of information that |
144 is displayed for types, terms, theorems, goals etc. See also |
141 is displayed for types, terms, theorems, goals etc. See also |
145 \secref{sec:config}. |
142 \secref{sec:config}. |
146 |
143 |
147 \begin{description} |
|
148 |
|
149 \<^descr> @{attribute show_markup} controls direct inlining of markup |
144 \<^descr> @{attribute show_markup} controls direct inlining of markup |
150 into the printed representation of formal entities --- notably type |
145 into the printed representation of formal entities --- notably type |
151 and sort constraints. This enables Prover IDE users to retrieve |
146 and sort constraints. This enables Prover IDE users to retrieve |
152 that information via tooltips or popups while hovering with the |
147 that information via tooltips or popups while hovering with the |
153 mouse over the output window, for example. Consequently, this |
148 mouse over the output window, for example. Consequently, this |
254 The \emph{print mode} facility allows to modify various operations |
247 The \emph{print mode} facility allows to modify various operations |
255 for printing. Commands like @{command typ}, @{command term}, |
248 for printing. Commands like @{command typ}, @{command term}, |
256 @{command thm} (see \secref{sec:print-diag}) take additional print |
249 @{command thm} (see \secref{sec:print-diag}) take additional print |
257 modes as optional argument. The underlying ML operations are as |
250 modes as optional argument. The underlying ML operations are as |
258 follows. |
251 follows. |
259 |
|
260 \begin{description} |
|
261 |
252 |
262 \<^descr> @{ML "print_mode_value ()"} yields the list of currently |
253 \<^descr> @{ML "print_mode_value ()"} yields the list of currently |
263 active print mode names. This should be understood as symbolic |
254 active print mode names. This should be understood as symbolic |
264 representation of certain individual features for printing (with |
255 representation of certain individual features for printing (with |
265 precedence from left to right). |
256 precedence from left to right). |
269 prepended by the given @{text "modes"}. This provides a thread-safe |
260 prepended by the given @{text "modes"}. This provides a thread-safe |
270 way to augment print modes. It is also monotonic in the set of mode |
261 way to augment print modes. It is also monotonic in the set of mode |
271 names: it retains the default print mode that certain |
262 names: it retains the default print mode that certain |
272 user-interfaces might have installed for their proper functioning! |
263 user-interfaces might have installed for their proper functioning! |
273 |
264 |
274 \end{description} |
|
275 |
265 |
276 \<^medskip> |
266 \<^medskip> |
277 The pretty printer for inner syntax maintains alternative |
267 The pretty printer for inner syntax maintains alternative |
278 mixfix productions for any print mode name invented by the user, say |
268 mixfix productions for any print mode name invented by the user, say |
279 in commands like @{command notation} or @{command abbreviation}. |
269 in commands like @{command notation} or @{command abbreviation}. |
280 Mode names can be arbitrary, but the following ones have a specific |
270 Mode names can be arbitrary, but the following ones have a specific |
281 meaning by convention: |
271 meaning by convention: |
282 |
272 |
283 \begin{itemize} |
|
284 |
|
285 \<^item> @{verbatim \<open>""\<close>} (the empty string): default mode; |
273 \<^item> @{verbatim \<open>""\<close>} (the empty string): default mode; |
286 implicitly active as last element in the list of modes. |
274 implicitly active as last element in the list of modes. |
287 |
275 |
288 \<^item> @{verbatim input}: dummy print mode that is never active; may |
276 \<^item> @{verbatim input}: dummy print mode that is never active; may |
289 be used to specify notation that is only available for input. |
277 be used to specify notation that is only available for input. |
563 |
542 |
564 text \<open>The inner lexical syntax vaguely resembles the outer one |
543 text \<open>The inner lexical syntax vaguely resembles the outer one |
565 (\secref{sec:outer-lex}), but some details are different. There are |
544 (\secref{sec:outer-lex}), but some details are different. There are |
566 two main categories of inner syntax tokens: |
545 two main categories of inner syntax tokens: |
567 |
546 |
568 \begin{enumerate} |
|
569 |
|
570 \<^enum> \emph{delimiters} --- the literal tokens occurring in |
547 \<^enum> \emph{delimiters} --- the literal tokens occurring in |
571 productions of the given priority grammar (cf.\ |
548 productions of the given priority grammar (cf.\ |
572 \secref{sec:priority-grammar}); |
549 \secref{sec:priority-grammar}); |
573 |
550 |
574 \<^enum> \emph{named tokens} --- various categories of identifiers etc. |
551 \<^enum> \emph{named tokens} --- various categories of identifiers etc. |
575 |
552 |
576 \end{enumerate} |
|
577 |
553 |
578 Delimiters override named tokens and may thus render certain |
554 Delimiters override named tokens and may thus render certain |
579 identifiers inaccessible. Sometimes the logical context admits |
555 identifiers inaccessible. Sometimes the logical context admits |
580 alternative ways to refer to the same entity, potentially via |
556 alternative ways to refer to the same entity, potentially via |
581 qualified names. |
557 qualified names. |
849 \<^item> Dummy variables (written as underscore) may occur in different |
818 \<^item> Dummy variables (written as underscore) may occur in different |
850 roles. |
819 roles. |
851 |
820 |
852 \begin{description} |
821 \begin{description} |
853 |
822 |
854 \<^descr> A type ``@{text "_"}'' or ``@{text "_ :: sort"}'' acts like an |
823 \item A type ``@{text "_"}'' or ``@{text "_ :: sort"}'' acts like an |
855 anonymous inference parameter, which is filled-in according to the |
824 anonymous inference parameter, which is filled-in according to the |
856 most general type produced by the type-checking phase. |
825 most general type produced by the type-checking phase. |
857 |
826 |
858 \<^descr> A bound ``@{text "_"}'' refers to a vacuous abstraction, where |
827 \item A bound ``@{text "_"}'' refers to a vacuous abstraction, where |
859 the body does not refer to the binding introduced here. As in the |
828 the body does not refer to the binding introduced here. As in the |
860 term @{term "\<lambda>x _. x"}, which is @{text "\<alpha>"}-equivalent to @{text |
829 term @{term "\<lambda>x _. x"}, which is @{text "\<alpha>"}-equivalent to @{text |
861 "\<lambda>x y. x"}. |
830 "\<lambda>x y. x"}. |
862 |
831 |
863 \<^descr> A free ``@{text "_"}'' refers to an implicit outer binding. |
832 \item A free ``@{text "_"}'' refers to an implicit outer binding. |
864 Higher definitional packages usually allow forms like @{text "f x _ |
833 Higher definitional packages usually allow forms like @{text "f x _ |
865 = x"}. |
834 = x"}. |
866 |
835 |
867 \<^descr> A schematic ``@{text "_"}'' (within a term pattern, see |
836 \item A schematic ``@{text "_"}'' (within a term pattern, see |
868 \secref{sec:term-decls}) refers to an anonymous variable that is |
837 \secref{sec:term-decls}) refers to an anonymous variable that is |
869 implicitly abstracted over its context of locally bound variables. |
838 implicitly abstracted over its context of locally bound variables. |
870 For example, this allows pattern matching of @{text "{x. f x = g |
839 For example, this allows pattern matching of @{text "{x. f x = g |
871 x}"} against @{text "{x. _ = _}"}, or even @{text "{_. _ = _}"} by |
840 x}"} against @{text "{x. _ = _}"}, or even @{text "{_. _ = _}"} by |
872 using both bound and schematic dummies. |
841 using both bound and schematic dummies. |
873 |
842 |
874 \end{description} |
843 \end{description} |
875 |
844 |
876 \<^descr> The three literal dots ``@{verbatim "..."}'' may be also |
845 \<^descr> The three literal dots ``@{verbatim "..."}'' may be also |
877 written as ellipsis symbol @{verbatim "\<dots>"}. In both cases this |
846 written as ellipsis symbol @{verbatim "\<dots>"}. In both cases this |
885 rules (\secref{sec:syn-trans}), notably on the RHS. |
854 rules (\secref{sec:syn-trans}), notably on the RHS. |
886 |
855 |
887 \<^descr> @{verbatim XCONST} is similar to @{verbatim CONST}, but |
856 \<^descr> @{verbatim XCONST} is similar to @{verbatim CONST}, but |
888 retains the constant name as given. This is only relevant to |
857 retains the constant name as given. This is only relevant to |
889 translation rules (\secref{sec:syn-trans}), notably on the LHS. |
858 translation rules (\secref{sec:syn-trans}), notably on the LHS. |
890 |
|
891 \end{itemize} |
|
892 \<close> |
859 \<close> |
893 |
860 |
894 |
861 |
895 subsection \<open>Inspecting the syntax\<close> |
862 subsection \<open>Inspecting the syntax\<close> |
896 |
863 |
897 text \<open> |
864 text \<open> |
898 \begin{matharray}{rcl} |
865 \begin{matharray}{rcl} |
899 @{command_def "print_syntax"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
866 @{command_def "print_syntax"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
900 \end{matharray} |
867 \end{matharray} |
901 |
868 |
902 \begin{description} |
|
903 |
|
904 \<^descr> @{command "print_syntax"} prints the inner syntax of the |
869 \<^descr> @{command "print_syntax"} prints the inner syntax of the |
905 current context. The output can be quite large; the most important |
870 current context. The output can be quite large; the most important |
906 sections are explained below. |
871 sections are explained below. |
907 |
872 |
908 \begin{description} |
873 \begin{description} |
909 |
874 |
910 \<^descr> @{text "lexicon"} lists the delimiters of the inner token |
875 \item @{text "lexicon"} lists the delimiters of the inner token |
911 language; see \secref{sec:inner-lex}. |
876 language; see \secref{sec:inner-lex}. |
912 |
877 |
913 \<^descr> @{text "prods"} lists the productions of the underlying |
878 \item @{text "prods"} lists the productions of the underlying |
914 priority grammar; see \secref{sec:priority-grammar}. |
879 priority grammar; see \secref{sec:priority-grammar}. |
915 |
880 |
916 The nonterminal @{text "A\<^sup>(\<^sup>p\<^sup>)"} is rendered in plain text as @{text |
881 The nonterminal @{text "A\<^sup>(\<^sup>p\<^sup>)"} is rendered in plain text as @{text |
917 "A[p]"}; delimiters are quoted. Many productions have an extra |
882 "A[p]"}; delimiters are quoted. Many productions have an extra |
918 @{text "\<dots> => name"}. These names later become the heads of parse |
883 @{text "\<dots> => name"}. These names later become the heads of parse |
919 trees; they also guide the pretty printer. |
884 trees; they also guide the pretty printer. |
920 |
885 |
921 Productions without such parse tree names are called \emph{copy |
886 Productions without such parse tree names are called \emph{copy |
922 productions}. Their right-hand side must have exactly one |
887 productions}. Their right-hand side must have exactly one |
923 nonterminal symbol (or named token). The parser does not create a |
888 nonterminal symbol (or named token). The parser does not create a |
924 new parse tree node for copy productions, but simply returns the |
889 new parse tree node for copy productions, but simply returns the |
925 parse tree of the right-hand symbol. |
890 parse tree of the right-hand symbol. |
926 |
891 |
927 If the right-hand side of a copy production consists of a single |
892 If the right-hand side of a copy production consists of a single |
928 nonterminal without any delimiters, then it is called a \emph{chain |
893 nonterminal without any delimiters, then it is called a \emph{chain |
929 production}. Chain productions act as abbreviations: conceptually, |
894 production}. Chain productions act as abbreviations: conceptually, |
930 they are removed from the grammar by adding new productions. |
895 they are removed from the grammar by adding new productions. |
931 Priority information attached to chain productions is ignored; only |
896 Priority information attached to chain productions is ignored; only |
932 the dummy value @{text "-1"} is displayed. |
897 the dummy value @{text "-1"} is displayed. |
933 |
898 |
934 \<^descr> @{text "print modes"} lists the alternative print modes |
899 \item @{text "print modes"} lists the alternative print modes |
935 provided by this grammar; see \secref{sec:print-modes}. |
900 provided by this grammar; see \secref{sec:print-modes}. |
936 |
901 |
937 \<^descr> @{text "parse_rules"} and @{text "print_rules"} relate to |
902 \item @{text "parse_rules"} and @{text "print_rules"} relate to |
938 syntax translations (macros); see \secref{sec:syn-trans}. |
903 syntax translations (macros); see \secref{sec:syn-trans}. |
939 |
904 |
940 \<^descr> @{text "parse_ast_translation"} and @{text |
905 \item @{text "parse_ast_translation"} and @{text |
941 "print_ast_translation"} list sets of constants that invoke |
906 "print_ast_translation"} list sets of constants that invoke |
942 translation functions for abstract syntax trees, which are only |
907 translation functions for abstract syntax trees, which are only |
943 required in very special situations; see \secref{sec:tr-funs}. |
908 required in very special situations; see \secref{sec:tr-funs}. |
944 |
909 |
945 \<^descr> @{text "parse_translation"} and @{text "print_translation"} |
910 \item @{text "parse_translation"} and @{text "print_translation"} |
946 list the sets of constants that invoke regular translation |
911 list the sets of constants that invoke regular translation |
947 functions; see \secref{sec:tr-funs}. |
912 functions; see \secref{sec:tr-funs}. |
948 |
|
949 \end{description} |
|
950 |
913 |
951 \end{description} |
914 \end{description} |
952 \<close> |
915 \<close> |
953 |
916 |
954 |
917 |
972 |
935 |
973 Certain warning or error messages are printed, depending on the |
936 Certain warning or error messages are printed, depending on the |
974 situation and the given configuration options. Parsing ultimately |
937 situation and the given configuration options. Parsing ultimately |
975 fails, if multiple results remain after the filtering phase. |
938 fails, if multiple results remain after the filtering phase. |
976 |
939 |
977 \begin{description} |
|
978 |
|
979 \<^descr> @{attribute syntax_ambiguity_warning} controls output of |
940 \<^descr> @{attribute syntax_ambiguity_warning} controls output of |
980 explicit warning messages about syntax ambiguity. |
941 explicit warning messages about syntax ambiguity. |
981 |
942 |
982 \<^descr> @{attribute syntax_ambiguity_limit} determines the number of |
943 \<^descr> @{attribute syntax_ambiguity_limit} determines the number of |
983 resulting parse trees that are shown as part of the printed message |
944 resulting parse trees that are shown as part of the printed message |
984 in case of an ambiguity. |
945 in case of an ambiguity. |
985 |
|
986 \end{description} |
|
987 \<close> |
946 \<close> |
988 |
947 |
989 |
948 |
990 section \<open>Syntax transformations \label{sec:syntax-transformations}\<close> |
949 section \<open>Syntax transformations \label{sec:syntax-transformations}\<close> |
991 |
950 |
1213 (@{verbatim "_"}). The latter correspond to nonterminal symbols |
1167 (@{verbatim "_"}). The latter correspond to nonterminal symbols |
1214 @{text "A\<^sub>i"} derived from the argument types @{text "\<tau>\<^sub>i"} as |
1168 @{text "A\<^sub>i"} derived from the argument types @{text "\<tau>\<^sub>i"} as |
1215 follows: |
1169 follows: |
1216 \begin{itemize} |
1170 \begin{itemize} |
1217 |
1171 |
1218 \<^item> @{text "prop"} if @{text "\<tau>\<^sub>i = prop"} |
1172 \item @{text "prop"} if @{text "\<tau>\<^sub>i = prop"} |
1219 |
1173 |
1220 \<^item> @{text "logic"} if @{text "\<tau>\<^sub>i = (\<dots>)\<kappa>"} for logical type |
1174 \item @{text "logic"} if @{text "\<tau>\<^sub>i = (\<dots>)\<kappa>"} for logical type |
1221 constructor @{text "\<kappa> \<noteq> prop"} |
1175 constructor @{text "\<kappa> \<noteq> prop"} |
1222 |
1176 |
1223 \<^item> @{text any} if @{text "\<tau>\<^sub>i = \<alpha>"} for type variables |
1177 \item @{text any} if @{text "\<tau>\<^sub>i = \<alpha>"} for type variables |
1224 |
1178 |
1225 \<^item> @{text "\<kappa>"} if @{text "\<tau>\<^sub>i = \<kappa>"} for nonterminal @{text "\<kappa>"} |
1179 \item @{text "\<kappa>"} if @{text "\<tau>\<^sub>i = \<kappa>"} for nonterminal @{text "\<kappa>"} |
1226 (syntactic type constructor) |
1180 (syntactic type constructor) |
1227 |
1181 |
1228 \end{itemize} |
1182 \end{itemize} |
1229 |
1183 |
1230 Each @{text "A\<^sub>i"} is decorated by priority @{text "p\<^sub>i"} from the |
1184 Each @{text "A\<^sub>i"} is decorated by priority @{text "p\<^sub>i"} from the |
1231 given list @{text "ps"}; missing priorities default to 0. |
1185 given list @{text "ps"}; missing priorities default to 0. |
1289 AST rewrite rules @{text "(lhs, rhs)"} need to obey the following |
1243 AST rewrite rules @{text "(lhs, rhs)"} need to obey the following |
1290 side-conditions: |
1244 side-conditions: |
1291 |
1245 |
1292 \begin{itemize} |
1246 \begin{itemize} |
1293 |
1247 |
1294 \<^item> Rules must be left linear: @{text "lhs"} must not contain |
1248 \item Rules must be left linear: @{text "lhs"} must not contain |
1295 repeated variables.\footnote{The deeper reason for this is that AST |
1249 repeated variables.\footnote{The deeper reason for this is that AST |
1296 equality is not well-defined: different occurrences of the ``same'' |
1250 equality is not well-defined: different occurrences of the ``same'' |
1297 AST could be decorated differently by accidental type-constraints or |
1251 AST could be decorated differently by accidental type-constraints or |
1298 source position information, for example.} |
1252 source position information, for example.} |
1299 |
1253 |
1300 \<^item> Every variable in @{text "rhs"} must also occur in @{text |
1254 \item Every variable in @{text "rhs"} must also occur in @{text |
1301 "lhs"}. |
1255 "lhs"}. |
1302 |
1256 |
1303 \end{itemize} |
1257 \end{itemize} |
1304 |
1258 |
1305 \<^descr> @{command "no_translations"}~@{text rules} removes syntactic |
1259 \<^descr> @{command "no_translations"}~@{text rules} removes syntactic |
1306 translation rules, which are interpreted in the same manner as for |
1260 translation rules, which are interpreted in the same manner as for |
1309 \<^descr> @{attribute syntax_ast_trace} and @{attribute |
1263 \<^descr> @{attribute syntax_ast_trace} and @{attribute |
1310 syntax_ast_stats} control diagnostic output in the AST normalization |
1264 syntax_ast_stats} control diagnostic output in the AST normalization |
1311 process, when translation rules are applied to concrete input or |
1265 process, when translation rules are applied to concrete input or |
1312 output. |
1266 output. |
1313 |
1267 |
1314 \end{description} |
|
1315 |
1268 |
1316 Raw syntax and translations provides a slightly more low-level |
1269 Raw syntax and translations provides a slightly more low-level |
1317 access to the grammar and the form of resulting parse trees. It is |
1270 access to the grammar and the form of resulting parse trees. It is |
1318 often possible to avoid this untyped macro mechanism, and use |
1271 often possible to avoid this untyped macro mechanism, and use |
1319 type-safe @{command abbreviation} or @{command notation} instead. |
1272 type-safe @{command abbreviation} or @{command notation} instead. |
1320 Some important situations where @{command syntax} and @{command |
1273 Some important situations where @{command syntax} and @{command |
1321 translations} are really need are as follows: |
1274 translations} are really need are as follows: |
1322 |
1275 |
1323 \begin{itemize} |
|
1324 |
|
1325 \<^item> Iterated replacement via recursive @{command translations}. |
1276 \<^item> Iterated replacement via recursive @{command translations}. |
1326 For example, consider list enumeration @{term "[a, b, c, d]"} as |
1277 For example, consider list enumeration @{term "[a, b, c, d]"} as |
1327 defined in theory @{theory List} in Isabelle/HOL. |
1278 defined in theory @{theory List} in Isabelle/HOL. |
1328 |
1279 |
1329 \<^item> Change of binding status of variables: anything beyond the |
1280 \<^item> Change of binding status of variables: anything beyond the |
1330 built-in @{keyword "binder"} mixfix annotation requires explicit |
1281 built-in @{keyword "binder"} mixfix annotation requires explicit |
1331 syntax translations. For example, consider list filter |
1282 syntax translations. For example, consider list filter |
1332 comprehension @{term "[x \<leftarrow> xs . P]"} as defined in theory @{theory |
1283 comprehension @{term "[x \<leftarrow> xs . P]"} as defined in theory @{theory |
1333 List} in Isabelle/HOL. |
1284 List} in Isabelle/HOL. |
1334 |
1285 \<close> |
1335 \end{itemize} |
1286 |
1336 \<close> |
|
1337 |
1287 |
1338 subsubsection \<open>Applying translation rules\<close> |
1288 subsubsection \<open>Applying translation rules\<close> |
1339 |
1289 |
1340 text \<open>As a term is being parsed or printed, an AST is generated as |
1290 text \<open>As a term is being parsed or printed, an AST is generated as |
1341 an intermediate form according to \figref{fig:parse-print}. The AST |
1291 an intermediate form according to \figref{fig:parse-print}. The AST |