137 val Type (c, _) = Proof_Context.read_type_name_proper ctxt false s; |
137 val Type (c, _) = Proof_Context.read_type_name_proper ctxt false s; |
138 val decl = Type.the_decl (Proof_Context.tsig_of ctxt) (c, pos); |
138 val decl = Type.the_decl (Proof_Context.tsig_of ctxt) (c, pos); |
139 val res = |
139 val res = |
140 (case try check (c, decl) of |
140 (case try check (c, decl) of |
141 SOME res => res |
141 SOME res => res |
142 | NONE => error ("Not a " ^ kind ^ ": " ^ quote c ^ Position.str_of pos)); |
142 | NONE => error ("Not a " ^ kind ^ ": " ^ quote c ^ Position.here pos)); |
143 in ML_Syntax.print_string res end); |
143 in ML_Syntax.print_string res end); |
144 |
144 |
145 val _ = Context.>> (Context.map_theory |
145 val _ = Context.>> (Context.map_theory |
146 (inline (Binding.name "type_name") |
146 (inline (Binding.name "type_name") |
147 (type_name "logical type" (fn (c, Type.LogicalType _) => c)) #> |
147 (type_name "logical type" (fn (c, Type.LogicalType _) => c)) #> |
158 fun const_name check = Args.context -- Scan.lift (Parse.position Args.name_source) |
158 fun const_name check = Args.context -- Scan.lift (Parse.position Args.name_source) |
159 >> (fn (ctxt, (s, pos)) => |
159 >> (fn (ctxt, (s, pos)) => |
160 let |
160 let |
161 val Const (c, _) = Proof_Context.read_const_proper ctxt false s; |
161 val Const (c, _) = Proof_Context.read_const_proper ctxt false s; |
162 val res = check (Proof_Context.consts_of ctxt, c) |
162 val res = check (Proof_Context.consts_of ctxt, c) |
163 handle TYPE (msg, _, _) => error (msg ^ Position.str_of pos); |
163 handle TYPE (msg, _, _) => error (msg ^ Position.here pos); |
164 in ML_Syntax.print_string res end); |
164 in ML_Syntax.print_string res end); |
165 |
165 |
166 val _ = Context.>> (Context.map_theory |
166 val _ = Context.>> (Context.map_theory |
167 (inline (Binding.name "const_name") |
167 (inline (Binding.name "const_name") |
168 (const_name (fn (consts, c) => (Consts.the_const consts c; c))) #> |
168 (const_name (fn (consts, c) => (Consts.the_const consts c; c))) #> |
173 |
173 |
174 inline (Binding.name "syntax_const") |
174 inline (Binding.name "syntax_const") |
175 (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (c, pos)) => |
175 (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (c, pos)) => |
176 if is_some (Syntax.lookup_const (Proof_Context.syn_of ctxt) c) |
176 if is_some (Syntax.lookup_const (Proof_Context.syn_of ctxt) c) |
177 then ML_Syntax.print_string c |
177 then ML_Syntax.print_string c |
178 else error ("Unknown syntax const: " ^ quote c ^ Position.str_of pos))) #> |
178 else error ("Unknown syntax const: " ^ quote c ^ Position.here pos))) #> |
179 |
179 |
180 inline (Binding.name "const") |
180 inline (Binding.name "const") |
181 (Args.context -- Scan.lift Args.name_source -- Scan.optional |
181 (Args.context -- Scan.lift Args.name_source -- Scan.optional |
182 (Scan.lift (Args.$$$ "(") |-- Parse.enum1' "," Args.typ --| Scan.lift (Args.$$$ ")")) [] |
182 (Scan.lift (Args.$$$ "(") |-- Parse.enum1' "," Args.typ --| Scan.lift (Args.$$$ ")")) [] |
183 >> (fn ((ctxt, raw_c), Ts) => |
183 >> (fn ((ctxt, raw_c), Ts) => |
195 (* outer syntax *) |
195 (* outer syntax *) |
196 |
196 |
197 fun with_keyword f = |
197 fun with_keyword f = |
198 Args.theory -- Scan.lift (Parse.position Parse.string) >> (fn (thy, (name, pos)) => |
198 Args.theory -- Scan.lift (Parse.position Parse.string) >> (fn (thy, (name, pos)) => |
199 (f ((name, Thy_Header.the_keyword thy name), pos) |
199 (f ((name, Thy_Header.the_keyword thy name), pos) |
200 handle ERROR msg => error (msg ^ Position.str_of pos))); |
200 handle ERROR msg => error (msg ^ Position.here pos))); |
201 |
201 |
202 val _ = Context.>> (Context.map_theory |
202 val _ = Context.>> (Context.map_theory |
203 (value (Binding.name "keyword") |
203 (value (Binding.name "keyword") |
204 (with_keyword |
204 (with_keyword |
205 (fn ((name, NONE), _) => "Parse.$$$ " ^ ML_Syntax.print_string name |
205 (fn ((name, NONE), _) => "Parse.$$$ " ^ ML_Syntax.print_string name |
206 | ((name, SOME _), pos) => |
206 | ((name, SOME _), pos) => |
207 error ("Expected minor keyword " ^ quote name ^ Position.str_of pos))) #> |
207 error ("Expected minor keyword " ^ quote name ^ Position.here pos))) #> |
208 value (Binding.name "command_spec") |
208 value (Binding.name "command_spec") |
209 (with_keyword |
209 (with_keyword |
210 (fn ((name, SOME kind), pos) => |
210 (fn ((name, SOME kind), pos) => |
211 "Keyword.command_spec " ^ ML_Syntax.atomic |
211 "Keyword.command_spec " ^ ML_Syntax.atomic |
212 ((ML_Syntax.print_pair |
212 ((ML_Syntax.print_pair |
215 (ML_Syntax.print_pair ML_Syntax.print_string |
215 (ML_Syntax.print_pair ML_Syntax.print_string |
216 (ML_Syntax.print_list ML_Syntax.print_string)) |
216 (ML_Syntax.print_list ML_Syntax.print_string)) |
217 (ML_Syntax.print_list ML_Syntax.print_string))) |
217 (ML_Syntax.print_list ML_Syntax.print_string))) |
218 ML_Syntax.print_position) ((name, kind), pos)) |
218 ML_Syntax.print_position) ((name, kind), pos)) |
219 | ((name, NONE), pos) => |
219 | ((name, NONE), pos) => |
220 error ("Expected command keyword " ^ quote name ^ Position.str_of pos))))); |
220 error ("Expected command keyword " ^ quote name ^ Position.here pos))))); |
221 |
221 |
222 end; |
222 end; |
223 |
223 |