409 fold_map inferred_param (rev (map #2 (Variable.fixes_of ctxt))) ctxt; |
409 fold_map inferred_param (rev (map #2 (Variable.fixes_of ctxt))) ctxt; |
410 |
410 |
411 |
411 |
412 (* type and constant names *) |
412 (* type and constant names *) |
413 |
413 |
414 fun read_tyname ctxt c = |
414 local |
415 if Syntax.is_tid c then |
415 |
416 TFree (c, the_default (Sign.defaultS (theory_of ctxt)) (Variable.def_sort ctxt (c, ~1))) |
416 val token_content = Syntax.read_token #>> SymbolPos.content; |
417 else |
417 |
418 let |
418 fun prep_const_proper ctxt (c, pos) = |
419 val thy = theory_of ctxt; |
419 let val t as (Const (d, _)) = |
420 val d = Sign.intern_type thy c; |
420 (case Variable.lookup_const ctxt c of |
421 in Type (d, replicate (Sign.arity_number thy d) dummyT) end; |
421 SOME d => Const (d, Consts.type_scheme (consts_of ctxt) d handle TYPE (msg, _, _) => error msg) |
422 |
422 | NONE => Consts.read_const (consts_of ctxt) c) |
423 fun read_const_proper ctxt c = |
423 in Position.report (Markup.const d) pos; t end; |
424 (case Variable.lookup_const ctxt c of |
424 |
425 SOME d => Const (d, Consts.type_scheme (consts_of ctxt) d handle TYPE (msg, _, _) => error msg) |
425 in |
426 | NONE => Consts.read_const (consts_of ctxt) c); |
426 |
427 |
427 fun read_tyname ctxt str = |
428 fun read_const ctxt c = |
428 let |
429 (case (lookup_skolem ctxt c, Variable.is_const ctxt c) of |
429 val thy = theory_of ctxt; |
430 (SOME x, false) => Free (x, infer_type ctxt x) |
430 val (c, pos) = token_content str; |
431 | _ => read_const_proper ctxt c); |
431 in |
|
432 if Syntax.is_tid c then |
|
433 (Position.report Markup.tfree pos; |
|
434 TFree (c, the_default (Sign.defaultS thy) (Variable.def_sort ctxt (c, ~1)))) |
|
435 else |
|
436 let |
|
437 val d = Sign.intern_type thy c; |
|
438 val _ = Position.report (Markup.tycon d) pos; |
|
439 in Type (d, replicate (Sign.arity_number thy d) dummyT) end |
|
440 end; |
|
441 |
|
442 fun read_const_proper ctxt = prep_const_proper ctxt o token_content; |
|
443 |
|
444 fun read_const ctxt str = |
|
445 let val (c, pos) = token_content str in |
|
446 (case (lookup_skolem ctxt c, Variable.is_const ctxt c) of |
|
447 (SOME x, false) => |
|
448 (Position.report (Markup.name x |
|
449 (if can Name.dest_skolem x then Markup.skolem else Markup.free)) pos; |
|
450 Free (x, infer_type ctxt x)) |
|
451 | _ => prep_const_proper ctxt (c, pos)) |
|
452 end; |
|
453 |
|
454 end; |
432 |
455 |
433 |
456 |
434 (* read_term *) |
457 (* read_term *) |
435 |
458 |
436 fun read_term_mode mode ctxt = Syntax.read_term (set_mode mode ctxt); |
459 fun read_term_mode mode ctxt = Syntax.read_term (set_mode mode ctxt); |
637 |
660 |
638 (** inner syntax operations **) |
661 (** inner syntax operations **) |
639 |
662 |
640 local |
663 local |
641 |
664 |
642 fun parse_token markup str = |
|
643 let |
|
644 val (syms, pos) = Syntax.read_token str; |
|
645 val _ = Position.report markup pos; |
|
646 in (syms, pos) end; |
|
647 |
|
648 fun parse_sort ctxt text = |
665 fun parse_sort ctxt text = |
649 let |
666 let |
650 val (syms, pos) = parse_token Markup.sort text; |
667 val (syms, pos) = Syntax.parse_token Markup.sort text; |
651 val S = Syntax.standard_parse_sort ctxt (syn_of ctxt) |
668 val S = Syntax.standard_parse_sort ctxt (syn_of ctxt) |
652 (Sign.intern_sort (theory_of ctxt)) (syms, pos) |
669 (Sign.intern_sort (theory_of ctxt)) (syms, pos) |
653 handle ERROR msg => cat_error msg ("Failed to parse sort" ^ Position.str_of pos) |
670 handle ERROR msg => cat_error msg ("Failed to parse sort" ^ Position.str_of pos) |
654 in S end; |
671 in S end; |
655 |
672 |
656 fun parse_typ ctxt text = |
673 fun parse_typ ctxt text = |
657 let |
674 let |
658 val thy = ProofContext.theory_of ctxt; |
675 val thy = ProofContext.theory_of ctxt; |
659 val get_sort = get_sort thy (Variable.def_sort ctxt); |
676 val get_sort = get_sort thy (Variable.def_sort ctxt); |
660 |
677 |
661 val (syms, pos) = parse_token Markup.typ text; |
678 val (syms, pos) = Syntax.parse_token Markup.typ text; |
662 val T = Sign.intern_tycons thy |
679 val T = Sign.intern_tycons thy |
663 (Syntax.standard_parse_typ ctxt (syn_of ctxt) get_sort (Sign.intern_sort thy) (syms, pos)) |
680 (Syntax.standard_parse_typ ctxt (syn_of ctxt) get_sort (Sign.intern_sort thy) (syms, pos)) |
664 handle ERROR msg => cat_error msg ("Failed to parse type" ^ Position.str_of pos); |
681 handle ERROR msg => cat_error msg ("Failed to parse type" ^ Position.str_of pos); |
665 in T end; |
682 in T end; |
666 |
683 |
668 let |
685 let |
669 val thy = theory_of ctxt; |
686 val thy = theory_of ctxt; |
670 val {get_sort, map_const, map_free, map_type, map_sort} = term_context ctxt; |
687 val {get_sort, map_const, map_free, map_type, map_sort} = term_context ctxt; |
671 |
688 |
672 val (T', _) = TypeInfer.paramify_dummies T 0; |
689 val (T', _) = TypeInfer.paramify_dummies T 0; |
673 val markup as (kind, _) = if T' = propT then Markup.proposition else Markup.term; |
690 val (markup, kind) = if T' = propT then (Markup.prop, "proposition") else (Markup.term, "term"); |
674 val (syms, pos) = parse_token markup text; |
691 val (syms, pos) = Syntax.parse_token markup text; |
675 |
692 |
676 fun check t = (Syntax.check_term ctxt (TypeInfer.constrain T' t); NONE) |
693 fun check t = (Syntax.check_term ctxt (TypeInfer.constrain T' t); NONE) |
677 handle ERROR msg => SOME msg; |
694 handle ERROR msg => SOME msg; |
678 val t = Syntax.standard_parse_term (Syntax.pp ctxt) check get_sort map_const map_free |
695 val t = Syntax.standard_parse_term (Syntax.pp ctxt) check get_sort map_const map_free |
679 map_type map_sort ctxt (Sign.is_logtype thy) (syn_of ctxt) T' (syms, pos) |
696 map_type map_sort ctxt (Sign.is_logtype thy) (syn_of ctxt) T' (syms, pos) |
871 let |
888 let |
872 val thy = theory_of ctxt; |
889 val thy = theory_of ctxt; |
873 val local_facts = facts_of ctxt; |
890 val local_facts = facts_of ctxt; |
874 val thmref = Facts.map_name_of_ref (Facts.intern local_facts) xthmref; |
891 val thmref = Facts.map_name_of_ref (Facts.intern local_facts) xthmref; |
875 val name = Facts.name_of_ref thmref; |
892 val name = Facts.name_of_ref thmref; |
|
893 val pos = Facts.pos_of_ref xthmref; |
876 val thms = |
894 val thms = |
877 if name = "" then [Thm.transfer thy Drule.dummy_thm] |
895 if name = "" then [Thm.transfer thy Drule.dummy_thm] |
878 else |
896 else |
879 (case Facts.lookup (Context.Proof ctxt) local_facts name of |
897 (case Facts.lookup (Context.Proof ctxt) local_facts name of |
880 SOME (_, ths) => map (Thm.transfer thy) (Facts.select thmref ths) |
898 SOME (_, ths) => (Position.report (Markup.local_fact name) pos; |
|
899 map (Thm.transfer thy) (Facts.select thmref ths)) |
881 | NONE => PureThy.get_fact (Context.Proof ctxt) thy xthmref); |
900 | NONE => PureThy.get_fact (Context.Proof ctxt) thy xthmref); |
882 in pick name thms end; |
901 in pick name thms end; |
883 |
902 |
884 in |
903 in |
885 |
904 |