46 Some specification package might thus intercept syntax processing at |
46 Some specification package might thus intercept syntax processing at |
47 a well-defined stage after @{text "parse"}, to a augment the |
47 a well-defined stage after @{text "parse"}, to a augment the |
48 resulting pre-term before full type-reconstruction is performed by |
48 resulting pre-term before full type-reconstruction is performed by |
49 @{text "check"}, for example. Note that the formal status of bound |
49 @{text "check"}, for example. Note that the formal status of bound |
50 variables, versus free variables, versus constants must not be |
50 variables, versus free variables, versus constants must not be |
51 changed between these phases! *} |
51 changed between these phases! |
|
52 |
|
53 \medskip In general, @{text check} and @{text uncheck} operate |
|
54 simultaneously on a list of terms. This is particular important for |
|
55 type-checking, to reconstruct types for several terms of the same context |
|
56 and scope. In contrast, @{text parse} and @{text unparse} operate separately |
|
57 in single terms. |
|
58 |
|
59 There are analogous operations to read and print types, with the same |
|
60 sub-division into phases. |
|
61 *} |
52 |
62 |
53 |
63 |
54 section {* Reading and pretty printing \label{sec:read-print} *} |
64 section {* Reading and pretty printing \label{sec:read-print} *} |
55 |
65 |
56 text {* Read and print operations are roughly dual to each other, such |
66 text {* Read and print operations are roughly dual to each other, such |
62 (pretty t)"} might fail, or produce a differently typed term, or a |
72 (pretty t)"} might fail, or produce a differently typed term, or a |
63 completely different term in the face of syntactic overloading! *} |
73 completely different term in the face of syntactic overloading! *} |
64 |
74 |
65 text %mlref {* |
75 text %mlref {* |
66 \begin{mldecls} |
76 \begin{mldecls} |
|
77 @{index_ML Syntax.read_typs: "Proof.context -> string list -> typ list"} \\ |
|
78 @{index_ML Syntax.read_terms: "Proof.context -> string list -> term list"} \\ |
|
79 @{index_ML Syntax.read_props: "Proof.context -> string list -> term list"} \\[0.5ex] |
67 @{index_ML Syntax.read_typ: "Proof.context -> string -> typ"} \\ |
80 @{index_ML Syntax.read_typ: "Proof.context -> string -> typ"} \\ |
68 @{index_ML Syntax.read_term: "Proof.context -> string -> term"} \\ |
81 @{index_ML Syntax.read_term: "Proof.context -> string -> term"} \\ |
69 @{index_ML Syntax.read_prop: "Proof.context -> string -> term"} \\ |
82 @{index_ML Syntax.read_prop: "Proof.context -> string -> term"} \\[0.5ex] |
70 @{index_ML Syntax.pretty_typ: "Proof.context -> typ -> Pretty.T"} \\ |
83 @{index_ML Syntax.pretty_typ: "Proof.context -> typ -> Pretty.T"} \\ |
71 @{index_ML Syntax.pretty_term: "Proof.context -> term -> Pretty.T"} \\ |
84 @{index_ML Syntax.pretty_term: "Proof.context -> term -> Pretty.T"} \\ |
|
85 @{index_ML Syntax.string_of_typ: "Proof.context -> typ -> string"} \\ |
|
86 @{index_ML Syntax.string_of_term: "Proof.context -> term -> string"} \\ |
72 \end{mldecls} |
87 \end{mldecls} |
73 |
88 |
74 %FIXME description |
89 \begin{description} |
|
90 |
|
91 \item @{ML Syntax.read_typs}~@{text "ctxt strs"} reads and checks a |
|
92 simultaneous list of source strings as types of the logic. |
|
93 |
|
94 \item @{ML Syntax.read_terms}~@{text "ctxt strs"} reads and checks a |
|
95 simultaneous list of source strings as terms of the logic. |
|
96 Type-reconstruction puts all parsed terms into the same scope. |
|
97 |
|
98 If particular type-constraints are required for some of the arguments, the |
|
99 read operations needs to be split into its parse and check phases, using |
|
100 @{ML Type.constraint} on the intermediate pre-terms. |
|
101 |
|
102 \item @{ML Syntax.read_props} ~@{text "ctxt strs"} reads and checks a |
|
103 simultaneous list of source strings as propositions of the logic, with an |
|
104 implicit type-constraint for each argument to make it of type @{typ prop}; |
|
105 this also affects the inner syntax for parsing. The remaining |
|
106 type-reconstructions works as for @{ML Syntax.read_terms} above. |
|
107 |
|
108 \item @{ML Syntax.read_typ}, @{ML Syntax.read_term}, @{ML Syntax.read_prop} |
|
109 are like the simultaneous versions above, but operate on a single argument |
|
110 only. This convenient shorthand is adequate in situations where a single |
|
111 item in its own scope is processed. Never use @{ML "map o Syntax.read_term"} |
|
112 where @{ML Syntax.read_terms} is actually intended! |
|
113 |
|
114 \item @{ML Syntax.pretty_typ}~@{text "ctxt T"} and @{ML |
|
115 Syntax.pretty_term}~@{text "ctxt t"} uncheck and pretty-print the given type |
|
116 or term, respectively. Although the uncheck phase acts on a simultaneous |
|
117 list as well, this is rarely relevant in practice, so only the singleton |
|
118 case is provided as combined pretty operation. Moreover, the distinction of |
|
119 term vs.\ proposition is ignored here. |
|
120 |
|
121 \item @{ML Syntax.string_of_typ} and @{ML Syntax.string_of_term} are |
|
122 convenient compositions of @{ML Syntax.pretty_typ} and @{ML |
|
123 Syntax.pretty_term} with @{ML Pretty.string_of} for output. The result may |
|
124 be concatenated with other strings, as long as there is no further |
|
125 formatting and line-breaking involved. |
|
126 |
|
127 \end{description} |
|
128 |
|
129 The most important operations in practice are @{ML Syntax.read_term}, @{ML |
|
130 Syntax.read_prop}, and @{ML Syntax.string_of_term}. |
|
131 |
|
132 \medskip Note that the string values that are passed in and out here are |
|
133 actually annotated by the system, to carry further markup that is relevant |
|
134 for the Prover IDE \cite{isabelle-jedit}. User code should neither compose |
|
135 its own strings for input, nor try to analyze the string for output. |
|
136 |
|
137 The standard way to provide the required position markup for input works via |
|
138 the outer syntax parser wrapper @{ML Parse.inner_syntax}, which is already |
|
139 part of @{ML Parse.typ}, @{ML Parse.term}, @{ML Parse.prop}. So a string |
|
140 obtained from one of the latter may be directly passed to the corresponding |
|
141 read operation, in order to get PIDE markup of the input and precise |
|
142 positions for warnings and errors. |
75 *} |
143 *} |
76 |
144 |
77 |
145 |
78 section {* Parsing and unparsing \label{sec:parse-unparse} *} |
146 section {* Parsing and unparsing \label{sec:parse-unparse} *} |
79 |
147 |