62 val basic_nonterms: string list |
62 val basic_nonterms: string list |
63 val print_gram: syntax -> unit |
63 val print_gram: syntax -> unit |
64 val print_trans: syntax -> unit |
64 val print_trans: syntax -> unit |
65 val print_syntax: syntax -> unit |
65 val print_syntax: syntax -> unit |
66 val read: Proof.context -> (string -> bool) -> syntax -> typ -> string -> term list |
66 val read: Proof.context -> (string -> bool) -> syntax -> typ -> string -> term list |
67 val standard_parse_term: Pretty.pp -> (term -> term Exn.result) -> |
67 val standard_parse_term: Pretty.pp -> (term -> string option) -> |
68 (((string * int) * sort) list -> string * int -> Term.sort) -> |
68 (((string * int) * sort) list -> string * int -> Term.sort) -> |
69 (string -> string option) -> (string -> string option) -> |
69 (string -> string option) -> (string -> string option) -> |
70 (typ -> typ) -> (sort -> sort) -> Proof.context -> |
70 (typ -> typ) -> (sort -> sort) -> Proof.context -> |
71 (string -> bool) -> syntax -> typ -> string -> term |
71 (string -> bool) -> syntax -> typ -> string -> term |
72 val standard_parse_typ: Proof.context -> syntax -> |
72 val standard_parse_typ: Proof.context -> syntax -> |
471 |
471 |
472 (*brute-force disambiguation via type-inference*) |
472 (*brute-force disambiguation via type-inference*) |
473 fun disambig _ _ [t] = t |
473 fun disambig _ _ [t] = t |
474 | disambig pp check ts = |
474 | disambig pp check ts = |
475 let |
475 let |
476 val err_results = map check ts; |
476 val errs = map check ts; |
477 val errs = map_filter (fn Exn.Exn (ERROR msg) => SOME msg | _ => NONE) err_results; |
477 val results = map_filter (fn (t, NONE) => SOME t | _ => NONE) (ts ~~ errs); |
478 val results = map_filter Exn.get_result err_results; |
|
479 |
478 |
480 val ambiguity = length ts; |
479 val ambiguity = length ts; |
481 fun ambig_msg () = |
480 fun ambig_msg () = |
482 if ambiguity > 1 andalso ambiguity <= ! ambiguity_level then |
481 if ambiguity > 1 andalso ambiguity <= ! ambiguity_level then |
483 "Got more than one parse tree.\n\ |
482 "Got more than one parse tree.\n\ |
484 \Retry with smaller ambiguity_level for more information." |
483 \Retry with smaller ambiguity_level for more information." |
485 else ""; |
484 else ""; |
486 in |
485 in |
487 if null results then cat_error (ambig_msg ()) (cat_lines errs) |
486 if null results then cat_error (ambig_msg ()) (cat_lines (map_filter I errs)) |
488 else if length results = 1 then |
487 else if length results = 1 then |
489 (if ambiguity > ! ambiguity_level then |
488 (if ambiguity > ! ambiguity_level then |
490 warning "Fortunately, only one parse tree is type correct.\n\ |
489 warning "Fortunately, only one parse tree is type correct.\n\ |
491 \You may still want to disambiguate your grammar or your input." |
490 \You may still want to disambiguate your grammar or your input." |
492 else (); hd results) |
491 else (); hd results) |