src/Pure/sign.ML
changeset 952 9e10962866b0
parent 949 83c588d6fee9
child 959 35c2e5e114c4
equal deleted inserted replaced
951:682139612060 952:9e10962866b0
   270     val T' = certify_typ sg T
   270     val T' = certify_typ sg T
   271              handle TYPE arg => error (exn_type_msg arg);
   271              handle TYPE arg => error (exn_type_msg arg);
   272 
   272 
   273     val ct = const_type sg;
   273     val ct = const_type sg;
   274 
   274 
   275     fun process_terms (t::ts) (idx, infrd_t, tye) msg n =
   275     fun warn() =
   276          let val (infrd_t', tye', msg') = 
   276       if length ts > 1 andalso length ts <= !Syntax.ambiguity_level
   277               let val (T,tye) =
   277       then (*no warning shown yet*)
   278                     Type.infer_types(tsig,ct,types,sorts,used,freeze,T',t)
   278            writeln "Warning: Currently parsed input \
   279               in (Some T, Some tye, msg) end
   279                    \produces more than one parse tree.\n\
   280               handle TYPE arg => (None, None, exn_type_msg arg)
   280                    \For more information lower Syntax.ambiguity_level."
   281 
   281       else ();
   282              val old_show_brackets = !show_brackets;
   282 
   283 
   283     datatype result = One of int * term * (indexname * typ) list
   284              val _ = (show_brackets := true);
   284                     | Errs of (string * typ list * term list)list
   285 
   285                     | Ambigs of term list;
   286              val msg'' = 
   286 
   287                if is_none idx then (if is_none infrd_t' then msg' else "")
   287     fun process_term(res,(t,i)) =
   288                else if is_none infrd_t' then "" 
   288        let val (u,tye) = Type.infer_types(tsig,ct,types,sorts,used,freeze,T',t)
   289                else (if msg' = "" then 
   289        in case res of
   290                 "Error: More than one term is type correct:\n" ^
   290             One(_,t0,_) => Ambigs([u,t0])
   291                 (show_term (the infrd_t)) else msg') ^ "\n" ^ 
   291           | Errs _ => One(i,u,tye)
   292                 (show_term (the infrd_t')) ^ "\n";
   292           | Ambigs(us) => Ambigs(u::us)
   293 
   293        end
   294          in show_brackets := old_show_brackets;
   294        handle TYPE arg => (case res of Errs(errs) => Errs(arg::errs)
   295             if is_none infrd_t' then
   295                                      | _ => res);
   296               process_terms ts (idx, infrd_t, tye) msg'' (n+1)
   296 
   297             else
   297   in case foldl process_term (Errs[], ts ~~ (0 upto (length ts - 1))) of
   298               process_terms ts (Some n, infrd_t', tye') msg'' (n+1)
   298        One(res) =>
   299          end
   299          (if length ts > !Syntax.ambiguity_level
   300       | process_terms [] (idx, infrd_t, tye) msg _ = 
   300           then writeln "Fortunately, only one parse tree is type correct.\n\
   301           if msg = "" then (the idx, the infrd_t, the tye) 
   301             \It helps (speed!) if you disambiguate your grammar or your input."
   302           else
   302           else ();
   303             (if length ts > 1 andalso length ts <= !Syntax.ambiguity_level then
   303           res)
   304                                                       (*no warning shown yet?*)
   304      | Errs(errs) => (warn(); error(cat_lines(map exn_type_msg errs)))
   305                writeln "Warning: Currently parsed input \
   305      | Ambigs(us) =>
   306                        \produces more than one parse tree.\n\
   306          (warn();
   307                        \For more information lower Syntax.ambiguity_level."
   307           let val old_show_brackets = !show_brackets
   308              else ();
   308               val _ = show_brackets := true;
   309              error msg)
   309               val errs = cat_lines(map show_term us)
   310 
   310           in show_brackets := old_show_brackets;
   311     val (idx, infrd_t, tye) = process_terms ts (None, None, None) "" 0;
   311              error("Error: More than one term is type correct:\n" ^ errs)
   312   in if print_msg andalso length ts > !Syntax.ambiguity_level then
   312           end)
   313        writeln "Fortunately, only one parse tree is type correct.\n\
   313   end;
   314          \It helps (speed!) if you disambiguate your grammar or your input."
       
   315      else ();
       
   316      (idx, infrd_t, tye)
       
   317   end;
       
   318 
       
   319 
   314 
   320 
   315 
   321 (** extend signature **)    (*exception ERROR*)
   316 (** extend signature **)    (*exception ERROR*)
   322 
   317 
   323 (** signature extension functions **)  (*exception ERROR*)
   318 (** signature extension functions **)  (*exception ERROR*)