734 |
734 |
735 (** inner syntax operations **) |
735 (** inner syntax operations **) |
736 |
736 |
737 local |
737 local |
738 |
738 |
|
739 fun parse_failed ctxt pos msg kind = |
|
740 (Context_Position.report ctxt Markup.bad pos; |
|
741 cat_error msg ("Failed to parse " ^ kind)); |
|
742 |
739 fun parse_sort ctxt text = |
743 fun parse_sort ctxt text = |
740 let |
744 let |
741 val (syms, pos) = Syntax.parse_token ctxt Markup.sort text; |
745 val (syms, pos) = Syntax.parse_token ctxt Markup.sort text; |
742 val S = Syntax.standard_parse_sort ctxt (syn_of ctxt) (syms, pos) |
746 val S = Syntax.standard_parse_sort ctxt (syn_of ctxt) (syms, pos) |
743 handle ERROR msg => cat_error msg "Failed to parse sort"; |
747 handle ERROR msg => parse_failed ctxt pos msg "sort"; |
744 in Type.minimize_sort (tsig_of ctxt) S end; |
748 in Type.minimize_sort (tsig_of ctxt) S end; |
745 |
749 |
746 fun parse_typ ctxt text = |
750 fun parse_typ ctxt text = |
747 let |
751 let |
748 val (syms, pos) = Syntax.parse_token ctxt Markup.typ text; |
752 val (syms, pos) = Syntax.parse_token ctxt Markup.typ text; |
749 val T = Syntax.standard_parse_typ ctxt (syn_of ctxt) (get_sort ctxt) (syms, pos) |
753 val T = Syntax.standard_parse_typ ctxt (syn_of ctxt) (get_sort ctxt) (syms, pos) |
750 handle ERROR msg => cat_error msg "Failed to parse type"; |
754 handle ERROR msg => parse_failed ctxt pos msg "type"; |
751 in T end; |
755 in T end; |
752 |
756 |
753 fun parse_term T ctxt text = |
757 fun parse_term T ctxt text = |
754 let |
758 let |
755 val {get_sort, map_const, map_free} = term_context ctxt; |
759 val {get_sort, map_const, map_free} = term_context ctxt; |
762 fun check t = (Syntax.check_term ctxt (Type_Infer.constrain T' t); NONE) |
766 fun check t = (Syntax.check_term ctxt (Type_Infer.constrain T' t); NONE) |
763 handle ERROR msg => SOME msg; |
767 handle ERROR msg => SOME msg; |
764 val t = |
768 val t = |
765 Syntax.standard_parse_term check get_sort map_const map_free |
769 Syntax.standard_parse_term check get_sort map_const map_free |
766 ctxt (Type.is_logtype (tsig_of ctxt)) (syn_of ctxt) T' (syms, pos) |
770 ctxt (Type.is_logtype (tsig_of ctxt)) (syn_of ctxt) T' (syms, pos) |
767 handle ERROR msg => cat_error msg ("Failed to parse " ^ kind); |
771 handle ERROR msg => parse_failed ctxt pos msg kind; |
768 in t end; |
772 in t end; |
769 |
773 |
770 |
774 |
771 fun unparse_sort ctxt = |
775 fun unparse_sort ctxt = |
772 Syntax.standard_unparse_sort {extern_class = Type.extern_class (tsig_of ctxt)} |
776 Syntax.standard_unparse_sort {extern_class = Type.extern_class (tsig_of ctxt)} |