merged;
authorwenzelm
Tue Mar 18 21:02:33 2014 +0100 (2014-03-18)
changeset 562113250d70c8d0b
parent 56196 32b7eafc5a52
parent 56210 c7c85cdb725d
child 56212 3253aaf73a01
merged;
src/Pure/System/session.ML
src/Pure/System/session.scala
src/Pure/Thy/thy_load.ML
src/Pure/Thy/thy_load.scala
src/Tools/jEdit/src/jedit_thy_load.scala
     1.1 --- a/NEWS	Tue Mar 18 09:39:07 2014 -0700
     1.2 +++ b/NEWS	Tue Mar 18 21:02:33 2014 +0100
     1.3 @@ -465,10 +465,8 @@
     1.4  theory merge).  Note that the softer Thm.eq_thm_prop is often more
     1.5  appropriate than Thm.eq_thm.
     1.6  
     1.7 -* Simplified programming interface to define ML antiquotations (to
     1.8 -make it more close to the analogous Thy_Output.antiquotation).  See
     1.9 -ML_Context.antiquotation and structure ML_Antiquotation.  Minor
    1.10 -INCOMPATIBILITY.
    1.11 +* Simplified programming interface to define ML antiquotations, see
    1.12 +structure ML_Antiquotation.  Minor INCOMPATIBILITY.
    1.13  
    1.14  * ML antiquotation @{here} refers to its source position, which is
    1.15  occasionally useful for experimentation and diagnostic purposes.
     2.1 --- a/src/CCL/CCL.thy	Tue Mar 18 09:39:07 2014 -0700
     2.2 +++ b/src/CCL/CCL.thy	Tue Mar 18 21:02:33 2014 +0100
     2.3 @@ -295,9 +295,9 @@
     2.4  val XH_to_Ds = map XH_to_D
     2.5  val XH_to_Es = map XH_to_E;
     2.6  
     2.7 -bind_thms ("ccl_rews", @{thms caseBs} @ @{thms ccl_injs} @ ccl_dstncts);
     2.8 -bind_thms ("ccl_dstnctsEs", ccl_dstncts RL [@{thm notE}]);
     2.9 -bind_thms ("ccl_injDs", XH_to_Ds @{thms ccl_injs});
    2.10 +ML_Thms.bind_thms ("ccl_rews", @{thms caseBs} @ @{thms ccl_injs} @ ccl_dstncts);
    2.11 +ML_Thms.bind_thms ("ccl_dstnctsEs", ccl_dstncts RL [@{thm notE}]);
    2.12 +ML_Thms.bind_thms ("ccl_injDs", XH_to_Ds @{thms ccl_injs});
    2.13  *}
    2.14  
    2.15  lemmas [simp] = ccl_rews
     3.1 --- a/src/CCL/Term.thy	Tue Mar 18 09:39:07 2014 -0700
     3.2 +++ b/src/CCL/Term.thy	Tue Mar 18 21:02:33 2014 +0100
     3.3 @@ -286,7 +286,7 @@
     3.4  subsection {* Constructors are distinct *}
     3.5  
     3.6  ML {*
     3.7 -bind_thms ("term_dstncts",
     3.8 +ML_Thms.bind_thms ("term_dstncts",
     3.9    mkall_dstnct_thms @{context} @{thms data_defs} (@{thms ccl_injs} @ @{thms term_injs})
    3.10      [["bot","inl","inr"], ["bot","zero","succ"], ["bot","nil","cons"]]);
    3.11  *}
    3.12 @@ -305,7 +305,7 @@
    3.13  subsection {* Rewriting and Proving *}
    3.14  
    3.15  ML {*
    3.16 -  bind_thms ("term_injDs", XH_to_Ds @{thms term_injs});
    3.17 +  ML_Thms.bind_thms ("term_injDs", XH_to_Ds @{thms term_injs});
    3.18  *}
    3.19  
    3.20  lemmas term_rews = termBs term_injs term_dstncts ccl_porews term_porews
     4.1 --- a/src/CCL/Type.thy	Tue Mar 18 09:39:07 2014 -0700
     4.2 +++ b/src/CCL/Type.thy	Tue Mar 18 21:02:33 2014 +0100
     4.3 @@ -101,7 +101,7 @@
     4.4    unfolding simp_type_defs by blast+
     4.5  
     4.6  ML {*
     4.7 -bind_thms ("case_rls", XH_to_Es @{thms XHs});
     4.8 +ML_Thms.bind_thms ("case_rls", XH_to_Es @{thms XHs});
     4.9  *}
    4.10  
    4.11  
    4.12 @@ -262,7 +262,7 @@
    4.13  
    4.14  lemmas iXHs = NatXH ListXH
    4.15  
    4.16 -ML {* bind_thms ("icase_rls", XH_to_Es @{thms iXHs}) *}
    4.17 +ML {* ML_Thms.bind_thms ("icase_rls", XH_to_Es @{thms iXHs}) *}
    4.18  
    4.19  
    4.20  subsection {* Type Rules *}
    4.21 @@ -340,7 +340,7 @@
    4.22  (*         - intro rules are type rules for canonical terms                *)
    4.23  (*         - elim rules are case rules (no non-canonical terms appear)     *)
    4.24  
    4.25 -ML {* bind_thms ("XHEs", XH_to_Es @{thms XHs}) *}
    4.26 +ML {* ML_Thms.bind_thms ("XHEs", XH_to_Es @{thms XHs}) *}
    4.27  
    4.28  lemmas [intro!] = SubtypeI canTs icanTs
    4.29    and [elim!] = SubtypeE XHEs
     5.1 --- a/src/Doc/Codegen/Setup.thy	Tue Mar 18 09:39:07 2014 -0700
     5.2 +++ b/src/Doc/Codegen/Setup.thy	Tue Mar 18 21:02:33 2014 +0100
     5.3 @@ -9,7 +9,7 @@
     5.4  
     5.5  (* FIXME avoid writing into source directory *)
     5.6  ML {*
     5.7 -  Isabelle_System.mkdirs (Path.append (Thy_Load.master_directory @{theory}) (Path.basic "examples"))
     5.8 +  Isabelle_System.mkdirs (Path.append (Resources.master_directory @{theory}) (Path.basic "examples"))
     5.9  *}
    5.10  
    5.11  ML_file "../antiquote_setup.ML"
     6.1 --- a/src/Doc/IsarImplementation/ML.thy	Tue Mar 18 09:39:07 2014 -0700
     6.2 +++ b/src/Doc/IsarImplementation/ML.thy	Tue Mar 18 21:02:33 2014 +0100
     6.3 @@ -627,8 +627,8 @@
     6.4    \begin{mldecls}
     6.5    @{index_ML ML_Context.the_generic_context: "unit -> Context.generic"} \\
     6.6    @{index_ML "Context.>>": "(Context.generic -> Context.generic) -> unit"} \\
     6.7 -  @{index_ML bind_thms: "string * thm list -> unit"} \\
     6.8 -  @{index_ML bind_thm: "string * thm -> unit"} \\
     6.9 +  @{index_ML ML_Thms.bind_thms: "string * thm list -> unit"} \\
    6.10 +  @{index_ML ML_Thms.bind_thm: "string * thm -> unit"} \\
    6.11    \end{mldecls}
    6.12  
    6.13    \begin{description}
    6.14 @@ -642,12 +642,12 @@
    6.15    \item @{ML "Context.>>"}~@{text f} applies context transformation
    6.16    @{text f} to the implicit context of the ML toplevel.
    6.17  
    6.18 -  \item @{ML bind_thms}~@{text "(name, thms)"} stores a list of
    6.19 +  \item @{ML ML_Thms.bind_thms}~@{text "(name, thms)"} stores a list of
    6.20    theorems produced in ML both in the (global) theory context and the
    6.21    ML toplevel, associating it with the provided name.  Theorems are
    6.22    put into a global ``standard'' format before being stored.
    6.23  
    6.24 -  \item @{ML bind_thm} is similar to @{ML bind_thms} but refers to a
    6.25 +  \item @{ML ML_Thms.bind_thm} is similar to @{ML ML_Thms.bind_thms} but refers to a
    6.26    singleton fact.
    6.27  
    6.28    \end{description}
     7.1 --- a/src/Doc/Tutorial/ToyList/ToyList_Test.thy	Tue Mar 18 09:39:07 2014 -0700
     7.2 +++ b/src/Doc/Tutorial/ToyList/ToyList_Test.thy	Tue Mar 18 21:02:33 2014 +0100
     7.3 @@ -5,7 +5,7 @@
     7.4  ML {*  (* FIXME somewhat non-standard, fragile *)
     7.5    let
     7.6      val texts =
     7.7 -      map (File.read o Path.append (Thy_Load.master_directory @{theory}) o Path.explode)
     7.8 +      map (File.read o Path.append (Resources.master_directory @{theory}) o Path.explode)
     7.9          ["ToyList1", "ToyList2"];
    7.10      val trs = Outer_Syntax.parse Position.start (implode texts);
    7.11      val end_state = fold (Toplevel.command_exception false) trs Toplevel.toplevel;
     8.1 --- a/src/Doc/antiquote_setup.ML	Tue Mar 18 09:39:07 2014 -0700
     8.2 +++ b/src/Doc/antiquote_setup.ML	Tue Mar 18 21:02:33 2014 +0100
     8.3 @@ -152,7 +152,7 @@
     8.4  val _ =
     8.5    Theory.setup (Thy_Output.antiquotation @{binding thy_file} (Scan.lift Args.name)
     8.6      (fn {context = ctxt, ...} =>
     8.7 -      fn name => (Thy_Load.check_thy Path.current name; Thy_Output.output ctxt [Pretty.str name])));
     8.8 +      fn name => (Resources.check_thy Path.current name; Thy_Output.output ctxt [Pretty.str name])));
     8.9  
    8.10  
    8.11  (* Isabelle/jEdit elements *)
     9.1 --- a/src/FOLP/IFOLP.thy	Tue Mar 18 09:39:07 2014 -0700
     9.2 +++ b/src/FOLP/IFOLP.thy	Tue Mar 18 21:02:33 2014 +0100
     9.3 @@ -411,7 +411,7 @@
     9.4    done
     9.5  
     9.6  (*NOT PROVED
     9.7 -bind_thm ("ex1_cong", prove_goal (the_context ())
     9.8 +ML_Thms.bind_thm ("ex1_cong", prove_goal (the_context ())
     9.9      "(!!x.f(x):P(x) <-> Q(x)) ==> ?p:(EX! x.P(x)) <-> (EX! x.Q(x))"
    9.10   (fn prems =>
    9.11    [ (REPEAT   (eresolve_tac [ex1E, spec RS mp] 1 ORELSE ares_tac [iffI,ex1I] 1
    10.1 --- a/src/HOL/Bali/AxSem.thy	Tue Mar 18 09:39:07 2014 -0700
    10.2 +++ b/src/HOL/Bali/AxSem.thy	Tue Mar 18 21:02:33 2014 +0100
    10.3 @@ -1006,7 +1006,7 @@
    10.4  apply  (auto simp add: type_ok_def)
    10.5  done
    10.6  
    10.7 -ML {* bind_thms ("ax_Abrupts", sum3_instantiate @{context} @{thm ax_derivs.Abrupt}) *}
    10.8 +ML {* ML_Thms.bind_thms ("ax_Abrupts", sum3_instantiate @{context} @{thm ax_derivs.Abrupt}) *}
    10.9  declare ax_Abrupts [intro!]
   10.10  
   10.11  lemmas ax_Normal_cases = ax_cases [of _ _ _ normal]
    11.1 --- a/src/HOL/Bali/Eval.thy	Tue Mar 18 09:39:07 2014 -0700
    11.2 +++ b/src/HOL/Bali/Eval.thy	Tue Mar 18 21:02:33 2014 +0100
    11.3 @@ -745,7 +745,7 @@
    11.4  *)
    11.5  
    11.6  ML {*
    11.7 -bind_thm ("eval_induct", rearrange_prems 
    11.8 +ML_Thms.bind_thm ("eval_induct", rearrange_prems 
    11.9  [0,1,2,8,4,30,31,27,15,16,
   11.10   17,18,19,20,21,3,5,25,26,23,6,
   11.11   7,11,9,13,14,12,22,10,28,
   11.12 @@ -881,7 +881,7 @@
   11.13      | _ => SOME (mk_meta_eq @{thm eval_stmt_eq})) *}
   11.14  
   11.15  ML {*
   11.16 -bind_thms ("AbruptIs", sum3_instantiate @{context} @{thm eval.Abrupt})
   11.17 +ML_Thms.bind_thms ("AbruptIs", sum3_instantiate @{context} @{thm eval.Abrupt})
   11.18  *}
   11.19  
   11.20  declare halloc.Abrupt [intro!] eval.Abrupt [intro!]  AbruptIs [intro!]
    12.1 --- a/src/HOL/Bali/Evaln.thy	Tue Mar 18 09:39:07 2014 -0700
    12.2 +++ b/src/HOL/Bali/Evaln.thy	Tue Mar 18 21:02:33 2014 +0100
    12.3 @@ -292,7 +292,7 @@
    12.4        (_ $ _ $ _ $ _ $ _ $ (Const _ $ _) $ _) => NONE
    12.5      | _ => SOME (mk_meta_eq @{thm evaln_stmt_eq})) *}
    12.6  
    12.7 -ML {* bind_thms ("evaln_AbruptIs", sum3_instantiate @{context} @{thm evaln.Abrupt}) *}
    12.8 +ML {* ML_Thms.bind_thms ("evaln_AbruptIs", sum3_instantiate @{context} @{thm evaln.Abrupt}) *}
    12.9  declare evaln_AbruptIs [intro!]
   12.10  
   12.11  lemma evaln_Callee: "G\<turnstile>Norm s\<midarrow>In1l (Callee l e)\<succ>\<midarrow>n\<rightarrow> (v,s') = False"
    13.1 --- a/src/HOL/Bali/Example.thy	Tue Mar 18 09:39:07 2014 -0700
    13.2 +++ b/src/HOL/Bali/Example.thy	Tue Mar 18 21:02:33 2014 +0100
    13.3 @@ -894,7 +894,7 @@
    13.4  
    13.5  declare member_is_static_simp [simp]
    13.6  declare wt.Skip [rule del] wt.Init [rule del]
    13.7 -ML {* bind_thms ("wt_intros", map (rewrite_rule @{context} @{thms id_def}) @{thms wt.intros}) *}
    13.8 +ML {* ML_Thms.bind_thms ("wt_intros", map (rewrite_rule @{context} @{thms id_def}) @{thms wt.intros}) *}
    13.9  lemmas wtIs = wt_Call wt_Super wt_FVar wt_StatRef wt_intros
   13.10  lemmas daIs = assigned.select_convs da_Skip da_NewC da_Lit da_Super da.intros
   13.11  
   13.12 @@ -1187,7 +1187,7 @@
   13.13  declare BaseCl_def [simp] ExtCl_def [simp] Ext_foo_def [simp]
   13.14          Base_foo_defs  [simp]
   13.15  
   13.16 -ML {* bind_thms ("eval_intros", map 
   13.17 +ML {* ML_Thms.bind_thms ("eval_intros", map 
   13.18          (simplify (@{context} delsimps @{thms Skip_eq} addsimps @{thms lvar_def}) o 
   13.19           rewrite_rule @{context} [@{thm assign_def}, @{thm Let_def}]) @{thms eval.intros}) *}
   13.20  lemmas eval_Is = eval_Init eval_StatRef AbruptIs eval_intros
    14.1 --- a/src/HOL/Bali/Term.thy	Tue Mar 18 09:39:07 2014 -0700
    14.2 +++ b/src/HOL/Bali/Term.thy	Tue Mar 18 21:02:33 2014 +0100
    14.3 @@ -262,7 +262,7 @@
    14.4    is_stmt :: "term \<Rightarrow> bool"
    14.5    where "is_stmt t = (\<exists>c. t=In1r c)"
    14.6  
    14.7 -ML {* bind_thms ("is_stmt_rews", sum3_instantiate @{context} @{thm is_stmt_def}) *}
    14.8 +ML {* ML_Thms.bind_thms ("is_stmt_rews", sum3_instantiate @{context} @{thm is_stmt_def}) *}
    14.9  
   14.10  declare is_stmt_rews [simp]
   14.11  
    15.1 --- a/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy	Tue Mar 18 09:39:07 2014 -0700
    15.2 +++ b/src/HOL/Decision_Procs/Reflected_Multivariate_Polynomial.thy	Tue Mar 18 21:02:33 2014 +0100
    15.3 @@ -68,43 +68,43 @@
    15.4  
    15.5  subsection{* Degrees and heads and coefficients *}
    15.6  
    15.7 -fun degree:: "poly \<Rightarrow> nat"
    15.8 +fun degree :: "poly \<Rightarrow> nat"
    15.9  where
   15.10    "degree (CN c 0 p) = 1 + degree p"
   15.11  | "degree p = 0"
   15.12  
   15.13 -fun head:: "poly \<Rightarrow> poly"
   15.14 +fun head :: "poly \<Rightarrow> poly"
   15.15  where
   15.16    "head (CN c 0 p) = head p"
   15.17  | "head p = p"
   15.18  
   15.19  (* More general notions of degree and head *)
   15.20 -fun degreen:: "poly \<Rightarrow> nat \<Rightarrow> nat"
   15.21 +fun degreen :: "poly \<Rightarrow> nat \<Rightarrow> nat"
   15.22  where
   15.23    "degreen (CN c n p) = (\<lambda>m. if n = m then 1 + degreen p n else 0)"
   15.24  | "degreen p = (\<lambda>m. 0)"
   15.25  
   15.26 -fun headn:: "poly \<Rightarrow> nat \<Rightarrow> poly"
   15.27 +fun headn :: "poly \<Rightarrow> nat \<Rightarrow> poly"
   15.28  where
   15.29    "headn (CN c n p) = (\<lambda>m. if n \<le> m then headn p m else CN c n p)"
   15.30  | "headn p = (\<lambda>m. p)"
   15.31  
   15.32 -fun coefficients:: "poly \<Rightarrow> poly list"
   15.33 +fun coefficients :: "poly \<Rightarrow> poly list"
   15.34  where
   15.35    "coefficients (CN c 0 p) = c # coefficients p"
   15.36  | "coefficients p = [p]"
   15.37  
   15.38 -fun isconstant:: "poly \<Rightarrow> bool"
   15.39 +fun isconstant :: "poly \<Rightarrow> bool"
   15.40  where
   15.41    "isconstant (CN c 0 p) = False"
   15.42  | "isconstant p = True"
   15.43  
   15.44 -fun behead:: "poly \<Rightarrow> poly"
   15.45 +fun behead :: "poly \<Rightarrow> poly"
   15.46  where
   15.47    "behead (CN c 0 p) = (let p' = behead p in if p' = 0\<^sub>p then c else CN c 0 p')"
   15.48  | "behead p = 0\<^sub>p"
   15.49  
   15.50 -fun headconst:: "poly \<Rightarrow> Num"
   15.51 +fun headconst :: "poly \<Rightarrow> Num"
   15.52  where
   15.53    "headconst (CN c n p) = headconst p"
   15.54  | "headconst (C n) = n"
   15.55 @@ -679,11 +679,11 @@
   15.56    shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> p *\<^sub>p q = 0\<^sub>p \<longleftrightarrow> p = 0\<^sub>p \<or> q = 0\<^sub>p"
   15.57    using polymul_properties(2) by blast
   15.58  
   15.59 -lemma polymul_degreen:  (* FIXME duplicate? *)
   15.60 +lemma polymul_degreen:
   15.61    assumes "SORT_CONSTRAINT('a::{field_char_0,field_inverse_zero})"
   15.62    shows "isnpolyh p n0 \<Longrightarrow> isnpolyh q n1 \<Longrightarrow> m \<le> min n0 n1 \<Longrightarrow>
   15.63      degreen (p *\<^sub>p q) m = (if p = 0\<^sub>p \<or> q = 0\<^sub>p then 0 else degreen p m + degreen q m)"
   15.64 -  using polymul_properties(3) by blast
   15.65 +  by (fact polymul_properties(3))
   15.66  
   15.67  lemma polymul_norm:
   15.68    assumes "SORT_CONSTRAINT('a::{field_char_0,field_inverse_zero})"
   15.69 @@ -852,10 +852,10 @@
   15.70    by (simp add: shift1_def)
   15.71  
   15.72  lemma shift1_isnpoly:
   15.73 -  assumes pn: "isnpoly p"
   15.74 -    and pnz: "p \<noteq> 0\<^sub>p"
   15.75 +  assumes "isnpoly p"
   15.76 +    and "p \<noteq> 0\<^sub>p"
   15.77    shows "isnpoly (shift1 p) "
   15.78 -  using pn pnz by (simp add: shift1_def isnpoly_def)
   15.79 +  using assms by (simp add: shift1_def isnpoly_def)
   15.80  
   15.81  lemma shift1_nz[simp]:"shift1 p \<noteq> 0\<^sub>p"
   15.82    by (simp add: shift1_def)
   15.83 @@ -864,10 +864,10 @@
   15.84    by (induct n arbitrary: p) (auto simp add: shift1_isnpoly funpow_swap1)
   15.85  
   15.86  lemma funpow_isnpolyh:
   15.87 -  assumes f: "\<And>p. isnpolyh p n \<Longrightarrow> isnpolyh (f p) n"
   15.88 -    and np: "isnpolyh p n"
   15.89 +  assumes "\<And>p. isnpolyh p n \<Longrightarrow> isnpolyh (f p) n"
   15.90 +    and "isnpolyh p n"
   15.91    shows "isnpolyh (funpow k f p) n"
   15.92 -  using f np by (induct k arbitrary: p) auto
   15.93 +  using assms by (induct k arbitrary: p) auto
   15.94  
   15.95  lemma funpow_shift1:
   15.96    "(Ipoly bs (funpow n shift1 p) :: 'a :: {field_char_0,field_inverse_zero}) =
   15.97 @@ -886,10 +886,10 @@
   15.98    by (induct p rule: poly_cmul.induct) (auto simp add: field_simps)
   15.99  
  15.100  lemma behead:
  15.101 -  assumes np: "isnpolyh p n"
  15.102 +  assumes "isnpolyh p n"
  15.103    shows "Ipoly bs (Add (Mul (head p) (Pw (Bound 0) (degree p))) (behead p)) =
  15.104      (Ipoly bs p :: 'a :: {field_char_0,field_inverse_zero})"
  15.105 -  using np
  15.106 +  using assms
  15.107  proof (induct p arbitrary: n rule: behead.induct)
  15.108    case (1 c p n)
  15.109    then have pn: "isnpolyh p n" by simp
  15.110 @@ -902,12 +902,12 @@
  15.111  qed (auto simp add: Let_def)
  15.112  
  15.113  lemma behead_isnpolyh:
  15.114 -  assumes np: "isnpolyh p n"
  15.115 +  assumes "isnpolyh p n"
  15.116    shows "isnpolyh (behead p) n"
  15.117 -  using np by (induct p rule: behead.induct) (auto simp add: Let_def isnpolyh_mono)
  15.118 +  using assms by (induct p rule: behead.induct) (auto simp add: Let_def isnpolyh_mono)
  15.119  
  15.120  
  15.121 -subsection{* Miscellaneous lemmas about indexes, decrementation, substitution  etc ... *}
  15.122 +subsection {* Miscellaneous lemmas about indexes, decrementation, substitution  etc ... *}
  15.123  
  15.124  lemma isnpolyh_polybound0: "isnpolyh p (Suc n) \<Longrightarrow> polybound0 p"
  15.125  proof (induct p arbitrary: n rule: poly.induct, auto)
  15.126 @@ -938,28 +938,27 @@
  15.127    by (induct p  arbitrary: n0 rule: head.induct) (auto intro: isnpolyh_polybound0)
  15.128  
  15.129  lemma polybound0_I:
  15.130 -  assumes nb: "polybound0 a"
  15.131 +  assumes "polybound0 a"
  15.132    shows "Ipoly (b # bs) a = Ipoly (b' # bs) a"
  15.133 -  using nb
  15.134 -  by (induct a rule: poly.induct) auto
  15.135 +  using assms by (induct a rule: poly.induct) auto
  15.136  
  15.137  lemma polysubst0_I: "Ipoly (b # bs) (polysubst0 a t) = Ipoly ((Ipoly (b # bs) a) # bs) t"
  15.138    by (induct t) simp_all
  15.139  
  15.140  lemma polysubst0_I':
  15.141 -  assumes nb: "polybound0 a"
  15.142 +  assumes "polybound0 a"
  15.143    shows "Ipoly (b # bs) (polysubst0 a t) = Ipoly ((Ipoly (b' # bs) a) # bs) t"
  15.144 -  by (induct t) (simp_all add: polybound0_I[OF nb, where b="b" and b'="b'"])
  15.145 +  by (induct t) (simp_all add: polybound0_I[OF assms, where b="b" and b'="b'"])
  15.146  
  15.147  lemma decrpoly:
  15.148 -  assumes nb: "polybound0 t"
  15.149 +  assumes "polybound0 t"
  15.150    shows "Ipoly (x # bs) t = Ipoly bs (decrpoly t)"
  15.151 -  using nb by (induct t rule: decrpoly.induct) simp_all
  15.152 +  using assms by (induct t rule: decrpoly.induct) simp_all
  15.153  
  15.154  lemma polysubst0_polybound0:
  15.155 -  assumes nb: "polybound0 t"
  15.156 +  assumes "polybound0 t"
  15.157    shows "polybound0 (polysubst0 t a)"
  15.158 -  using nb by (induct a rule: poly.induct) auto
  15.159 +  using assms by (induct a rule: poly.induct) auto
  15.160  
  15.161  lemma degree0_polybound0: "isnpolyh p n \<Longrightarrow> degree p = 0 \<Longrightarrow> polybound0 p"
  15.162    by (induct p arbitrary: n rule: degree.induct) (auto simp add: isnpolyh_polybound0)
  15.163 @@ -1034,10 +1033,10 @@
  15.164  lemma wf_bs_insensitive: "length bs = length bs' \<Longrightarrow> wf_bs bs p = wf_bs bs' p"
  15.165    unfolding wf_bs_def by simp
  15.166  
  15.167 -lemma wf_bs_insensitive': "wf_bs (x#bs) p = wf_bs (y#bs) p"
  15.168 +lemma wf_bs_insensitive': "wf_bs (x # bs) p = wf_bs (y # bs) p"
  15.169    unfolding wf_bs_def by simp
  15.170  
  15.171 -lemma wf_bs_coefficients': "\<forall>c \<in> set (coefficients p). wf_bs bs c \<Longrightarrow> wf_bs (x#bs) p"
  15.172 +lemma wf_bs_coefficients': "\<forall>c \<in> set (coefficients p). wf_bs bs c \<Longrightarrow> wf_bs (x # bs) p"
  15.173    by (induct p rule: coefficients.induct) (auto simp add: wf_bs_def)
  15.174  
  15.175  lemma coefficients_Nil[simp]: "coefficients p \<noteq> []"
  15.176 @@ -1046,11 +1045,11 @@
  15.177  lemma coefficients_head: "last (coefficients p) = head p"
  15.178    by (induct p rule: coefficients.induct) auto
  15.179  
  15.180 -lemma wf_bs_decrpoly: "wf_bs bs (decrpoly p) \<Longrightarrow> wf_bs (x#bs) p"
  15.181 +lemma wf_bs_decrpoly: "wf_bs bs (decrpoly p) \<Longrightarrow> wf_bs (x # bs) p"
  15.182    unfolding wf_bs_def by (induct p rule: decrpoly.induct) auto
  15.183  
  15.184  lemma length_le_list_ex: "length xs \<le> n \<Longrightarrow> \<exists>ys. length (xs @ ys) = n"
  15.185 -  apply (rule exI[where x="replicate (n - length xs) z"])
  15.186 +  apply (rule exI[where x="replicate (n - length xs) z" for z])
  15.187    apply simp
  15.188    done
  15.189  
  15.190 @@ -1481,7 +1480,8 @@
  15.191  lemma funpow_shift1_head: "isnpolyh p n0 \<Longrightarrow> p\<noteq> 0\<^sub>p \<Longrightarrow> head (funpow k shift1 p) = head p"
  15.192  proof (induct k arbitrary: n0 p)
  15.193    case 0
  15.194 -  then show ?case by auto
  15.195 +  then show ?case
  15.196 +    by auto
  15.197  next
  15.198    case (Suc k n0 p)
  15.199    then have "isnpolyh (shift1 p) 0"
  15.200 @@ -1522,7 +1522,6 @@
  15.201    shows "head (p +\<^sub>p q) = (if degree p < degree q then head q else head p)"
  15.202    using np nq deg
  15.203    apply (induct p q arbitrary: n0 n1 rule: polyadd.induct)
  15.204 -  using np
  15.205    apply simp_all
  15.206    apply (case_tac n', simp, simp)
  15.207    apply (case_tac n, simp, simp)
  15.208 @@ -1646,7 +1645,7 @@
  15.209  lemma polyneg_degree: "isnpolyh p n \<Longrightarrow> degree (polyneg p) = degree p"
  15.210    by (induct p arbitrary: n rule: degree.induct) auto
  15.211  
  15.212 -lemma polyneg_head: "isnpolyh p n \<Longrightarrow> head(polyneg p) = polyneg (head p)"
  15.213 +lemma polyneg_head: "isnpolyh p n \<Longrightarrow> head (polyneg p) = polyneg (head p)"
  15.214    by (induct p arbitrary: n rule: degree.induct) auto
  15.215  
  15.216  
  15.217 @@ -1657,8 +1656,9 @@
  15.218      and np: "isnpolyh p n0"
  15.219      and ns: "isnpolyh s n1"
  15.220      and ap: "head p = a"
  15.221 -    and ndp: "degree p = n" and pnz: "p \<noteq> 0\<^sub>p"
  15.222 -  shows "polydivide_aux a n p k s = (k',r) \<longrightarrow> k' \<ge> k \<and> (degree r = 0 \<or> degree r < degree p) \<and>
  15.223 +    and ndp: "degree p = n"
  15.224 +    and pnz: "p \<noteq> 0\<^sub>p"
  15.225 +  shows "polydivide_aux a n p k s = (k', r) \<longrightarrow> k' \<ge> k \<and> (degree r = 0 \<or> degree r < degree p) \<and>
  15.226      (\<exists>nr. isnpolyh r nr) \<and> (\<exists>q n1. isnpolyh q n1 \<and> (polypow (k' - k) a) *\<^sub>p s = p *\<^sub>p q +\<^sub>p r)"
  15.227    using ns
  15.228  proof (induct "degree s" arbitrary: s k k' r n1 rule: less_induct)
  15.229 @@ -1718,7 +1718,8 @@
  15.230          have nr: "isnpolyh (s -\<^sub>p ?p') 0"
  15.231            using polysub_normh[OF ns np'] by simp
  15.232          from degree_polysub_samehead[OF ns np' headsp' degsp']
  15.233 -        have "degree (s -\<^sub>p ?p') < degree s \<or> s -\<^sub>p ?p' = 0\<^sub>p" by simp
  15.234 +        have "degree (s -\<^sub>p ?p') < degree s \<or> s -\<^sub>p ?p' = 0\<^sub>p"
  15.235 +          by simp
  15.236          moreover
  15.237          {
  15.238            assume deglt:"degree (s -\<^sub>p ?p') < degree s"
  15.239 @@ -1798,7 +1799,7 @@
  15.240              using isnpolyh_unique[OF ns polymul_normh[OF nxdn np]]
  15.241              by blast
  15.242            {
  15.243 -            assume h1: "polydivide_aux a n p k s = (k',r)"
  15.244 +            assume h1: "polydivide_aux a n p k s = (k', r)"
  15.245              from polydivide_aux.simps sz dn' ba
  15.246              have eq: "polydivide_aux a n p k s = polydivide_aux a n p k (s -\<^sub>p ?p')"
  15.247                by (simp add: Let_def)
  15.248 @@ -1877,11 +1878,11 @@
  15.249                  by (simp add: field_simps)
  15.250              }
  15.251              then have ieq:"\<forall>bs :: 'a::{field_char_0,field_inverse_zero} list.
  15.252 -              Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  15.253 -              Ipoly bs (p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r)"
  15.254 +                Ipoly bs (a ^\<^sub>p (k' - k) *\<^sub>p s) =
  15.255 +                Ipoly bs (p *\<^sub>p (q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)) +\<^sub>p r)"
  15.256                by auto
  15.257              let ?q = "q +\<^sub>p (a ^\<^sub>p (k' - Suc k) *\<^sub>p ?b *\<^sub>p ?xdn)"
  15.258 -            from polyadd_normh[OF nq polymul_normh[OF polymul_normh[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - Suc k"] head_isnpolyh[OF ns], simplified ap ] nxdn]]
  15.259 +            from polyadd_normh[OF nq polymul_normh[OF polymul_normh[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - Suc k"] head_isnpolyh[OF ns], simplified ap] nxdn]]
  15.260              have nqw: "isnpolyh ?q 0"
  15.261                by simp
  15.262              from ieq isnpolyh_unique[OF polymul_normh[OF polypow_normh[OF head_isnpolyh[OF np], where k="k' - k"] ns, simplified ap] polyadd_normh[OF polymul_normh[OF np nqw] nr]]
  15.263 @@ -1979,13 +1980,13 @@
  15.264  definition "isnonconstant p \<longleftrightarrow> \<not> isconstant p"
  15.265  
  15.266  lemma isnonconstant_pnormal_iff:
  15.267 -  assumes nc: "isnonconstant p"
  15.268 +  assumes "isnonconstant p"
  15.269    shows "pnormal (polypoly bs p) \<longleftrightarrow> Ipoly bs (head p) \<noteq> 0"
  15.270  proof
  15.271    let ?p = "polypoly bs p"
  15.272    assume H: "pnormal ?p"
  15.273    have csz: "coefficients p \<noteq> []"
  15.274 -    using nc by (cases p) auto
  15.275 +    using assms by (cases p) auto
  15.276    from coefficients_head[of p] last_map[OF csz, of "Ipoly bs"] pnormal_last_nonzero[OF H]
  15.277    show "Ipoly bs (head p) \<noteq> 0"
  15.278      by (simp add: polypoly_def)
  15.279 @@ -1993,7 +1994,7 @@
  15.280    assume h: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.281    let ?p = "polypoly bs p"
  15.282    have csz: "coefficients p \<noteq> []"
  15.283 -    using nc by (cases p) auto
  15.284 +    using assms by (cases p) auto
  15.285    then have pz: "?p \<noteq> []"
  15.286      by (simp add: polypoly_def)
  15.287    then have lg: "length ?p > 0"
  15.288 @@ -2013,18 +2014,18 @@
  15.289    done
  15.290  
  15.291  lemma isnonconstant_nonconstant:
  15.292 -  assumes inc: "isnonconstant p"
  15.293 +  assumes "isnonconstant p"
  15.294    shows "nonconstant (polypoly bs p) \<longleftrightarrow> Ipoly bs (head p) \<noteq> 0"
  15.295  proof
  15.296    let ?p = "polypoly bs p"
  15.297    assume nc: "nonconstant ?p"
  15.298 -  from isnonconstant_pnormal_iff[OF inc, of bs] nc
  15.299 +  from isnonconstant_pnormal_iff[OF assms, of bs] nc
  15.300    show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.301      unfolding nonconstant_def by blast
  15.302  next
  15.303    let ?p = "polypoly bs p"
  15.304    assume h: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.305 -  from isnonconstant_pnormal_iff[OF inc, of bs] h
  15.306 +  from isnonconstant_pnormal_iff[OF assms, of bs] h
  15.307    have pn: "pnormal ?p"
  15.308      by blast
  15.309    {
  15.310 @@ -2032,8 +2033,8 @@
  15.311      assume H: "?p = [x]"
  15.312      from H have "length (coefficients p) = 1"
  15.313        unfolding polypoly_def by auto
  15.314 -    with isnonconstant_coefficients_length[OF inc]
  15.315 -      have False by arith
  15.316 +    with isnonconstant_coefficients_length[OF assms]
  15.317 +    have False by arith
  15.318    }
  15.319    then show "nonconstant ?p"
  15.320      using pn unfolding nonconstant_def by blast
  15.321 @@ -2047,26 +2048,26 @@
  15.322    done
  15.323  
  15.324  lemma degree_degree:
  15.325 -  assumes inc: "isnonconstant p"
  15.326 +  assumes "isnonconstant p"
  15.327    shows "degree p = Polynomial_List.degree (polypoly bs p) \<longleftrightarrow> \<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.328  proof
  15.329    let ?p = "polypoly bs p"
  15.330    assume H: "degree p = Polynomial_List.degree ?p"
  15.331 -  from isnonconstant_coefficients_length[OF inc] have pz: "?p \<noteq> []"
  15.332 +  from isnonconstant_coefficients_length[OF assms] have pz: "?p \<noteq> []"
  15.333      unfolding polypoly_def by auto
  15.334 -  from H degree_coefficients[of p] isnonconstant_coefficients_length[OF inc]
  15.335 +  from H degree_coefficients[of p] isnonconstant_coefficients_length[OF assms]
  15.336    have lg: "length (pnormalize ?p) = length ?p"
  15.337      unfolding Polynomial_List.degree_def polypoly_def by simp
  15.338    then have "pnormal ?p"
  15.339      using pnormal_length[OF pz] by blast
  15.340 -  with isnonconstant_pnormal_iff[OF inc] show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.341 +  with isnonconstant_pnormal_iff[OF assms] show "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.342      by blast
  15.343  next
  15.344    let ?p = "polypoly bs p"
  15.345    assume H: "\<lparr>head p\<rparr>\<^sub>p\<^bsup>bs\<^esup> \<noteq> 0"
  15.346 -  with isnonconstant_pnormal_iff[OF inc] have "pnormal ?p"
  15.347 +  with isnonconstant_pnormal_iff[OF assms] have "pnormal ?p"
  15.348      by blast
  15.349 -  with degree_coefficients[of p] isnonconstant_coefficients_length[OF inc]
  15.350 +  with degree_coefficients[of p] isnonconstant_coefficients_length[OF assms]
  15.351    show "degree p = Polynomial_List.degree ?p"
  15.352      unfolding polypoly_def pnormal_def Polynomial_List.degree_def by auto
  15.353  qed
  15.354 @@ -2077,7 +2078,7 @@
  15.355  primrec swap :: "nat \<Rightarrow> nat \<Rightarrow> poly \<Rightarrow> poly"
  15.356  where
  15.357    "swap n m (C x) = C x"
  15.358 -| "swap n m (Bound k) = Bound (if k = n then m else if k=m then n else k)"
  15.359 +| "swap n m (Bound k) = Bound (if k = n then m else if k = m then n else k)"
  15.360  | "swap n m (Neg t) = Neg (swap n m t)"
  15.361  | "swap n m (Add s t) = Add (swap n m s) (swap n m t)"
  15.362  | "swap n m (Sub s t) = Sub (swap n m s) (swap n m t)"
    16.1 --- a/src/HOL/SMT_Examples/boogie.ML	Tue Mar 18 09:39:07 2014 -0700
    16.2 +++ b/src/HOL/SMT_Examples/boogie.ML	Tue Mar 18 21:02:33 2014 +0100
    16.3 @@ -317,7 +317,7 @@
    16.4  val _ =
    16.5    Outer_Syntax.command @{command_spec "boogie_file"}
    16.6      "prove verification condition from .b2i file"
    16.7 -    (Thy_Load.provide_parse_files "boogie_file" >> (fn files =>
    16.8 +    (Resources.provide_parse_files "boogie_file" >> (fn files =>
    16.9        Toplevel.theory (fn thy =>
   16.10          let
   16.11            val ([{lines, ...}], thy') = files thy;
    17.1 --- a/src/HOL/SPARK/Tools/spark_commands.ML	Tue Mar 18 09:39:07 2014 -0700
    17.2 +++ b/src/HOL/SPARK/Tools/spark_commands.ML	Tue Mar 18 21:02:33 2014 +0100
    17.3 @@ -12,7 +12,7 @@
    17.4      val ([{src_path, lines = vc_lines, pos = vc_pos, ...}: Token.file,
    17.5        {lines = fdl_lines, pos = fdl_pos, ...},
    17.6        {lines = rls_lines, pos = rls_pos, ...}], thy') = files thy;
    17.7 -    val base = fst (Path.split_ext (File.full_path (Thy_Load.master_directory thy') src_path));
    17.8 +    val base = fst (Path.split_ext (File.full_path (Resources.master_directory thy') src_path));
    17.9    in
   17.10      SPARK_VCs.set_vcs
   17.11        (snd (Fdl_Parser.parse_declarations fdl_pos (cat_lines fdl_lines)))
   17.12 @@ -24,7 +24,7 @@
   17.13  (* FIXME *)
   17.14  fun spark_open_old (vc_name, prfx) thy =
   17.15    let
   17.16 -    val ((vc_path, vc_id), vc_text) = Thy_Load.load_file thy (Path.explode vc_name);
   17.17 +    val ((vc_path, vc_id), vc_text) = Resources.load_file thy (Path.explode vc_name);
   17.18      val (base, header) =
   17.19        (case Path.split_ext vc_path of
   17.20          (base, "vcg") => (base, Fdl_Lexer.vcg_header >> K ())
   17.21 @@ -117,13 +117,13 @@
   17.22  val _ =
   17.23    Outer_Syntax.command @{command_spec "spark_open_vcg"}
   17.24      "open a new SPARK environment and load a SPARK-generated .vcg file"
   17.25 -    (Parse.parname -- Thy_Load.provide_parse_files "spark_open_vcg"
   17.26 +    (Parse.parname -- Resources.provide_parse_files "spark_open_vcg"
   17.27        >> (Toplevel.theory o spark_open Fdl_Lexer.vcg_header));
   17.28  
   17.29  val _ =
   17.30    Outer_Syntax.command @{command_spec "spark_open_siv"}
   17.31      "open a new SPARK environment and load a SPARK-generated .siv file"
   17.32 -    (Parse.parname -- Thy_Load.provide_parse_files "spark_open_siv"
   17.33 +    (Parse.parname -- Resources.provide_parse_files "spark_open_siv"
   17.34        >> (Toplevel.theory o spark_open Fdl_Lexer.siv_header));
   17.35  
   17.36  val pfun_type = Scan.option
    18.1 --- a/src/HOL/Tools/SMT/smt_config.ML	Tue Mar 18 09:39:07 2014 -0700
    18.2 +++ b/src/HOL/Tools/SMT/smt_config.ML	Tue Mar 18 21:02:33 2014 +0100
    18.3 @@ -198,7 +198,7 @@
    18.4    if name = "" then NONE
    18.5    else
    18.6      Path.explode name
    18.7 -    |> Path.append (Thy_Load.master_directory (Context.theory_of context))
    18.8 +    |> Path.append (Resources.master_directory (Context.theory_of context))
    18.9      |> SOME o Cache_IO.unsynchronized_init)
   18.10  
   18.11  val certificates_of = Certificates.get o Context.Proof
    19.1 --- a/src/HOL/Tools/SMT2/smt2_config.ML	Tue Mar 18 09:39:07 2014 -0700
    19.2 +++ b/src/HOL/Tools/SMT2/smt2_config.ML	Tue Mar 18 21:02:33 2014 +0100
    19.3 @@ -195,7 +195,7 @@
    19.4    if name = "" then NONE
    19.5    else
    19.6      Path.explode name
    19.7 -    |> Path.append (Thy_Load.master_directory (Context.theory_of context))
    19.8 +    |> Path.append (Resources.master_directory (Context.theory_of context))
    19.9      |> SOME o Cache_IO.unsynchronized_init)
   19.10  
   19.11  val certificates_of = Certificates.get o Context.Proof
    20.1 --- a/src/HOL/Tools/recdef.ML	Tue Mar 18 09:39:07 2014 -0700
    20.2 +++ b/src/HOL/Tools/recdef.ML	Tue Mar 18 21:02:33 2014 +0100
    20.3 @@ -290,7 +290,7 @@
    20.4  
    20.5  val hints =
    20.6    @{keyword "("} |--
    20.7 -    Parse.!!! (Parse.position @{keyword "hints"} -- Args.parse --| @{keyword ")"})
    20.8 +    Parse.!!! (Parse.position @{keyword "hints"} -- Parse.args --| @{keyword ")"})
    20.9    >> uncurry Args.src;
   20.10  
   20.11  val recdef_decl =
    21.1 --- a/src/HOL/UNITY/Comp/Alloc.thy	Tue Mar 18 09:39:07 2014 -0700
    21.2 +++ b/src/HOL/UNITY/Comp/Alloc.thy	Tue Mar 18 21:02:33 2014 +0100
    21.3 @@ -425,7 +425,7 @@
    21.4    apply (rule fst_o_funPair)
    21.5    done
    21.6  
    21.7 -ML {* bind_thms ("fst_o_client_map'", make_o_equivs @{context} @{thm fst_o_client_map}) *}
    21.8 +ML {* ML_Thms.bind_thms ("fst_o_client_map'", make_o_equivs @{context} @{thm fst_o_client_map}) *}
    21.9  declare fst_o_client_map' [simp]
   21.10  
   21.11  lemma snd_o_client_map: "snd o client_map = clientState_d.dummy"
   21.12 @@ -433,7 +433,7 @@
   21.13    apply (rule snd_o_funPair)
   21.14    done
   21.15  
   21.16 -ML {* bind_thms ("snd_o_client_map'", make_o_equivs @{context} @{thm snd_o_client_map}) *}
   21.17 +ML {* ML_Thms.bind_thms ("snd_o_client_map'", make_o_equivs @{context} @{thm snd_o_client_map}) *}
   21.18  declare snd_o_client_map' [simp]
   21.19  
   21.20  
   21.21 @@ -443,28 +443,28 @@
   21.22    apply record_auto
   21.23    done
   21.24  
   21.25 -ML {* bind_thms ("client_o_sysOfAlloc'", make_o_equivs @{context} @{thm client_o_sysOfAlloc}) *}
   21.26 +ML {* ML_Thms.bind_thms ("client_o_sysOfAlloc'", make_o_equivs @{context} @{thm client_o_sysOfAlloc}) *}
   21.27  declare client_o_sysOfAlloc' [simp]
   21.28  
   21.29  lemma allocGiv_o_sysOfAlloc_eq: "allocGiv o sysOfAlloc = allocGiv"
   21.30    apply record_auto
   21.31    done
   21.32  
   21.33 -ML {* bind_thms ("allocGiv_o_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocGiv_o_sysOfAlloc_eq}) *}
   21.34 +ML {* ML_Thms.bind_thms ("allocGiv_o_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocGiv_o_sysOfAlloc_eq}) *}
   21.35  declare allocGiv_o_sysOfAlloc_eq' [simp]
   21.36  
   21.37  lemma allocAsk_o_sysOfAlloc_eq: "allocAsk o sysOfAlloc = allocAsk"
   21.38    apply record_auto
   21.39    done
   21.40  
   21.41 -ML {* bind_thms ("allocAsk_o_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocAsk_o_sysOfAlloc_eq}) *}
   21.42 +ML {* ML_Thms.bind_thms ("allocAsk_o_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocAsk_o_sysOfAlloc_eq}) *}
   21.43  declare allocAsk_o_sysOfAlloc_eq' [simp]
   21.44  
   21.45  lemma allocRel_o_sysOfAlloc_eq: "allocRel o sysOfAlloc = allocRel"
   21.46    apply record_auto
   21.47    done
   21.48  
   21.49 -ML {* bind_thms ("allocRel_o_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocRel_o_sysOfAlloc_eq}) *}
   21.50 +ML {* ML_Thms.bind_thms ("allocRel_o_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocRel_o_sysOfAlloc_eq}) *}
   21.51  declare allocRel_o_sysOfAlloc_eq' [simp]
   21.52  
   21.53  
   21.54 @@ -474,49 +474,49 @@
   21.55    apply record_auto
   21.56    done
   21.57  
   21.58 -ML {* bind_thms ("client_o_sysOfClient'", make_o_equivs @{context} @{thm client_o_sysOfClient}) *}
   21.59 +ML {* ML_Thms.bind_thms ("client_o_sysOfClient'", make_o_equivs @{context} @{thm client_o_sysOfClient}) *}
   21.60  declare client_o_sysOfClient' [simp]
   21.61  
   21.62  lemma allocGiv_o_sysOfClient_eq: "allocGiv o sysOfClient = allocGiv o snd "
   21.63    apply record_auto
   21.64    done
   21.65  
   21.66 -ML {* bind_thms ("allocGiv_o_sysOfClient_eq'", make_o_equivs @{context} @{thm allocGiv_o_sysOfClient_eq}) *}
   21.67 +ML {* ML_Thms.bind_thms ("allocGiv_o_sysOfClient_eq'", make_o_equivs @{context} @{thm allocGiv_o_sysOfClient_eq}) *}
   21.68  declare allocGiv_o_sysOfClient_eq' [simp]
   21.69  
   21.70  lemma allocAsk_o_sysOfClient_eq: "allocAsk o sysOfClient = allocAsk o snd "
   21.71    apply record_auto
   21.72    done
   21.73  
   21.74 -ML {* bind_thms ("allocAsk_o_sysOfClient_eq'", make_o_equivs @{context} @{thm allocAsk_o_sysOfClient_eq}) *}
   21.75 +ML {* ML_Thms.bind_thms ("allocAsk_o_sysOfClient_eq'", make_o_equivs @{context} @{thm allocAsk_o_sysOfClient_eq}) *}
   21.76  declare allocAsk_o_sysOfClient_eq' [simp]
   21.77  
   21.78  lemma allocRel_o_sysOfClient_eq: "allocRel o sysOfClient = allocRel o snd "
   21.79    apply record_auto
   21.80    done
   21.81  
   21.82 -ML {* bind_thms ("allocRel_o_sysOfClient_eq'", make_o_equivs @{context} @{thm allocRel_o_sysOfClient_eq}) *}
   21.83 +ML {* ML_Thms.bind_thms ("allocRel_o_sysOfClient_eq'", make_o_equivs @{context} @{thm allocRel_o_sysOfClient_eq}) *}
   21.84  declare allocRel_o_sysOfClient_eq' [simp]
   21.85  
   21.86  lemma allocGiv_o_inv_sysOfAlloc_eq: "allocGiv o inv sysOfAlloc = allocGiv"
   21.87    apply (simp add: o_def)
   21.88    done
   21.89  
   21.90 -ML {* bind_thms ("allocGiv_o_inv_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocGiv_o_inv_sysOfAlloc_eq}) *}
   21.91 +ML {* ML_Thms.bind_thms ("allocGiv_o_inv_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocGiv_o_inv_sysOfAlloc_eq}) *}
   21.92  declare allocGiv_o_inv_sysOfAlloc_eq' [simp]
   21.93  
   21.94  lemma allocAsk_o_inv_sysOfAlloc_eq: "allocAsk o inv sysOfAlloc = allocAsk"
   21.95    apply (simp add: o_def)
   21.96    done
   21.97  
   21.98 -ML {* bind_thms ("allocAsk_o_inv_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocAsk_o_inv_sysOfAlloc_eq}) *}
   21.99 +ML {* ML_Thms.bind_thms ("allocAsk_o_inv_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocAsk_o_inv_sysOfAlloc_eq}) *}
  21.100  declare allocAsk_o_inv_sysOfAlloc_eq' [simp]
  21.101  
  21.102  lemma allocRel_o_inv_sysOfAlloc_eq: "allocRel o inv sysOfAlloc = allocRel"
  21.103    apply (simp add: o_def)
  21.104    done
  21.105  
  21.106 -ML {* bind_thms ("allocRel_o_inv_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocRel_o_inv_sysOfAlloc_eq}) *}
  21.107 +ML {* ML_Thms.bind_thms ("allocRel_o_inv_sysOfAlloc_eq'", make_o_equivs @{context} @{thm allocRel_o_inv_sysOfAlloc_eq}) *}
  21.108  declare allocRel_o_inv_sysOfAlloc_eq' [simp]
  21.109  
  21.110  lemma rel_inv_client_map_drop_map: "(rel o inv client_map o drop_map i o inv sysOfClient) =
  21.111 @@ -524,7 +524,7 @@
  21.112    apply (simp add: o_def drop_map_def)
  21.113    done
  21.114  
  21.115 -ML {* bind_thms ("rel_inv_client_map_drop_map'", make_o_equivs @{context} @{thm rel_inv_client_map_drop_map}) *}
  21.116 +ML {* ML_Thms.bind_thms ("rel_inv_client_map_drop_map'", make_o_equivs @{context} @{thm rel_inv_client_map_drop_map}) *}
  21.117  declare rel_inv_client_map_drop_map [simp]
  21.118  
  21.119  lemma ask_inv_client_map_drop_map: "(ask o inv client_map o drop_map i o inv sysOfClient) =
  21.120 @@ -532,7 +532,7 @@
  21.121    apply (simp add: o_def drop_map_def)
  21.122    done
  21.123  
  21.124 -ML {* bind_thms ("ask_inv_client_map_drop_map'", make_o_equivs @{context} @{thm ask_inv_client_map_drop_map}) *}
  21.125 +ML {* ML_Thms.bind_thms ("ask_inv_client_map_drop_map'", make_o_equivs @{context} @{thm ask_inv_client_map_drop_map}) *}
  21.126  declare ask_inv_client_map_drop_map [simp]
  21.127  
  21.128  
  21.129 @@ -549,13 +549,13 @@
  21.130          @{thm Client} |> simplify (@{context} addsimps @{thms client_spec_simps})
  21.131                 |> list_of_Int;
  21.132  
  21.133 -bind_thm ("Client_Increasing_ask", Client_Increasing_ask);
  21.134 -bind_thm ("Client_Increasing_rel", Client_Increasing_rel);
  21.135 -bind_thm ("Client_Bounded", Client_Bounded);
  21.136 -bind_thm ("Client_Progress", Client_Progress);
  21.137 -bind_thm ("Client_AllowedActs", Client_AllowedActs);
  21.138 -bind_thm ("Client_preserves_giv", Client_preserves_giv);
  21.139 -bind_thm ("Client_preserves_dummy", Client_preserves_dummy);
  21.140 +ML_Thms.bind_thm ("Client_Increasing_ask", Client_Increasing_ask);
  21.141 +ML_Thms.bind_thm ("Client_Increasing_rel", Client_Increasing_rel);
  21.142 +ML_Thms.bind_thm ("Client_Bounded", Client_Bounded);
  21.143 +ML_Thms.bind_thm ("Client_Progress", Client_Progress);
  21.144 +ML_Thms.bind_thm ("Client_AllowedActs", Client_AllowedActs);
  21.145 +ML_Thms.bind_thm ("Client_preserves_giv", Client_preserves_giv);
  21.146 +ML_Thms.bind_thm ("Client_preserves_dummy", Client_preserves_dummy);
  21.147  *}
  21.148  
  21.149  declare
  21.150 @@ -579,13 +579,13 @@
  21.151          @{thm Network} |> simplify (@{context} addsimps @{thms network_spec_simps})
  21.152                  |> list_of_Int;
  21.153  
  21.154 -bind_thm ("Network_Ask", Network_Ask);
  21.155 -bind_thm ("Network_Giv", Network_Giv);
  21.156 -bind_thm ("Network_Rel", Network_Rel);
  21.157 -bind_thm ("Network_AllowedActs", Network_AllowedActs);
  21.158 -bind_thm ("Network_preserves_allocGiv", Network_preserves_allocGiv);
  21.159 -bind_thm ("Network_preserves_rel", Network_preserves_rel);
  21.160 -bind_thm ("Network_preserves_ask", Network_preserves_ask);
  21.161 +ML_Thms.bind_thm ("Network_Ask", Network_Ask);
  21.162 +ML_Thms.bind_thm ("Network_Giv", Network_Giv);
  21.163 +ML_Thms.bind_thm ("Network_Rel", Network_Rel);
  21.164 +ML_Thms.bind_thm ("Network_AllowedActs", Network_AllowedActs);
  21.165 +ML_Thms.bind_thm ("Network_preserves_allocGiv", Network_preserves_allocGiv);
  21.166 +ML_Thms.bind_thm ("Network_preserves_rel", Network_preserves_rel);
  21.167 +ML_Thms.bind_thm ("Network_preserves_ask", Network_preserves_ask);
  21.168  *}
  21.169  
  21.170  declare Network_preserves_allocGiv [iff]
  21.171 @@ -610,13 +610,13 @@
  21.172          @{thm Alloc} |> simplify (@{context} addsimps @{thms alloc_spec_simps})
  21.173                |> list_of_Int;
  21.174  
  21.175 -bind_thm ("Alloc_Increasing_0", Alloc_Increasing_0);
  21.176 -bind_thm ("Alloc_Safety", Alloc_Safety);
  21.177 -bind_thm ("Alloc_Progress", Alloc_Progress);
  21.178 -bind_thm ("Alloc_AllowedActs", Alloc_AllowedActs);
  21.179 -bind_thm ("Alloc_preserves_allocRel", Alloc_preserves_allocRel);
  21.180 -bind_thm ("Alloc_preserves_allocAsk", Alloc_preserves_allocAsk);
  21.181 -bind_thm ("Alloc_preserves_dummy", Alloc_preserves_dummy);
  21.182 +ML_Thms.bind_thm ("Alloc_Increasing_0", Alloc_Increasing_0);
  21.183 +ML_Thms.bind_thm ("Alloc_Safety", Alloc_Safety);
  21.184 +ML_Thms.bind_thm ("Alloc_Progress", Alloc_Progress);
  21.185 +ML_Thms.bind_thm ("Alloc_AllowedActs", Alloc_AllowedActs);
  21.186 +ML_Thms.bind_thm ("Alloc_preserves_allocRel", Alloc_preserves_allocRel);
  21.187 +ML_Thms.bind_thm ("Alloc_preserves_allocAsk", Alloc_preserves_allocAsk);
  21.188 +ML_Thms.bind_thm ("Alloc_preserves_dummy", Alloc_preserves_dummy);
  21.189  *}
  21.190  
  21.191  text{*Strip off the INT in the guarantees postcondition*}
  21.192 @@ -808,7 +808,7 @@
  21.193  
  21.194  
  21.195  ML {*
  21.196 -bind_thms ("System_Increasing'", list_of_Int @{thm System_Increasing})
  21.197 +ML_Thms.bind_thms ("System_Increasing'", list_of_Int @{thm System_Increasing})
  21.198  *}
  21.199  
  21.200  declare System_Increasing' [intro!]
    22.1 --- a/src/Pure/Isar/args.ML	Tue Mar 18 09:39:07 2014 -0700
    22.2 +++ b/src/Pure/Isar/args.ML	Tue Mar 18 21:02:33 2014 +0100
    22.3 @@ -61,12 +61,8 @@
    22.4    val type_name: {proper: bool, strict: bool} -> string context_parser
    22.5    val const: {proper: bool, strict: bool} -> string context_parser
    22.6    val goal_spec: ((int -> tactic) -> tactic) context_parser
    22.7 -  val parse: Token.T list parser
    22.8 -  val parse1: (string -> bool) -> Token.T list parser
    22.9    val attribs: (xstring * Position.T -> string) -> src list parser
   22.10    val opt_attribs: (xstring * Position.T -> string) -> src list parser
   22.11 -  val thm_name: (xstring * Position.T -> string) -> string -> (binding * src list) parser
   22.12 -  val opt_thm_name: (xstring * Position.T -> string) -> string -> (binding * src list) parser
   22.13    val syntax_generic: 'a context_parser -> src -> Context.generic -> 'a * Context.generic
   22.14    val syntax: 'a context_parser -> src -> Proof.context -> 'a * Proof.context
   22.15  end;
   22.16 @@ -151,21 +147,19 @@
   22.17  
   22.18  (* basic *)
   22.19  
   22.20 -fun token atom = Scan.ahead Parse.not_eof --| atom;
   22.21 -
   22.22 -val ident = token
   22.23 +val ident = Parse.token
   22.24    (Parse.short_ident || Parse.long_ident || Parse.sym_ident || Parse.term_var ||
   22.25      Parse.type_ident || Parse.type_var || Parse.number);
   22.26  
   22.27 -val string = token (Parse.string || Parse.verbatim);
   22.28 -val alt_string = token Parse.alt_string;
   22.29 -val symbolic = token (Parse.keyword_with Token.ident_or_symbolic);
   22.30 +val string = Parse.token (Parse.string || Parse.verbatim);
   22.31 +val alt_string = Parse.token Parse.alt_string;
   22.32 +val symbolic = Parse.token (Parse.keyword_with Token.ident_or_symbolic);
   22.33  
   22.34  fun $$$ x =
   22.35 -  (ident || token Parse.keyword) :|-- (fn tok =>
   22.36 +  (ident || Parse.token Parse.keyword) :|-- (fn tok =>
   22.37      let val y = Token.content_of tok in
   22.38        if x = y
   22.39 -      then (Token.assign (SOME (Token.Literal Markup.quasi_keyword)) tok; Scan.succeed x)
   22.40 +      then (Token.assign (SOME (Token.Literal (false, Markup.quasi_keyword))) tok; Scan.succeed x)
   22.41        else Scan.fail
   22.42      end);
   22.43  
   22.44 @@ -185,7 +179,7 @@
   22.45  fun mode s = Scan.optional (parens ($$$ s) >> K true) false;
   22.46  fun maybe scan = $$$ "_" >> K NONE || scan >> SOME;
   22.47  
   22.48 -val cartouche = token Parse.cartouche;
   22.49 +val cartouche = Parse.token Parse.cartouche;
   22.50  val cartouche_inner_syntax = cartouche >> Token.inner_syntax_of;
   22.51  val cartouche_source_position = cartouche >> Token.source_position_of;
   22.52  
   22.53 @@ -257,63 +251,22 @@
   22.54    Parse.nat >> (fn i => fn tac => tac i) ||
   22.55    $$$ "!" >> K ALLGOALS;
   22.56  
   22.57 -val goal = $$$ "[" |-- Parse.!!! (from_to --| $$$ "]");
   22.58 +val goal = Parse.keyword_improper "[" |-- Parse.!!! (from_to --| Parse.keyword_improper "]");
   22.59  fun goal_spec x = Scan.lift (Scan.optional goal (fn tac => tac 1)) x;
   22.60  
   22.61  
   22.62 -(* arguments within outer syntax *)
   22.63 -
   22.64 -val argument_kinds =
   22.65 - [Token.Ident, Token.LongIdent, Token.SymIdent, Token.Var, Token.TypeIdent, Token.TypeVar,
   22.66 -  Token.Nat, Token.Float, Token.String, Token.AltString, Token.Cartouche, Token.Verbatim];
   22.67 -
   22.68 -fun parse_args is_symid =
   22.69 -  let
   22.70 -    fun argument blk =
   22.71 -      Parse.group (fn () => "argument")
   22.72 -        (Scan.one (fn tok =>
   22.73 -          let val kind = Token.kind_of tok in
   22.74 -            member (op =) argument_kinds kind orelse
   22.75 -            Token.keyword_with is_symid tok orelse
   22.76 -            (blk andalso Token.keyword_with (fn s => s = ",") tok)
   22.77 -          end));
   22.78 -
   22.79 -    fun args blk x = Scan.optional (args1 blk) [] x
   22.80 -    and args1 blk x =
   22.81 -      ((Scan.repeat1
   22.82 -        (Scan.repeat1 (argument blk) ||
   22.83 -          argsp "(" ")" ||
   22.84 -          argsp "[" "]")) >> flat) x
   22.85 -    and argsp l r x =
   22.86 -      (token (Parse.$$$ l) ::: Parse.!!! (args true @@@ (token (Parse.$$$ r) >> single))) x;
   22.87 -  in (args, args1) end;
   22.88 -
   22.89 -val parse = #1 (parse_args Token.ident_or_symbolic) false;
   22.90 -fun parse1 is_symid = #2 (parse_args is_symid) false;
   22.91 -
   22.92 -
   22.93  (* attributes *)
   22.94  
   22.95  fun attribs check =
   22.96    let
   22.97      fun intern tok = check (Token.content_of tok, Token.pos_of tok);
   22.98      val attrib_name = internal_text || (symbolic || named) >> evaluate Token.Text intern;
   22.99 -    val attrib = Parse.position attrib_name -- Parse.!!! parse >> uncurry src;
  22.100 +    val attrib = Parse.position attrib_name -- Parse.!!! Parse.args >> uncurry src;
  22.101    in $$$ "[" |-- Parse.!!! (Parse.list attrib --| $$$ "]") end;
  22.102  
  22.103  fun opt_attribs check = Scan.optional (attribs check) [];
  22.104  
  22.105  
  22.106 -(* theorem specifications *)
  22.107 -
  22.108 -fun thm_name check_attrib s = binding -- opt_attribs check_attrib --| $$$ s;
  22.109 -
  22.110 -fun opt_thm_name check_attrib s =
  22.111 -  Scan.optional
  22.112 -    ((binding -- opt_attribs check_attrib || attribs check_attrib >> pair Binding.empty) --| $$$ s)
  22.113 -    (Binding.empty, []);
  22.114 -
  22.115 -
  22.116  
  22.117  (** syntax wrapper **)
  22.118  
    23.1 --- a/src/Pure/Isar/class.ML	Tue Mar 18 09:39:07 2014 -0700
    23.2 +++ b/src/Pure/Isar/class.ML	Tue Mar 18 21:02:33 2014 +0100
    23.3 @@ -666,9 +666,9 @@
    23.4      default_intro_tac ctxt facts;
    23.5  
    23.6  val _ = Theory.setup
    23.7 - (Method.setup (Binding.name "intro_classes") (Scan.succeed (K (METHOD intro_classes_tac)))
    23.8 + (Method.setup @{binding intro_classes} (Scan.succeed (K (METHOD intro_classes_tac)))
    23.9      "back-chain introduction rules of classes" #>
   23.10 -  Method.setup (Binding.name "default") (Attrib.thms >> (METHOD oo default_tac))
   23.11 +  Method.setup @{binding default} (Attrib.thms >> (METHOD oo default_tac))
   23.12      "apply some intro/elim rule");
   23.13  
   23.14  end;
    24.1 --- a/src/Pure/Isar/code.ML	Tue Mar 18 09:39:07 2014 -0700
    24.2 +++ b/src/Pure/Isar/code.ML	Tue Mar 18 21:02:33 2014 +0100
    24.3 @@ -1285,7 +1285,7 @@
    24.4        || Scan.succeed (mk_attribute add_eqn_maybe_abs);
    24.5    in
    24.6      Datatype_Interpretation.init
    24.7 -    #> Attrib.setup (Binding.name "code") (Scan.lift code_attribute_parser)
    24.8 +    #> Attrib.setup @{binding code} (Scan.lift code_attribute_parser)
    24.9          "declare theorems for code generation"
   24.10    end);
   24.11  
    25.1 --- a/src/Pure/Isar/context_rules.ML	Tue Mar 18 09:39:07 2014 -0700
    25.2 +++ b/src/Pure/Isar/context_rules.ML	Tue Mar 18 21:02:33 2014 +0100
    25.3 @@ -209,13 +209,13 @@
    25.4      Scan.option Parse.nat) >> (fn (f, n) => f n)) x;
    25.5  
    25.6  val _ = Theory.setup
    25.7 - (Attrib.setup (Binding.name "intro") (add intro_bang intro intro_query)
    25.8 + (Attrib.setup @{binding intro} (add intro_bang intro intro_query)
    25.9      "declaration of introduction rule" #>
   25.10 -  Attrib.setup (Binding.name "elim") (add elim_bang elim elim_query)
   25.11 +  Attrib.setup @{binding elim} (add elim_bang elim elim_query)
   25.12      "declaration of elimination rule" #>
   25.13 -  Attrib.setup (Binding.name "dest") (add dest_bang dest dest_query)
   25.14 +  Attrib.setup @{binding dest} (add dest_bang dest dest_query)
   25.15      "declaration of destruction rule" #>
   25.16 -  Attrib.setup (Binding.name "rule") (Scan.lift Args.del >> K rule_del)
   25.17 +  Attrib.setup @{binding rule} (Scan.lift Args.del >> K rule_del)
   25.18      "remove declaration of intro/elim/dest rule");
   25.19  
   25.20  end;
    26.1 --- a/src/Pure/Isar/isar_cmd.ML	Tue Mar 18 09:39:07 2014 -0700
    26.2 +++ b/src/Pure/Isar/isar_cmd.ML	Tue Mar 18 21:02:33 2014 +0100
    26.3 @@ -247,9 +247,9 @@
    26.4      handle Toplevel.UNDEF => error "No goal present";
    26.5  
    26.6  val _ = Theory.setup
    26.7 -  (ML_Antiquotation.value (Binding.qualify true "Isar" (Binding.name "state"))
    26.8 +  (ML_Antiquotation.value (Binding.qualify true "Isar" @{binding state})
    26.9      (Scan.succeed "Isar_Cmd.diag_state ML_context") #>
   26.10 -   ML_Antiquotation.value (Binding.qualify true "Isar" (Binding.name "goal"))
   26.11 +   ML_Antiquotation.value (Binding.qualify true "Isar" @{binding goal})
   26.12      (Scan.succeed "Isar_Cmd.diag_goal ML_context"));
   26.13  
   26.14  
    27.1 --- a/src/Pure/Isar/locale.ML	Tue Mar 18 09:39:07 2014 -0700
    27.2 +++ b/src/Pure/Isar/locale.ML	Tue Mar 18 21:02:33 2014 +0100
    27.3 @@ -622,9 +622,9 @@
    27.4  val try_intro_locales_tac= gen_intro_locales_tac Method.try_intros_tac;
    27.5  
    27.6  val _ = Theory.setup
    27.7 - (Method.setup (Binding.name "intro_locales") (Scan.succeed (METHOD o try_intro_locales_tac false))
    27.8 + (Method.setup @{binding intro_locales} (Scan.succeed (METHOD o try_intro_locales_tac false))
    27.9      "back-chain introduction rules of locales without unfolding predicates" #>
   27.10 -  Method.setup (Binding.name "unfold_locales") (Scan.succeed (METHOD o try_intro_locales_tac true))
   27.11 +  Method.setup @{binding unfold_locales} (Scan.succeed (METHOD o try_intro_locales_tac true))
   27.12      "back-chain all introduction rules of locales");
   27.13  
   27.14  
    28.1 --- a/src/Pure/Isar/method.ML	Tue Mar 18 09:39:07 2014 -0700
    28.2 +++ b/src/Pure/Isar/method.ML	Tue Mar 18 21:02:33 2014 +0100
    28.3 @@ -201,7 +201,7 @@
    28.4  
    28.5  (* rule etc. -- single-step refinements *)
    28.6  
    28.7 -val rule_trace = Attrib.setup_config_bool (Binding.name "rule_trace") (fn _ => false);
    28.8 +val rule_trace = Attrib.setup_config_bool @{binding rule_trace} (fn _ => false);
    28.9  
   28.10  fun trace ctxt rules =
   28.11    if Config.get ctxt rule_trace andalso not (null rules) then
   28.12 @@ -458,7 +458,7 @@
   28.13          Select_Goals (combinator_info [pos1, pos2], n, m)) ||
   28.14    meth4) x
   28.15  and meth2 x =
   28.16 - (Parse.position Parse.xname -- Args.parse1 is_symid_meth >> (Source o uncurry Args.src) ||
   28.17 + (Parse.position Parse.xname -- Parse.args1 is_symid_meth >> (Source o uncurry Args.src) ||
   28.18    meth3) x
   28.19  and meth1 x =
   28.20    (Parse.enum1_positions "," meth2
   28.21 @@ -478,38 +478,38 @@
   28.22  (* theory setup *)
   28.23  
   28.24  val _ = Theory.setup
   28.25 - (setup (Binding.name "fail") (Scan.succeed (K fail)) "force failure" #>
   28.26 -  setup (Binding.name "succeed") (Scan.succeed (K succeed)) "succeed" #>
   28.27 -  setup (Binding.name "-") (Scan.succeed (K insert_facts))
   28.28 + (setup @{binding fail} (Scan.succeed (K fail)) "force failure" #>
   28.29 +  setup @{binding succeed} (Scan.succeed (K succeed)) "succeed" #>
   28.30 +  setup @{binding "-"} (Scan.succeed (K insert_facts))
   28.31      "do nothing (insert current facts only)" #>
   28.32 -  setup (Binding.name "insert") (Attrib.thms >> (K o insert))
   28.33 +  setup @{binding insert} (Attrib.thms >> (K o insert))
   28.34      "insert theorems, ignoring facts (improper)" #>
   28.35 -  setup (Binding.name "intro") (Attrib.thms >> (K o intro))
   28.36 +  setup @{binding intro} (Attrib.thms >> (K o intro))
   28.37      "repeatedly apply introduction rules" #>
   28.38 -  setup (Binding.name "elim") (Attrib.thms >> (K o elim))
   28.39 +  setup @{binding elim} (Attrib.thms >> (K o elim))
   28.40      "repeatedly apply elimination rules" #>
   28.41 -  setup (Binding.name "unfold") (Attrib.thms >> unfold_meth) "unfold definitions" #>
   28.42 -  setup (Binding.name "fold") (Attrib.thms >> fold_meth) "fold definitions" #>
   28.43 -  setup (Binding.name "atomize") (Scan.lift (Args.mode "full") >> atomize)
   28.44 +  setup @{binding unfold} (Attrib.thms >> unfold_meth) "unfold definitions" #>
   28.45 +  setup @{binding fold} (Attrib.thms >> fold_meth) "fold definitions" #>
   28.46 +  setup @{binding atomize} (Scan.lift (Args.mode "full") >> atomize)
   28.47      "present local premises as object-level statements" #>
   28.48 -  setup (Binding.name "rule") (Attrib.thms >> (fn ths => fn ctxt => some_rule ctxt ths))
   28.49 +  setup @{binding rule} (Attrib.thms >> (fn ths => fn ctxt => some_rule ctxt ths))
   28.50      "apply some intro/elim rule" #>
   28.51 -  setup (Binding.name "erule") (xrule_meth erule) "apply rule in elimination manner (improper)" #>
   28.52 -  setup (Binding.name "drule") (xrule_meth drule) "apply rule in destruct manner (improper)" #>
   28.53 -  setup (Binding.name "frule") (xrule_meth frule) "apply rule in forward manner (improper)" #>
   28.54 -  setup (Binding.name "this") (Scan.succeed (K this)) "apply current facts as rules" #>
   28.55 -  setup (Binding.name "fact") (Attrib.thms >> fact) "composition by facts from context" #>
   28.56 -  setup (Binding.name "assumption") (Scan.succeed assumption)
   28.57 +  setup @{binding erule} (xrule_meth erule) "apply rule in elimination manner (improper)" #>
   28.58 +  setup @{binding drule} (xrule_meth drule) "apply rule in destruct manner (improper)" #>
   28.59 +  setup @{binding frule} (xrule_meth frule) "apply rule in forward manner (improper)" #>
   28.60 +  setup @{binding this} (Scan.succeed (K this)) "apply current facts as rules" #>
   28.61 +  setup @{binding fact} (Attrib.thms >> fact) "composition by facts from context" #>
   28.62 +  setup @{binding assumption} (Scan.succeed assumption)
   28.63      "proof by assumption, preferring facts" #>
   28.64 -  setup (Binding.name "rename_tac") (Args.goal_spec -- Scan.lift (Scan.repeat1 Args.name) >>
   28.65 +  setup @{binding rename_tac} (Args.goal_spec -- Scan.lift (Scan.repeat1 Args.name) >>
   28.66      (fn (quant, xs) => K (SIMPLE_METHOD'' quant (rename_tac xs))))
   28.67      "rename parameters of goal" #>
   28.68 -  setup (Binding.name "rotate_tac") (Args.goal_spec -- Scan.lift (Scan.optional Parse.int 1) >>
   28.69 +  setup @{binding rotate_tac} (Args.goal_spec -- Scan.lift (Scan.optional Parse.int 1) >>
   28.70      (fn (quant, i) => K (SIMPLE_METHOD'' quant (rotate_tac i))))
   28.71        "rotate assumptions of goal" #>
   28.72 -  setup (Binding.name "tactic") (Scan.lift Args.name_source_position >> tactic)
   28.73 +  setup @{binding tactic} (Scan.lift Args.name_source_position >> tactic)
   28.74      "ML tactic as proof method" #>
   28.75 -  setup (Binding.name "raw_tactic") (Scan.lift Args.name_source_position >> raw_tactic)
   28.76 +  setup @{binding raw_tactic} (Scan.lift Args.name_source_position >> raw_tactic)
   28.77      "ML tactic as raw proof method");
   28.78  
   28.79  
    29.1 --- a/src/Pure/Isar/outer_syntax.ML	Tue Mar 18 09:39:07 2014 -0700
    29.2 +++ b/src/Pure/Isar/outer_syntax.ML	Tue Mar 18 21:02:33 2014 +0100
    29.3 @@ -288,7 +288,7 @@
    29.4  fun isar in_stream term : isar =
    29.5    Source.tty in_stream
    29.6    |> Symbol.source
    29.7 -  |> Source.map_filter (fn "\\<^newline>" => SOME "\n" | s => SOME s)  (*Proof General legacy*)
    29.8 +  |> Source.map_filter (fn "\<^newline>" => SOME "\n" | s => SOME s)  (*Proof General legacy*)
    29.9    |> Token.source {do_recover = SOME true} Keyword.get_lexicons Position.none
   29.10    |> toplevel_source term (SOME true) lookup_commands_dynamic;
   29.11  
    30.1 --- a/src/Pure/Isar/parse.ML	Tue Mar 18 09:39:07 2014 -0700
    30.2 +++ b/src/Pure/Isar/parse.ML	Tue Mar 18 21:02:33 2014 +0100
    30.3 @@ -15,6 +15,7 @@
    30.4    val triple2: 'a * ('b * 'c) -> 'a * 'b * 'c
    30.5    val triple_swap: ('a * 'b) * 'c -> ('a * 'c) * 'b
    30.6    val not_eof: Token.T parser
    30.7 +  val token: 'a parser -> Token.T parser
    30.8    val position: 'a parser -> ('a * Position.T) parser
    30.9    val source_position: 'a parser -> Symbol_Pos.source parser
   30.10    val inner_syntax: 'a parser -> string parser
   30.11 @@ -37,6 +38,8 @@
   30.12    val eof: string parser
   30.13    val command_name: string -> string parser
   30.14    val keyword_with: (string -> bool) -> string parser
   30.15 +  val keyword_markup: bool * Markup.T -> string -> string parser
   30.16 +  val keyword_improper: string -> string parser
   30.17    val $$$ : string -> string parser
   30.18    val reserved: string -> string parser
   30.19    val semicolon: string parser
   30.20 @@ -104,6 +107,8 @@
   30.21    val termp: (string * string list) parser
   30.22    val target: (xstring * Position.T) parser
   30.23    val opt_target: (xstring * Position.T) option parser
   30.24 +  val args: Token.T list parser
   30.25 +  val args1: (string -> bool) -> Token.T list parser
   30.26  end;
   30.27  
   30.28  structure Parse: PARSE =
   30.29 @@ -168,6 +173,8 @@
   30.30  
   30.31  val not_eof = RESET_VALUE (Scan.one Token.not_eof);
   30.32  
   30.33 +fun token atom = Scan.ahead not_eof --| atom;
   30.34 +
   30.35  fun position scan = (Scan.ahead not_eof >> Token.pos_of) -- scan >> Library.swap;
   30.36  fun source_position atom = Scan.ahead atom |-- not_eof >> Token.source_position_of;
   30.37  fun inner_syntax atom = Scan.ahead atom |-- not_eof >> Token.inner_syntax_of;
   30.38 @@ -193,17 +200,20 @@
   30.39  val sync = kind Token.Sync;
   30.40  val eof = kind Token.EOF;
   30.41  
   30.42 -fun keyword_with pred = RESET_VALUE (Scan.one (Token.keyword_with pred) >> Token.content_of);
   30.43 -
   30.44  fun command_name x =
   30.45    group (fn () => Token.str_of_kind Token.Command ^ " " ^ quote x)
   30.46      (RESET_VALUE (Scan.one (fn tok => Token.is_command tok andalso Token.content_of tok = x)))
   30.47    >> Token.content_of;
   30.48  
   30.49 -fun $$$ x =
   30.50 +fun keyword_with pred = RESET_VALUE (Scan.one (Token.keyword_with pred) >> Token.content_of);
   30.51 +
   30.52 +fun keyword_markup markup x =
   30.53    group (fn () => Token.str_of_kind Token.Keyword ^ " " ^ quote x)
   30.54      (Scan.ahead not_eof -- keyword_with (fn y => x = y))
   30.55 -  >> (fn (tok, x) => (Token.assign (SOME (Token.Literal Markup.quasi_keyword)) tok; x));
   30.56 +  >> (fn (tok, x) => (Token.assign (SOME (Token.Literal markup)) tok; x));
   30.57 +
   30.58 +val keyword_improper = keyword_markup (true, Markup.improper);
   30.59 +val $$$ = keyword_markup (false, Markup.quasi_keyword);
   30.60  
   30.61  fun reserved x =
   30.62    group (fn () => "reserved identifier " ^ quote x)
   30.63 @@ -393,6 +403,42 @@
   30.64  val target = ($$$ "(" -- $$$ "in") |-- !!! (position xname --| $$$ ")");
   30.65  val opt_target = Scan.option target;
   30.66  
   30.67 +
   30.68 +(* arguments within outer syntax *)
   30.69 +
   30.70 +local
   30.71 +
   30.72 +val argument_kinds =
   30.73 + [Token.Ident, Token.LongIdent, Token.SymIdent, Token.Var, Token.TypeIdent, Token.TypeVar,
   30.74 +  Token.Nat, Token.Float, Token.String, Token.AltString, Token.Cartouche, Token.Verbatim];
   30.75 +
   30.76 +fun arguments is_symid =
   30.77 +  let
   30.78 +    fun argument blk =
   30.79 +      group (fn () => "argument")
   30.80 +        (Scan.one (fn tok =>
   30.81 +          let val kind = Token.kind_of tok in
   30.82 +            member (op =) argument_kinds kind orelse
   30.83 +            Token.keyword_with is_symid tok orelse
   30.84 +            (blk andalso Token.keyword_with (fn s => s = ",") tok)
   30.85 +          end));
   30.86 +
   30.87 +    fun args blk x = Scan.optional (args1 blk) [] x
   30.88 +    and args1 blk x =
   30.89 +      ((Scan.repeat1
   30.90 +        (Scan.repeat1 (argument blk) ||
   30.91 +          argsp "(" ")" ||
   30.92 +          argsp "[" "]")) >> flat) x
   30.93 +    and argsp l r x = (token ($$$ l) ::: !!! (args true @@@ (token ($$$ r) >> single))) x;
   30.94 +  in (args, args1) end;
   30.95 +
   30.96 +in
   30.97 +
   30.98 +val args = #1 (arguments Token.ident_or_symbolic) false;
   30.99 +fun args1 is_symid = #2 (arguments is_symid) false;
  30.100 +
  30.101 +end;
  30.102 +
  30.103  end;
  30.104  
  30.105  type 'a parser = 'a Parse.parser;
    31.1 --- a/src/Pure/Isar/parse.scala	Tue Mar 18 09:39:07 2014 -0700
    31.2 +++ b/src/Pure/Isar/parse.scala	Tue Mar 18 21:02:33 2014 +0100
    31.3 @@ -64,7 +64,7 @@
    31.4      def path: Parser[String] =
    31.5        atom("file name/path specification", tok => tok.is_name && Path.is_wellformed(tok.content))
    31.6      def theory_name: Parser[String] =
    31.7 -      atom("theory name", tok => tok.is_name && Thy_Load.is_wellformed(tok.content))
    31.8 +      atom("theory name", tok => tok.is_name && Path.is_wellformed(tok.content))
    31.9  
   31.10      private def tag_name: Parser[String] =
   31.11        atom("tag name", tok =>
    32.1 --- a/src/Pure/Isar/parse_spec.ML	Tue Mar 18 09:39:07 2014 -0700
    32.2 +++ b/src/Pure/Isar/parse_spec.ML	Tue Mar 18 21:02:33 2014 +0100
    32.3 @@ -37,7 +37,7 @@
    32.4  
    32.5  (* theorem specifications *)
    32.6  
    32.7 -val attrib = Parse.position Parse.liberal_name -- Parse.!!! Args.parse >> uncurry Args.src;
    32.8 +val attrib = Parse.position Parse.liberal_name -- Parse.!!! Parse.args >> uncurry Args.src;
    32.9  val attribs = Parse.$$$ "[" |-- Parse.list attrib --| Parse.$$$ "]";
   32.10  val opt_attribs = Scan.optional attribs [];
   32.11  
    33.1 --- a/src/Pure/Isar/proof_context.ML	Tue Mar 18 09:39:07 2014 -0700
    33.2 +++ b/src/Pure/Isar/proof_context.ML	Tue Mar 18 21:02:33 2014 +0100
    33.3 @@ -1204,8 +1204,9 @@
    33.4  
    33.5  fun check_case ctxt (name, pos) fxs =
    33.6    let
    33.7 -    val (_, ((Rule_Cases.Case {fixes, assumes, binds, cases}, _), _)) =
    33.8 +    val (_, ((Rule_Cases.Case {fixes, assumes, binds, cases}, is_proper), _)) =
    33.9        Name_Space.check (Context.Proof ctxt) (cases_of ctxt) (name, pos);
   33.10 +    val _ = if is_proper then () else Context_Position.report ctxt pos Markup.improper;
   33.11  
   33.12      fun replace (opt_x :: xs) ((y, T) :: ys) = (the_default y opt_x, T) :: replace xs ys
   33.13        | replace [] ys = ys
    34.1 --- a/src/Pure/Isar/token.ML	Tue Mar 18 09:39:07 2014 -0700
    34.2 +++ b/src/Pure/Isar/token.ML	Tue Mar 18 21:02:33 2014 +0100
    34.3 @@ -12,7 +12,7 @@
    34.4      Error of string | Sync | EOF
    34.5    type file = {src_path: Path.T, lines: string list, digest: SHA1.digest, pos: Position.T}
    34.6    datatype value =
    34.7 -    Literal of Markup.T | Text of string | Typ of typ | Term of term | Fact of thm list |
    34.8 +    Literal of bool * Markup.T | Text of string | Typ of typ | Term of term | Fact of thm list |
    34.9      Attribute of morphism -> attribute | Files of file Exn.result list
   34.10    type T
   34.11    val str_of_kind: kind -> string
   34.12 @@ -42,7 +42,7 @@
   34.13    val inner_syntax_of: T -> string
   34.14    val source_position_of: T -> Symbol_Pos.source
   34.15    val content_of: T -> string
   34.16 -  val keyword_markup: Markup.T -> string -> Markup.T
   34.17 +  val keyword_markup: bool * Markup.T -> string -> Markup.T
   34.18    val completion_report: T -> Position.report_text list
   34.19    val report: T -> Position.report_text
   34.20    val markup: T -> Markup.T
   34.21 @@ -87,7 +87,7 @@
   34.22  type file = {src_path: Path.T, lines: string list, digest: SHA1.digest, pos: Position.T};
   34.23  
   34.24  datatype value =
   34.25 -  Literal of Markup.T |
   34.26 +  Literal of bool * Markup.T |
   34.27    Text of string |
   34.28    Typ of typ |
   34.29    Term of term |
   34.30 @@ -255,8 +255,8 @@
   34.31  
   34.32  in
   34.33  
   34.34 -fun keyword_markup keyword x =
   34.35 -  if Symbol.is_ascii_identifier x then keyword else Markup.delimiter;
   34.36 +fun keyword_markup (important, keyword) x =
   34.37 +  if important orelse Symbol.is_ascii_identifier x then keyword else Markup.delimiter;
   34.38  
   34.39  fun completion_report tok =
   34.40    if is_kind Keyword tok
   34.41 @@ -265,7 +265,7 @@
   34.42  
   34.43  fun report tok =
   34.44    if is_kind Keyword tok then
   34.45 -    ((pos_of tok, keyword_markup Markup.keyword2 (content_of tok)), "")
   34.46 +    ((pos_of tok, keyword_markup (false, Markup.keyword2) (content_of tok)), "")
   34.47    else
   34.48      let val (m, text) = token_kind_markup (kind_of tok)
   34.49      in ((pos_of tok, m), text) end;
    35.1 --- a/src/Pure/ML/ml_antiquotation.ML	Tue Mar 18 09:39:07 2014 -0700
    35.2 +++ b/src/Pure/ML/ml_antiquotation.ML	Tue Mar 18 21:02:33 2014 +0100
    35.3 @@ -1,13 +1,15 @@
    35.4  (*  Title:      Pure/ML/ml_antiquotation.ML
    35.5      Author:     Makarius
    35.6  
    35.7 -Convenience operations for common ML antiquotations.  Miscellaneous
    35.8 -predefined antiquotations.
    35.9 +ML antiquotations.
   35.10  *)
   35.11  
   35.12  signature ML_ANTIQUOTATION =
   35.13  sig
   35.14    val variant: string -> Proof.context -> string * Proof.context
   35.15 +  val declaration: binding -> 'a context_parser ->
   35.16 +    (Args.src -> 'a -> Proof.context -> ML_Context.decl * Proof.context) ->
   35.17 +    theory -> theory
   35.18    val inline: binding -> string context_parser -> theory -> theory
   35.19    val value: binding -> string context_parser -> theory -> theory
   35.20  end;
   35.21 @@ -15,9 +17,7 @@
   35.22  structure ML_Antiquotation: ML_ANTIQUOTATION =
   35.23  struct
   35.24  
   35.25 -(** generic tools **)
   35.26 -
   35.27 -(* ML names *)
   35.28 +(* unique names *)
   35.29  
   35.30  val init_context = ML_Syntax.reserved |> Name.declare "ML_context";
   35.31  
   35.32 @@ -35,13 +35,19 @@
   35.33    in (b, ctxt') end;
   35.34  
   35.35  
   35.36 -(* specific antiquotations *)
   35.37 +(* define antiquotations *)
   35.38 +
   35.39 +fun declaration name scan body =
   35.40 +  ML_Context.add_antiquotation name
   35.41 +    (fn src => fn orig_ctxt =>
   35.42 +      let val (x, _) = Args.syntax scan src orig_ctxt
   35.43 +      in body src x orig_ctxt end);
   35.44  
   35.45  fun inline name scan =
   35.46 -  ML_Context.antiquotation name scan (fn _ => fn s => fn ctxt => (K ("", s), ctxt));
   35.47 +  declaration name scan (fn _ => fn s => fn ctxt => (K ("", s), ctxt));
   35.48  
   35.49  fun value name scan =
   35.50 -  ML_Context.antiquotation name scan (fn _ => fn s => fn ctxt =>
   35.51 +  declaration name scan (fn _ => fn s => fn ctxt =>
   35.52      let
   35.53        val (a, ctxt') = variant (Binding.name_of name) ctxt;
   35.54        val env = "val " ^ a ^ " = " ^ s ^ ";\n";
   35.55 @@ -49,11 +55,10 @@
   35.56      in (K (env, body), ctxt') end);
   35.57  
   35.58  
   35.59 -
   35.60 -(** misc antiquotations **)
   35.61 +(* basic antiquotations *)
   35.62  
   35.63  val _ = Theory.setup
   35.64 - (ML_Context.antiquotation (Binding.name "here") (Scan.succeed ())
   35.65 + (declaration (Binding.name "here") (Scan.succeed ())
   35.66      (fn src => fn () => fn ctxt =>
   35.67        let
   35.68          val (a, ctxt') = variant "position" ctxt;
   35.69 @@ -62,163 +67,8 @@
   35.70          val body = "Isabelle." ^ a;
   35.71        in (K (env, body), ctxt') end) #>
   35.72  
   35.73 -  inline (Binding.name "assert")
   35.74 -    (Scan.succeed "(fn b => if b then () else raise General.Fail \"Assertion failed\")") #>
   35.75 -
   35.76 -  inline (Binding.name "make_string") (Scan.succeed ml_make_string) #>
   35.77 -
   35.78 -  value (Binding.name "option") (Scan.lift (Parse.position Args.name) >> (fn (name, pos) =>
   35.79 -    (Options.default_typ name handle ERROR msg => error (msg ^ Position.here pos);
   35.80 -     ML_Syntax.print_string name))) #>
   35.81 -
   35.82    value (Binding.name "binding")
   35.83 -    (Scan.lift (Parse.position Args.name) >> ML_Syntax.make_binding) #>
   35.84 -
   35.85 -  value (Binding.name "theory")
   35.86 -    (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (name, pos)) =>
   35.87 -      (Context_Position.report ctxt pos
   35.88 -        (Theory.get_markup (Context.get_theory (Proof_Context.theory_of ctxt) name));
   35.89 -       "Context.get_theory (Proof_Context.theory_of ML_context) " ^ ML_Syntax.print_string name))
   35.90 -    || Scan.succeed "Proof_Context.theory_of ML_context") #>
   35.91 -
   35.92 -  value (Binding.name "theory_context")
   35.93 -    (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (name, pos)) =>
   35.94 -      (Context_Position.report ctxt pos
   35.95 -        (Theory.get_markup (Context.get_theory (Proof_Context.theory_of ctxt) name));
   35.96 -       "Proof_Context.get_global (Proof_Context.theory_of ML_context) " ^
   35.97 -        ML_Syntax.print_string name))) #>
   35.98 -
   35.99 -  inline (Binding.name "context") (Scan.succeed "Isabelle.ML_context") #>
  35.100 -
  35.101 -  inline (Binding.name "typ") (Args.typ >> (ML_Syntax.atomic o ML_Syntax.print_typ)) #>
  35.102 -  inline (Binding.name "term") (Args.term >> (ML_Syntax.atomic o ML_Syntax.print_term)) #>
  35.103 -  inline (Binding.name "prop") (Args.prop >> (ML_Syntax.atomic o ML_Syntax.print_term)) #>
  35.104 -
  35.105 -  value (Binding.name "ctyp") (Args.typ >> (fn T =>
  35.106 -    "Thm.ctyp_of (Proof_Context.theory_of ML_context) " ^
  35.107 -      ML_Syntax.atomic (ML_Syntax.print_typ T))) #>
  35.108 -
  35.109 -  value (Binding.name "cterm") (Args.term >> (fn t =>
  35.110 -    "Thm.cterm_of (Proof_Context.theory_of ML_context) " ^
  35.111 -     ML_Syntax.atomic (ML_Syntax.print_term t))) #>
  35.112 -
  35.113 -  value (Binding.name "cprop") (Args.prop >> (fn t =>
  35.114 -    "Thm.cterm_of (Proof_Context.theory_of ML_context) " ^
  35.115 -     ML_Syntax.atomic (ML_Syntax.print_term t))) #>
  35.116 -
  35.117 -  value (Binding.name "cpat")
  35.118 -    (Args.context --
  35.119 -      Scan.lift Args.name_inner_syntax >> uncurry Proof_Context.read_term_pattern >> (fn t =>
  35.120 -        "Thm.cterm_of (Proof_Context.theory_of ML_context) " ^
  35.121 -          ML_Syntax.atomic (ML_Syntax.print_term t))));
  35.122 -
  35.123 -
  35.124 -(* type classes *)
  35.125 -
  35.126 -fun class syn = Args.context -- Scan.lift Args.name_inner_syntax >> (fn (ctxt, s) =>
  35.127 -  Proof_Context.read_class ctxt s
  35.128 -  |> syn ? Lexicon.mark_class
  35.129 -  |> ML_Syntax.print_string);
  35.130 -
  35.131 -val _ = Theory.setup
  35.132 - (inline (Binding.name "class") (class false) #>
  35.133 -  inline (Binding.name "class_syntax") (class true) #>
  35.134 -
  35.135 -  inline (Binding.name "sort")
  35.136 -    (Args.context -- Scan.lift Args.name_inner_syntax >> (fn (ctxt, s) =>
  35.137 -      ML_Syntax.atomic (ML_Syntax.print_sort (Syntax.read_sort ctxt s)))));
  35.138 -
  35.139 -
  35.140 -(* type constructors *)
  35.141 -
  35.142 -fun type_name kind check = Args.context -- Scan.lift (Parse.position Args.name_inner_syntax)
  35.143 -  >> (fn (ctxt, (s, pos)) =>
  35.144 -    let
  35.145 -      val Type (c, _) = Proof_Context.read_type_name {proper = true, strict = false} ctxt s;
  35.146 -      val decl = Type.the_decl (Proof_Context.tsig_of ctxt) (c, pos);
  35.147 -      val res =
  35.148 -        (case try check (c, decl) of
  35.149 -          SOME res => res
  35.150 -        | NONE => error ("Not a " ^ kind ^ ": " ^ quote c ^ Position.here pos));
  35.151 -    in ML_Syntax.print_string res end);
  35.152 -
  35.153 -val _ = Theory.setup
  35.154 - (inline (Binding.name "type_name")
  35.155 -    (type_name "logical type" (fn (c, Type.LogicalType _) => c)) #>
  35.156 -  inline (Binding.name "type_abbrev")
  35.157 -    (type_name "type abbreviation" (fn (c, Type.Abbreviation _) => c)) #>
  35.158 -  inline (Binding.name "nonterminal")
  35.159 -    (type_name "nonterminal" (fn (c, Type.Nonterminal) => c)) #>
  35.160 -  inline (Binding.name "type_syntax")
  35.161 -    (type_name "type" (fn (c, _) => Lexicon.mark_type c)));
  35.162 -
  35.163 -
  35.164 -(* constants *)
  35.165 -
  35.166 -fun const_name check = Args.context -- Scan.lift (Parse.position Args.name_inner_syntax)
  35.167 -  >> (fn (ctxt, (s, pos)) =>
  35.168 -    let
  35.169 -      val Const (c, _) = Proof_Context.read_const {proper = true, strict = false} ctxt s;
  35.170 -      val res = check (Proof_Context.consts_of ctxt, c)
  35.171 -        handle TYPE (msg, _, _) => error (msg ^ Position.here pos);
  35.172 -    in ML_Syntax.print_string res end);
  35.173 -
  35.174 -val _ = Theory.setup
  35.175 - (inline (Binding.name "const_name")
  35.176 -    (const_name (fn (consts, c) => (Consts.the_const consts c; c))) #>
  35.177 -  inline (Binding.name "const_abbrev")
  35.178 -    (const_name (fn (consts, c) => (Consts.the_abbreviation consts c; c))) #>
  35.179 -  inline (Binding.name "const_syntax")
  35.180 -    (const_name (fn (_, c) => Lexicon.mark_const c)) #>
  35.181 -
  35.182 -  inline (Binding.name "syntax_const")
  35.183 -    (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (c, pos)) =>
  35.184 -      if is_some (Syntax.lookup_const (Proof_Context.syn_of ctxt) c)
  35.185 -      then ML_Syntax.print_string c
  35.186 -      else error ("Unknown syntax const: " ^ quote c ^ Position.here pos))) #>
  35.187 -
  35.188 -  inline (Binding.name "const")
  35.189 -    (Args.context -- Scan.lift Args.name_inner_syntax -- Scan.optional
  35.190 -        (Scan.lift (Args.$$$ "(") |-- Parse.enum1' "," Args.typ --| Scan.lift (Args.$$$ ")")) []
  35.191 -      >> (fn ((ctxt, raw_c), Ts) =>
  35.192 -        let
  35.193 -          val Const (c, _) =
  35.194 -            Proof_Context.read_const {proper = true, strict = true} ctxt raw_c;
  35.195 -          val consts = Proof_Context.consts_of ctxt;
  35.196 -          val n = length (Consts.typargs consts (c, Consts.type_scheme consts c));
  35.197 -          val _ = length Ts <> n andalso
  35.198 -            error ("Constant requires " ^ string_of_int n ^ " type argument(s): " ^
  35.199 -              quote c ^ enclose "(" ")" (commas (replicate n "_")));
  35.200 -          val const = Const (c, Consts.instance consts (c, Ts));
  35.201 -        in ML_Syntax.atomic (ML_Syntax.print_term const) end)));
  35.202 -
  35.203 -
  35.204 -(* outer syntax *)
  35.205 -
  35.206 -fun with_keyword f =
  35.207 -  Args.theory -- Scan.lift (Parse.position Parse.string) >> (fn (thy, (name, pos)) =>
  35.208 -    (f ((name, Thy_Header.the_keyword thy name), pos)
  35.209 -      handle ERROR msg => error (msg ^ Position.here pos)));
  35.210 -
  35.211 -val _ = Theory.setup
  35.212 - (value (Binding.name "keyword")
  35.213 -    (with_keyword
  35.214 -      (fn ((name, NONE), _) => "Parse.$$$ " ^ ML_Syntax.print_string name
  35.215 -        | ((name, SOME _), pos) =>
  35.216 -            error ("Expected minor keyword " ^ quote name ^ Position.here pos))) #>
  35.217 -  value (Binding.name "command_spec")
  35.218 -    (with_keyword
  35.219 -      (fn ((name, SOME kind), pos) =>
  35.220 -          "Keyword.command_spec " ^ ML_Syntax.atomic
  35.221 -            ((ML_Syntax.print_pair
  35.222 -              (ML_Syntax.print_pair ML_Syntax.print_string
  35.223 -                (ML_Syntax.print_pair
  35.224 -                  (ML_Syntax.print_pair ML_Syntax.print_string
  35.225 -                    (ML_Syntax.print_list ML_Syntax.print_string))
  35.226 -                  (ML_Syntax.print_list ML_Syntax.print_string)))
  35.227 -              ML_Syntax.print_position) ((name, kind), pos))
  35.228 -        | ((name, NONE), pos) =>
  35.229 -            error ("Expected command keyword " ^ quote name ^ Position.here pos))));
  35.230 +    (Scan.lift (Parse.position Args.name) >> ML_Syntax.make_binding));
  35.231  
  35.232  end;
  35.233  
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/src/Pure/ML/ml_antiquotations.ML	Tue Mar 18 21:02:33 2014 +0100
    36.3 @@ -0,0 +1,167 @@
    36.4 +(*  Title:      Pure/ML/ml_antiquotations.ML
    36.5 +    Author:     Makarius
    36.6 +
    36.7 +Miscellaneous ML antiquotations.
    36.8 +*)
    36.9 +
   36.10 +structure ML_Antiquotations: sig end =
   36.11 +struct
   36.12 +
   36.13 +val _ = Theory.setup
   36.14 + (ML_Antiquotation.inline @{binding assert}
   36.15 +    (Scan.succeed "(fn b => if b then () else raise General.Fail \"Assertion failed\")") #>
   36.16 +
   36.17 +  ML_Antiquotation.inline @{binding make_string} (Scan.succeed ml_make_string) #>
   36.18 +
   36.19 +  ML_Antiquotation.value @{binding option} (Scan.lift (Parse.position Args.name) >> (fn (name, pos) =>
   36.20 +    (Options.default_typ name handle ERROR msg => error (msg ^ Position.here pos);
   36.21 +     ML_Syntax.print_string name))) #>
   36.22 +
   36.23 +  ML_Antiquotation.value @{binding theory}
   36.24 +    (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (name, pos)) =>
   36.25 +      (Context_Position.report ctxt pos
   36.26 +        (Theory.get_markup (Context.get_theory (Proof_Context.theory_of ctxt) name));
   36.27 +       "Context.get_theory (Proof_Context.theory_of ML_context) " ^ ML_Syntax.print_string name))
   36.28 +    || Scan.succeed "Proof_Context.theory_of ML_context") #>
   36.29 +
   36.30 +  ML_Antiquotation.value @{binding theory_context}
   36.31 +    (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (name, pos)) =>
   36.32 +      (Context_Position.report ctxt pos
   36.33 +        (Theory.get_markup (Context.get_theory (Proof_Context.theory_of ctxt) name));
   36.34 +       "Proof_Context.get_global (Proof_Context.theory_of ML_context) " ^
   36.35 +        ML_Syntax.print_string name))) #>
   36.36 +
   36.37 +  ML_Antiquotation.inline @{binding context} (Scan.succeed "Isabelle.ML_context") #>
   36.38 +
   36.39 +  ML_Antiquotation.inline @{binding typ} (Args.typ >> (ML_Syntax.atomic o ML_Syntax.print_typ)) #>
   36.40 +  ML_Antiquotation.inline @{binding term} (Args.term >> (ML_Syntax.atomic o ML_Syntax.print_term)) #>
   36.41 +  ML_Antiquotation.inline @{binding prop} (Args.prop >> (ML_Syntax.atomic o ML_Syntax.print_term)) #>
   36.42 +
   36.43 +  ML_Antiquotation.value @{binding ctyp} (Args.typ >> (fn T =>
   36.44 +    "Thm.ctyp_of (Proof_Context.theory_of ML_context) " ^
   36.45 +      ML_Syntax.atomic (ML_Syntax.print_typ T))) #>
   36.46 +
   36.47 +  ML_Antiquotation.value @{binding cterm} (Args.term >> (fn t =>
   36.48 +    "Thm.cterm_of (Proof_Context.theory_of ML_context) " ^
   36.49 +     ML_Syntax.atomic (ML_Syntax.print_term t))) #>
   36.50 +
   36.51 +  ML_Antiquotation.value @{binding cprop} (Args.prop >> (fn t =>
   36.52 +    "Thm.cterm_of (Proof_Context.theory_of ML_context) " ^
   36.53 +     ML_Syntax.atomic (ML_Syntax.print_term t))) #>
   36.54 +
   36.55 +  ML_Antiquotation.value @{binding cpat}
   36.56 +    (Args.context --
   36.57 +      Scan.lift Args.name_inner_syntax >> uncurry Proof_Context.read_term_pattern >> (fn t =>
   36.58 +        "Thm.cterm_of (Proof_Context.theory_of ML_context) " ^
   36.59 +          ML_Syntax.atomic (ML_Syntax.print_term t))));
   36.60 +
   36.61 +
   36.62 +(* type classes *)
   36.63 +
   36.64 +fun class syn = Args.context -- Scan.lift Args.name_inner_syntax >> (fn (ctxt, s) =>
   36.65 +  Proof_Context.read_class ctxt s
   36.66 +  |> syn ? Lexicon.mark_class
   36.67 +  |> ML_Syntax.print_string);
   36.68 +
   36.69 +val _ = Theory.setup
   36.70 + (ML_Antiquotation.inline @{binding class} (class false) #>
   36.71 +  ML_Antiquotation.inline @{binding class_syntax} (class true) #>
   36.72 +
   36.73 +  ML_Antiquotation.inline @{binding sort}
   36.74 +    (Args.context -- Scan.lift Args.name_inner_syntax >> (fn (ctxt, s) =>
   36.75 +      ML_Syntax.atomic (ML_Syntax.print_sort (Syntax.read_sort ctxt s)))));
   36.76 +
   36.77 +
   36.78 +(* type constructors *)
   36.79 +
   36.80 +fun type_name kind check = Args.context -- Scan.lift (Parse.position Args.name_inner_syntax)
   36.81 +  >> (fn (ctxt, (s, pos)) =>
   36.82 +    let
   36.83 +      val Type (c, _) = Proof_Context.read_type_name {proper = true, strict = false} ctxt s;
   36.84 +      val decl = Type.the_decl (Proof_Context.tsig_of ctxt) (c, pos);
   36.85 +      val res =
   36.86 +        (case try check (c, decl) of
   36.87 +          SOME res => res
   36.88 +        | NONE => error ("Not a " ^ kind ^ ": " ^ quote c ^ Position.here pos));
   36.89 +    in ML_Syntax.print_string res end);
   36.90 +
   36.91 +val _ = Theory.setup
   36.92 + (ML_Antiquotation.inline @{binding type_name}
   36.93 +    (type_name "logical type" (fn (c, Type.LogicalType _) => c)) #>
   36.94 +  ML_Antiquotation.inline @{binding type_abbrev}
   36.95 +    (type_name "type abbreviation" (fn (c, Type.Abbreviation _) => c)) #>
   36.96 +  ML_Antiquotation.inline @{binding nonterminal}
   36.97 +    (type_name "nonterminal" (fn (c, Type.Nonterminal) => c)) #>
   36.98 +  ML_Antiquotation.inline @{binding type_syntax}
   36.99 +    (type_name "type" (fn (c, _) => Lexicon.mark_type c)));
  36.100 +
  36.101 +
  36.102 +(* constants *)
  36.103 +
  36.104 +fun const_name check = Args.context -- Scan.lift (Parse.position Args.name_inner_syntax)
  36.105 +  >> (fn (ctxt, (s, pos)) =>
  36.106 +    let
  36.107 +      val Const (c, _) = Proof_Context.read_const {proper = true, strict = false} ctxt s;
  36.108 +      val res = check (Proof_Context.consts_of ctxt, c)
  36.109 +        handle TYPE (msg, _, _) => error (msg ^ Position.here pos);
  36.110 +    in ML_Syntax.print_string res end);
  36.111 +
  36.112 +val _ = Theory.setup
  36.113 + (ML_Antiquotation.inline @{binding const_name}
  36.114 +    (const_name (fn (consts, c) => (Consts.the_const consts c; c))) #>
  36.115 +  ML_Antiquotation.inline @{binding const_abbrev}
  36.116 +    (const_name (fn (consts, c) => (Consts.the_abbreviation consts c; c))) #>
  36.117 +  ML_Antiquotation.inline @{binding const_syntax}
  36.118 +    (const_name (fn (_, c) => Lexicon.mark_const c)) #>
  36.119 +
  36.120 +  ML_Antiquotation.inline @{binding syntax_const}
  36.121 +    (Args.context -- Scan.lift (Parse.position Args.name) >> (fn (ctxt, (c, pos)) =>
  36.122 +      if is_some (Syntax.lookup_const (Proof_Context.syn_of ctxt) c)
  36.123 +      then ML_Syntax.print_string c
  36.124 +      else error ("Unknown syntax const: " ^ quote c ^ Position.here pos))) #>
  36.125 +
  36.126 +  ML_Antiquotation.inline @{binding const}
  36.127 +    (Args.context -- Scan.lift Args.name_inner_syntax -- Scan.optional
  36.128 +        (Scan.lift (Args.$$$ "(") |-- Parse.enum1' "," Args.typ --| Scan.lift (Args.$$$ ")")) []
  36.129 +      >> (fn ((ctxt, raw_c), Ts) =>
  36.130 +        let
  36.131 +          val Const (c, _) =
  36.132 +            Proof_Context.read_const {proper = true, strict = true} ctxt raw_c;
  36.133 +          val consts = Proof_Context.consts_of ctxt;
  36.134 +          val n = length (Consts.typargs consts (c, Consts.type_scheme consts c));
  36.135 +          val _ = length Ts <> n andalso
  36.136 +            error ("Constant requires " ^ string_of_int n ^ " type argument(s): " ^
  36.137 +              quote c ^ enclose "(" ")" (commas (replicate n "_")));
  36.138 +          val const = Const (c, Consts.instance consts (c, Ts));
  36.139 +        in ML_Syntax.atomic (ML_Syntax.print_term const) end)));
  36.140 +
  36.141 +
  36.142 +(* outer syntax *)
  36.143 +
  36.144 +fun with_keyword f =
  36.145 +  Args.theory -- Scan.lift (Parse.position Parse.string) >> (fn (thy, (name, pos)) =>
  36.146 +    (f ((name, Thy_Header.the_keyword thy name), pos)
  36.147 +      handle ERROR msg => error (msg ^ Position.here pos)));
  36.148 +
  36.149 +val _ = Theory.setup
  36.150 + (ML_Antiquotation.value @{binding keyword}
  36.151 +    (with_keyword
  36.152 +      (fn ((name, NONE), _) => "Parse.$$$ " ^ ML_Syntax.print_string name
  36.153 +        | ((name, SOME _), pos) =>
  36.154 +            error ("Expected minor keyword " ^ quote name ^ Position.here pos))) #>
  36.155 +  ML_Antiquotation.value @{binding command_spec}
  36.156 +    (with_keyword
  36.157 +      (fn ((name, SOME kind), pos) =>
  36.158 +          "Keyword.command_spec " ^ ML_Syntax.atomic
  36.159 +            ((ML_Syntax.print_pair
  36.160 +              (ML_Syntax.print_pair ML_Syntax.print_string
  36.161 +                (ML_Syntax.print_pair
  36.162 +                  (ML_Syntax.print_pair ML_Syntax.print_string
  36.163 +                    (ML_Syntax.print_list ML_Syntax.print_string))
  36.164 +                  (ML_Syntax.print_list ML_Syntax.print_string)))
  36.165 +              ML_Syntax.print_position) ((name, kind), pos))
  36.166 +        | ((name, NONE), pos) =>
  36.167 +            error ("Expected command keyword " ^ quote name ^ Position.here pos))));
  36.168 +
  36.169 +end;
  36.170 +
    37.1 --- a/src/Pure/ML/ml_context.ML	Tue Mar 18 09:39:07 2014 -0700
    37.2 +++ b/src/Pure/ML/ml_context.ML	Tue Mar 18 21:02:33 2014 +0100
    37.3 @@ -4,35 +4,25 @@
    37.4  ML context and antiquotations.
    37.5  *)
    37.6  
    37.7 -signature BASIC_ML_CONTEXT =
    37.8 -sig
    37.9 -  val bind_thm: string * thm -> unit
   37.10 -  val bind_thms: string * thm list -> unit
   37.11 -end
   37.12 -
   37.13  signature ML_CONTEXT =
   37.14  sig
   37.15 -  include BASIC_ML_CONTEXT
   37.16    val the_generic_context: unit -> Context.generic
   37.17    val the_global_context: unit -> theory
   37.18    val the_local_context: unit -> Proof.context
   37.19    val thm: xstring -> thm
   37.20    val thms: xstring -> thm list
   37.21    val exec: (unit -> unit) -> Context.generic -> Context.generic
   37.22 -  val get_stored_thms: unit -> thm list
   37.23 -  val get_stored_thm: unit -> thm
   37.24 -  val ml_store_thms: string * thm list -> unit
   37.25 -  val ml_store_thm: string * thm -> unit
   37.26    val check_antiquotation: Proof.context -> xstring * Position.T -> string
   37.27 +  type decl = Proof.context -> string * string
   37.28 +  val add_antiquotation: binding -> (Args.src -> Proof.context -> decl * Proof.context) ->
   37.29 +    theory -> theory
   37.30    val print_antiquotations: Proof.context -> unit
   37.31 -  type decl = Proof.context -> string * string
   37.32 -  val antiquotation: binding -> 'a context_parser ->
   37.33 -    (Args.src -> 'a -> Proof.context -> decl * Proof.context) -> theory -> theory
   37.34    val trace_raw: Config.raw
   37.35    val trace: bool Config.T
   37.36    val eval_antiquotes: ML_Lex.token Antiquote.antiquote list * Position.T ->
   37.37      Context.generic option -> (ML_Lex.token list * ML_Lex.token list) * Context.generic option
   37.38    val eval: bool -> Position.T -> ML_Lex.token Antiquote.antiquote list -> unit
   37.39 +  val eval_file: bool -> Path.T -> unit
   37.40    val eval_source: bool -> Symbol_Pos.source -> unit
   37.41    val eval_in: Proof.context option -> bool -> Position.T ->
   37.42      ML_Lex.token Antiquote.antiquote list -> unit
   37.43 @@ -59,41 +49,6 @@
   37.44    | NONE => error "Missing context after execution");
   37.45  
   37.46  
   37.47 -(* theorem bindings *)
   37.48 -
   37.49 -structure Stored_Thms = Theory_Data
   37.50 -(
   37.51 -  type T = thm list;
   37.52 -  val empty = [];
   37.53 -  fun extend _ = [];
   37.54 -  fun merge _ = [];
   37.55 -);
   37.56 -
   37.57 -fun get_stored_thms () = Stored_Thms.get (the_global_context ());
   37.58 -val get_stored_thm = hd o get_stored_thms;
   37.59 -
   37.60 -fun ml_store get (name, ths) =
   37.61 -  let
   37.62 -    val ths' = Context.>>> (Context.map_theory_result
   37.63 -      (Global_Theory.store_thms (Binding.name name, ths)));
   37.64 -    val _ = Theory.setup (Stored_Thms.put ths');
   37.65 -    val _ =
   37.66 -      if name = "" then ()
   37.67 -      else if not (ML_Syntax.is_identifier name) then
   37.68 -        error ("Cannot bind theorem(s) " ^ quote name ^ " as ML value")
   37.69 -      else
   37.70 -        ML_Compiler.eval true Position.none
   37.71 -          (ML_Lex.tokenize ("val " ^ name ^ " = " ^ get ^ " ();"));
   37.72 -    val _ = Theory.setup (Stored_Thms.put []);
   37.73 -  in () end;
   37.74 -
   37.75 -val ml_store_thms = ml_store "ML_Context.get_stored_thms";
   37.76 -fun ml_store_thm (name, th) = ml_store "ML_Context.get_stored_thm" (name, [th]);
   37.77 -
   37.78 -fun bind_thm (name, thm) = ml_store_thm (name, Drule.export_without_context thm);
   37.79 -fun bind_thms (name, thms) = ml_store_thms (name, map Drule.export_without_context thms);
   37.80 -
   37.81 -
   37.82  
   37.83  (** ML antiquotations **)
   37.84  
   37.85 @@ -125,19 +80,13 @@
   37.86    let val (src', f) = Args.check_src ctxt (get_antiquotations ctxt) src
   37.87    in f src' ctxt end;
   37.88  
   37.89 -fun antiquotation name scan body =
   37.90 -  add_antiquotation name
   37.91 -    (fn src => fn orig_ctxt =>
   37.92 -      let val (x, _) = Args.syntax scan src orig_ctxt
   37.93 -      in body src x orig_ctxt end);
   37.94 -
   37.95  
   37.96  (* parsing and evaluation *)
   37.97  
   37.98  local
   37.99  
  37.100  val antiq =
  37.101 -  Parse.!!! (Parse.position Parse.xname -- Args.parse --| Scan.ahead Parse.eof)
  37.102 +  Parse.!!! (Parse.position Parse.xname -- Parse.args --| Scan.ahead Parse.eof)
  37.103    >> uncurry Args.src;
  37.104  
  37.105  val begin_env0 = ML_Lex.tokenize "structure Isabelle =\nstruct\n";
  37.106 @@ -220,6 +169,10 @@
  37.107  
  37.108  (* derived versions *)
  37.109  
  37.110 +fun eval_file verbose path =
  37.111 +  let val pos = Path.position path
  37.112 +  in eval verbose pos (ML_Lex.read pos (File.read path)) end;
  37.113 +
  37.114  fun eval_source verbose source =
  37.115    eval verbose (#pos source) (ML_Lex.read_source source);
  37.116  
  37.117 @@ -238,5 +191,3 @@
  37.118  
  37.119  end;
  37.120  
  37.121 -structure Basic_ML_Context: BASIC_ML_CONTEXT = ML_Context;
  37.122 -open Basic_ML_Context;
    38.1 --- a/src/Pure/ML/ml_env.ML	Tue Mar 18 09:39:07 2014 -0700
    38.2 +++ b/src/Pure/ML/ml_env.ML	Tue Mar 18 21:02:33 2014 +0100
    38.3 @@ -20,23 +20,26 @@
    38.4  structure Env = Generic_Data
    38.5  (
    38.6    type T =
    38.7 -    ML_Name_Space.valueVal Symtab.table *
    38.8 -    ML_Name_Space.typeVal Symtab.table *
    38.9 -    ML_Name_Space.fixityVal Symtab.table *
   38.10 -    ML_Name_Space.structureVal Symtab.table *
   38.11 -    ML_Name_Space.signatureVal Symtab.table *
   38.12 -    ML_Name_Space.functorVal Symtab.table;
   38.13 -  val empty = (Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty);
   38.14 -  val extend = I;
   38.15 +    bool * (*global bootstrap environment*)
   38.16 +     (ML_Name_Space.valueVal Symtab.table *
   38.17 +      ML_Name_Space.typeVal Symtab.table *
   38.18 +      ML_Name_Space.fixityVal Symtab.table *
   38.19 +      ML_Name_Space.structureVal Symtab.table *
   38.20 +      ML_Name_Space.signatureVal Symtab.table *
   38.21 +      ML_Name_Space.functorVal Symtab.table);
   38.22 +  val empty : T =
   38.23 +    (true, (Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty, Symtab.empty));
   38.24 +  fun extend (_, tabs) : T = (false, tabs);
   38.25    fun merge
   38.26 -   ((val1, type1, fixity1, structure1, signature1, functor1),
   38.27 -    (val2, type2, fixity2, structure2, signature2, functor2)) : T =
   38.28 -    (Symtab.merge (K true) (val1, val2),
   38.29 -     Symtab.merge (K true) (type1, type2),
   38.30 -     Symtab.merge (K true) (fixity1, fixity2),
   38.31 -     Symtab.merge (K true) (structure1, structure2),
   38.32 -     Symtab.merge (K true) (signature1, signature2),
   38.33 -     Symtab.merge (K true) (functor1, functor2));
   38.34 +   ((_, (val1, type1, fixity1, structure1, signature1, functor1)),
   38.35 +    (_, (val2, type2, fixity2, structure2, signature2, functor2))) : T =
   38.36 +    (false,
   38.37 +     (Symtab.merge (K true) (val1, val2),
   38.38 +      Symtab.merge (K true) (type1, type2),
   38.39 +      Symtab.merge (K true) (fixity1, fixity2),
   38.40 +      Symtab.merge (K true) (structure1, structure2),
   38.41 +      Symtab.merge (K true) (signature1, signature2),
   38.42 +      Symtab.merge (K true) (functor1, functor2)));
   38.43  );
   38.44  
   38.45  val inherit = Env.put o Env.get;
   38.46 @@ -48,18 +51,22 @@
   38.47    let
   38.48      fun lookup sel1 sel2 name =
   38.49        Context.thread_data ()
   38.50 -      |> (fn NONE => NONE | SOME context => Symtab.lookup (sel1 (Env.get context)) name)
   38.51 +      |> (fn NONE => NONE | SOME context => Symtab.lookup (sel1 (#2 (Env.get context))) name)
   38.52        |> (fn NONE => sel2 ML_Name_Space.global name | some => some);
   38.53  
   38.54      fun all sel1 sel2 () =
   38.55        Context.thread_data ()
   38.56 -      |> (fn NONE => [] | SOME context => Symtab.dest (sel1 (Env.get context)))
   38.57 +      |> (fn NONE => [] | SOME context => Symtab.dest (sel1 (#2 (Env.get context))))
   38.58        |> append (sel2 ML_Name_Space.global ())
   38.59        |> sort_distinct (string_ord o pairself #1);
   38.60  
   38.61      fun enter ap1 sel2 entry =
   38.62        if is_some (Context.thread_data ()) then
   38.63 -        Context.>> (Env.map (ap1 (Symtab.update entry)))
   38.64 +        Context.>> (Env.map (fn (global, tabs) =>
   38.65 +          let
   38.66 +            val _ = if global then sel2 ML_Name_Space.global entry else ();
   38.67 +            val tabs' = ap1 (Symtab.update entry) tabs;
   38.68 +          in (global, tabs') end))
   38.69        else sel2 ML_Name_Space.global entry;
   38.70    in
   38.71     {lookupVal    = lookup #1 #lookupVal,
    39.1 --- a/src/Pure/ML/ml_thms.ML	Tue Mar 18 09:39:07 2014 -0700
    39.2 +++ b/src/Pure/ML/ml_thms.ML	Tue Mar 18 21:02:33 2014 +0100
    39.3 @@ -8,6 +8,12 @@
    39.4  sig
    39.5    val the_attributes: Proof.context -> int -> Args.src list
    39.6    val the_thmss: Proof.context -> thm list list
    39.7 +  val get_stored_thms: unit -> thm list
    39.8 +  val get_stored_thm: unit -> thm
    39.9 +  val store_thms: string * thm list -> unit
   39.10 +  val store_thm: string * thm -> unit
   39.11 +  val bind_thm: string * thm -> unit
   39.12 +  val bind_thms: string * thm list -> unit
   39.13  end;
   39.14  
   39.15  structure ML_Thms: ML_THMS =
   39.16 @@ -35,7 +41,7 @@
   39.17  (* attribute source *)
   39.18  
   39.19  val _ = Theory.setup
   39.20 -  (ML_Context.antiquotation @{binding attributes} (Scan.lift Parse_Spec.attribs)
   39.21 +  (ML_Antiquotation.declaration @{binding attributes} (Scan.lift Parse_Spec.attribs)
   39.22      (fn _ => fn raw_srcs => fn ctxt =>
   39.23        let
   39.24          val i = serial ();
   39.25 @@ -68,8 +74,8 @@
   39.26    in (decl, ctxt'') end;
   39.27  
   39.28  val _ = Theory.setup
   39.29 -  (ML_Context.antiquotation @{binding thm} (Attrib.thm >> single) (K (thm_binding "thm" true)) #>
   39.30 -   ML_Context.antiquotation @{binding thms} Attrib.thms (K (thm_binding "thms" false)));
   39.31 +  (ML_Antiquotation.declaration @{binding thm} (Attrib.thm >> single) (K (thm_binding "thm" true)) #>
   39.32 +   ML_Antiquotation.declaration @{binding thms} Attrib.thms (K (thm_binding "thms" false)));
   39.33  
   39.34  
   39.35  (* ad-hoc goals *)
   39.36 @@ -79,7 +85,7 @@
   39.37  val goal = Scan.unless (by || and_) Args.name_inner_syntax;
   39.38  
   39.39  val _ = Theory.setup
   39.40 -  (ML_Context.antiquotation @{binding lemma}
   39.41 +  (ML_Antiquotation.declaration @{binding lemma}
   39.42      (Scan.lift (Args.mode "open" -- Parse.enum1 "and" (Scan.repeat1 goal) --
   39.43        (by |-- Method.parse -- Scan.option Method.parse)))
   39.44      (fn _ => fn ((is_open, raw_propss), (m1, m2)) => fn ctxt =>
   39.45 @@ -100,5 +106,40 @@
   39.46              (Facts.named (Proof_Context.full_name ctxt' (Binding.name Auto_Bind.thisN)));
   39.47        in thm_binding "lemma" (length (flat propss) = 1) thms ctxt end));
   39.48  
   39.49 +
   39.50 +(* old-style theorem bindings *)
   39.51 +
   39.52 +structure Stored_Thms = Theory_Data
   39.53 +(
   39.54 +  type T = thm list;
   39.55 +  val empty = [];
   39.56 +  fun extend _ = [];
   39.57 +  fun merge _ = [];
   39.58 +);
   39.59 +
   39.60 +fun get_stored_thms () = Stored_Thms.get (ML_Context.the_global_context ());
   39.61 +val get_stored_thm = hd o get_stored_thms;
   39.62 +
   39.63 +fun ml_store get (name, ths) =
   39.64 +  let
   39.65 +    val ths' = Context.>>> (Context.map_theory_result
   39.66 +      (Global_Theory.store_thms (Binding.name name, ths)));
   39.67 +    val _ = Theory.setup (Stored_Thms.put ths');
   39.68 +    val _ =
   39.69 +      if name = "" then ()
   39.70 +      else if not (ML_Syntax.is_identifier name) then
   39.71 +        error ("Cannot bind theorem(s) " ^ quote name ^ " as ML value")
   39.72 +      else
   39.73 +        ML_Compiler.eval true Position.none
   39.74 +          (ML_Lex.tokenize ("val " ^ name ^ " = " ^ get ^ " ();"));
   39.75 +    val _ = Theory.setup (Stored_Thms.put []);
   39.76 +  in () end;
   39.77 +
   39.78 +val store_thms = ml_store "ML_Thms.get_stored_thms";
   39.79 +fun store_thm (name, th) = ml_store "ML_Thms.get_stored_thm" (name, [th]);
   39.80 +
   39.81 +fun bind_thm (name, thm) = store_thm (name, Drule.export_without_context thm);
   39.82 +fun bind_thms (name, thms) = store_thms (name, map Drule.export_without_context thms);
   39.83 +
   39.84  end;
   39.85  
    40.1 --- a/src/Pure/PIDE/document.ML	Tue Mar 18 09:39:07 2014 -0700
    40.2 +++ b/src/Pure/PIDE/document.ML	Tue Mar 18 21:02:33 2014 +0100
    40.3 @@ -443,7 +443,7 @@
    40.4                  NONE => Toplevel.toplevel
    40.5                | SOME eval => Command.eval_result_state eval)));
    40.6      val _ = Position.reports (map #2 imports ~~ map Theory.get_markup parents);
    40.7 -  in Thy_Load.begin_theory master_dir header parents end;
    40.8 +  in Resources.begin_theory master_dir header parents end;
    40.9  
   40.10  fun check_theory full name node =
   40.11    is_some (loaded_theory name) orelse
    41.1 --- a/src/Pure/PIDE/markup.ML	Tue Mar 18 09:39:07 2014 -0700
    41.2 +++ b/src/Pure/PIDE/markup.ML	Tue Mar 18 21:02:33 2014 +0100
    41.3 @@ -105,7 +105,6 @@
    41.4    val paragraphN: string val paragraph: T
    41.5    val text_foldN: string val text_fold: T
    41.6    val commandN: string val command: T
    41.7 -  val operatorN: string val operator: T
    41.8    val stringN: string val string: T
    41.9    val altstringN: string val altstring: T
   41.10    val verbatimN: string val verbatim: T
   41.11 @@ -117,6 +116,8 @@
   41.12    val keyword2N: string val keyword2: T
   41.13    val keyword3N: string val keyword3: T
   41.14    val quasi_keywordN: string val quasi_keyword: T
   41.15 +  val improperN: string val improper: T
   41.16 +  val operatorN: string val operator: T
   41.17    val elapsedN: string
   41.18    val cpuN: string
   41.19    val gcN: string
   41.20 @@ -427,6 +428,7 @@
   41.21  val (keyword2N, keyword2) = markup_elem "keyword2";
   41.22  val (keyword3N, keyword3) = markup_elem "keyword3";
   41.23  val (quasi_keywordN, quasi_keyword) = markup_elem "quasi_keyword";
   41.24 +val (improperN, improper) = markup_elem "improper";
   41.25  val (operatorN, operator) = markup_elem "operator";
   41.26  val (stringN, string) = markup_elem "string";
   41.27  val (altstringN, altstring) = markup_elem "altstring";
    42.1 --- a/src/Pure/PIDE/markup.scala	Tue Mar 18 09:39:07 2014 -0700
    42.2 +++ b/src/Pure/PIDE/markup.scala	Tue Mar 18 21:02:33 2014 +0100
    42.3 @@ -216,6 +216,7 @@
    42.4    val KEYWORD2 = "keyword2"
    42.5    val KEYWORD3 = "keyword3"
    42.6    val QUASI_KEYWORD = "quasi_keyword"
    42.7 +  val IMPROPER = "improper"
    42.8    val OPERATOR = "operator"
    42.9    val STRING = "string"
   42.10    val ALTSTRING = "altstring"
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/src/Pure/PIDE/resources.ML	Tue Mar 18 21:02:33 2014 +0100
    43.3 @@ -0,0 +1,243 @@
    43.4 +(*  Title:      Pure/PIDE/resources.ML
    43.5 +    Author:     Makarius
    43.6 +
    43.7 +Resources for theories and auxiliary files.
    43.8 +*)
    43.9 +
   43.10 +signature RESOURCES =
   43.11 +sig
   43.12 +  val master_directory: theory -> Path.T
   43.13 +  val imports_of: theory -> (string * Position.T) list
   43.14 +  val thy_path: Path.T -> Path.T
   43.15 +  val check_thy: Path.T -> string ->
   43.16 +   {master: Path.T * SHA1.digest, text: string, theory_pos: Position.T,
   43.17 +    imports: (string * Position.T) list, keywords: Thy_Header.keywords}
   43.18 +  val parse_files: string -> (theory -> Token.file list) parser
   43.19 +  val provide: Path.T * SHA1.digest -> theory -> theory
   43.20 +  val provide_parse_files: string -> (theory -> Token.file list * theory) parser
   43.21 +  val load_file: theory -> Path.T -> (Path.T * SHA1.digest) * string
   43.22 +  val loaded_files: theory -> Path.T list
   43.23 +  val loaded_files_current: theory -> bool
   43.24 +  val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
   43.25 +  val load_thy: bool -> (Toplevel.transition -> Time.time option) -> int -> Path.T ->
   43.26 +    Thy_Header.header -> Position.T -> string -> theory list -> theory * (unit -> unit) * int
   43.27 +end;
   43.28 +
   43.29 +structure Resources: RESOURCES =
   43.30 +struct
   43.31 +
   43.32 +(* manage source files *)
   43.33 +
   43.34 +type files =
   43.35 + {master_dir: Path.T,  (*master directory of theory source*)
   43.36 +  imports: (string * Position.T) list,  (*source specification of imports*)
   43.37 +  provided: (Path.T * SHA1.digest) list};  (*source path, digest*)
   43.38 +
   43.39 +fun make_files (master_dir, imports, provided): files =
   43.40 + {master_dir = master_dir, imports = imports, provided = provided};
   43.41 +
   43.42 +structure Files = Theory_Data
   43.43 +(
   43.44 +  type T = files;
   43.45 +  val empty = make_files (Path.current, [], []);
   43.46 +  fun extend _ = empty;
   43.47 +  fun merge _ = empty;
   43.48 +);
   43.49 +
   43.50 +fun map_files f =
   43.51 +  Files.map (fn {master_dir, imports, provided} =>
   43.52 +    make_files (f (master_dir, imports, provided)));
   43.53 +
   43.54 +
   43.55 +val master_directory = #master_dir o Files.get;
   43.56 +val imports_of = #imports o Files.get;
   43.57 +
   43.58 +fun put_deps master_dir imports = map_files (fn _ => (master_dir, imports, []));
   43.59 +
   43.60 +
   43.61 +(* theory files *)
   43.62 +
   43.63 +val thy_path = Path.ext "thy";
   43.64 +
   43.65 +fun check_file dir file = File.check_file (File.full_path dir file);
   43.66 +
   43.67 +fun check_thy dir thy_name =
   43.68 +  let
   43.69 +    val path = thy_path (Path.basic thy_name);
   43.70 +    val master_file = check_file dir path;
   43.71 +    val text = File.read master_file;
   43.72 +
   43.73 +    val {name = (name, pos), imports, keywords} =
   43.74 +      Thy_Header.read (Path.position master_file) text;
   43.75 +    val _ = thy_name <> name andalso
   43.76 +      error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name ^ Position.here pos);
   43.77 +  in
   43.78 +   {master = (master_file, SHA1.digest text), text = text, theory_pos = pos,
   43.79 +    imports = imports, keywords = keywords}
   43.80 +  end;
   43.81 +
   43.82 +
   43.83 +(* load files *)
   43.84 +
   43.85 +fun parse_files cmd =
   43.86 +  Scan.ahead Parse.not_eof -- Parse.path >> (fn (tok, name) => fn thy =>
   43.87 +    (case Token.get_files tok of
   43.88 +      [] =>
   43.89 +        let
   43.90 +          val master_dir = master_directory thy;
   43.91 +          val pos = Token.pos_of tok;
   43.92 +          val src_paths = Keyword.command_files cmd (Path.explode name);
   43.93 +        in map (Command.read_file master_dir pos) src_paths end
   43.94 +    | files => map Exn.release files));
   43.95 +
   43.96 +fun provide (src_path, id) =
   43.97 +  map_files (fn (master_dir, imports, provided) =>
   43.98 +    if AList.defined (op =) provided src_path then
   43.99 +      error ("Duplicate use of source file: " ^ Path.print src_path)
  43.100 +    else (master_dir, imports, (src_path, id) :: provided));
  43.101 +
  43.102 +fun provide_parse_files cmd =
  43.103 +  parse_files cmd >> (fn files => fn thy =>
  43.104 +    let
  43.105 +      val fs = files thy;
  43.106 +      val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy;
  43.107 +    in (fs, thy') end);
  43.108 +
  43.109 +fun load_file thy src_path =
  43.110 +  let
  43.111 +    val full_path = check_file (master_directory thy) src_path;
  43.112 +    val text = File.read full_path;
  43.113 +    val id = SHA1.digest text;
  43.114 +  in ((full_path, id), text) end;
  43.115 +
  43.116 +fun loaded_files_current thy =
  43.117 +  #provided (Files.get thy) |>
  43.118 +    forall (fn (src_path, id) =>
  43.119 +      (case try (load_file thy) src_path of
  43.120 +        NONE => false
  43.121 +      | SOME ((_, id'), _) => id = id'));
  43.122 +
  43.123 +(*Proof General legacy*)
  43.124 +fun loaded_files thy =
  43.125 +  let val {master_dir, provided, ...} = Files.get thy
  43.126 +  in map (File.full_path master_dir o #1) provided end;
  43.127 +
  43.128 +
  43.129 +(* load theory *)
  43.130 +
  43.131 +fun begin_theory master_dir {name, imports, keywords} parents =
  43.132 +  Theory.begin_theory name parents
  43.133 +  |> put_deps master_dir imports
  43.134 +  |> fold Thy_Header.declare_keyword keywords;
  43.135 +
  43.136 +fun excursion master_dir last_timing init elements =
  43.137 +  let
  43.138 +    fun prepare_span span =
  43.139 +      Thy_Syntax.span_content span
  43.140 +      |> Command.read init master_dir []
  43.141 +      |> (fn tr => Toplevel.put_timing (last_timing tr) tr);
  43.142 +
  43.143 +    fun element_result span_elem (st, _) =
  43.144 +      let
  43.145 +        val elem = Thy_Syntax.map_element prepare_span span_elem;
  43.146 +        val (results, st') = Toplevel.element_result elem st;
  43.147 +        val pos' = Toplevel.pos_of (Thy_Syntax.last_element elem);
  43.148 +      in (results, (st', pos')) end;
  43.149 +
  43.150 +    val (results, (end_state, end_pos)) =
  43.151 +      fold_map element_result elements (Toplevel.toplevel, Position.none);
  43.152 +
  43.153 +    val thy = Toplevel.end_theory end_pos end_state;
  43.154 +  in (results, thy) end;
  43.155 +
  43.156 +fun load_thy document last_timing update_time master_dir header text_pos text parents =
  43.157 +  let
  43.158 +    val time = ! Toplevel.timing;
  43.159 +
  43.160 +    val {name = (name, _), ...} = header;
  43.161 +    val _ = Thy_Header.define_keywords header;
  43.162 +
  43.163 +    val lexs = Keyword.get_lexicons ();
  43.164 +    val toks = Thy_Syntax.parse_tokens lexs text_pos text;
  43.165 +    val spans = Thy_Syntax.parse_spans toks;
  43.166 +    val elements = Thy_Syntax.parse_elements spans;
  43.167 +
  43.168 +    fun init () =
  43.169 +      begin_theory master_dir header parents
  43.170 +      |> Present.begin_theory update_time
  43.171 +          (fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans);
  43.172 +
  43.173 +    val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else ();
  43.174 +    val (results, thy) =
  43.175 +      cond_timeit time "" (fn () => excursion master_dir last_timing init elements);
  43.176 +    val _ = if time then writeln ("**** Finished theory " ^ quote name ^ " ****\n") else ();
  43.177 +
  43.178 +    fun present () =
  43.179 +      let
  43.180 +        val res = filter_out (Toplevel.is_ignored o #1) (maps Toplevel.join_results results);
  43.181 +        val ((minor, _), outer_syntax) = Outer_Syntax.get_syntax ();
  43.182 +      in
  43.183 +        if exists (Toplevel.is_skipped_proof o #2) res then
  43.184 +          warning ("Cannot present theory with skipped proofs: " ^ quote name)
  43.185 +        else
  43.186 +          let val tex_source =
  43.187 +            Thy_Output.present_thy minor Keyword.command_tags
  43.188 +              (Outer_Syntax.is_markup outer_syntax) res toks
  43.189 +            |> Buffer.content;
  43.190 +          in if document then Present.theory_output name tex_source else () end
  43.191 +      end;
  43.192 +
  43.193 +  in (thy, present, size text) end;
  43.194 +
  43.195 +
  43.196 +(* antiquotations *)
  43.197 +
  43.198 +local
  43.199 +
  43.200 +fun check_path strict ctxt dir (name, pos) =
  43.201 +  let
  43.202 +    val _ = Context_Position.report ctxt pos Markup.language_path;
  43.203 +
  43.204 +    val path = Path.append dir (Path.explode name)
  43.205 +      handle ERROR msg => error (msg ^ Position.here pos);
  43.206 +
  43.207 +    val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path));
  43.208 +    val _ =
  43.209 +      if can Path.expand path andalso File.exists path then ()
  43.210 +      else
  43.211 +        let
  43.212 +          val path' = perhaps (try Path.expand) path;
  43.213 +          val msg = "Bad file: " ^ Path.print path' ^ Position.here pos;
  43.214 +        in
  43.215 +          if strict then error msg
  43.216 +          else
  43.217 +            Context_Position.if_visible ctxt Output.report
  43.218 +              (Markup.markup (Markup.bad |> Markup.properties (Position.properties_of pos)) msg)
  43.219 +        end;
  43.220 +  in path end;
  43.221 +
  43.222 +fun file_antiq strict ctxt (name, pos) =
  43.223 +  let
  43.224 +    val dir = master_directory (Proof_Context.theory_of ctxt);
  43.225 +    val _ = check_path strict ctxt dir (name, pos);
  43.226 +  in
  43.227 +    space_explode "/" name
  43.228 +    |> map Thy_Output.verb_text
  43.229 +    |> space_implode (Thy_Output.verb_text "/" ^ "\\discretionary{}{}{}")
  43.230 +  end;
  43.231 +
  43.232 +in
  43.233 +
  43.234 +val _ = Theory.setup
  43.235 + (Thy_Output.antiquotation @{binding file} (Scan.lift (Parse.position Parse.path))
  43.236 +    (file_antiq true o #context) #>
  43.237 +  Thy_Output.antiquotation @{binding file_unchecked} (Scan.lift (Parse.position Parse.path))
  43.238 +    (file_antiq false o #context) #>
  43.239 +  ML_Antiquotation.value @{binding path}
  43.240 +    (Args.context -- Scan.lift (Parse.position Parse.path) >> (fn (ctxt, arg) =>
  43.241 +      let val path = check_path true ctxt Path.current arg
  43.242 +      in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end)));
  43.243 +
  43.244 +end;
  43.245 +
  43.246 +end;
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/src/Pure/PIDE/resources.scala	Tue Mar 18 21:02:33 2014 +0100
    44.3 @@ -0,0 +1,105 @@
    44.4 +/*  Title:      Pure/PIDE/resources.scala
    44.5 +    Author:     Makarius
    44.6 +
    44.7 +Resources for theories and auxiliary files.
    44.8 +*/
    44.9 +
   44.10 +package isabelle
   44.11 +
   44.12 +
   44.13 +import scala.annotation.tailrec
   44.14 +
   44.15 +import java.io.{File => JFile}
   44.16 +
   44.17 +
   44.18 +object Resources
   44.19 +{
   44.20 +  def thy_path(path: Path): Path = path.ext("thy")
   44.21 +}
   44.22 +
   44.23 +
   44.24 +class Resources(val loaded_theories: Set[String] = Set.empty, val base_syntax: Outer_Syntax)
   44.25 +{
   44.26 +  /* document node names */
   44.27 +
   44.28 +  def node_name(raw_path: Path): Document.Node.Name =
   44.29 +  {
   44.30 +    val path = raw_path.expand
   44.31 +    val node = path.implode
   44.32 +    val theory = Thy_Header.thy_name(node).getOrElse("")
   44.33 +    val master_dir = if (theory == "") "" else path.dir.implode
   44.34 +    Document.Node.Name(node, master_dir, theory)
   44.35 +  }
   44.36 +
   44.37 +
   44.38 +  /* file-system operations */
   44.39 +
   44.40 +  def append(dir: String, source_path: Path): String =
   44.41 +    (Path.explode(dir) + source_path).expand.implode
   44.42 +
   44.43 +  def with_thy_text[A](name: Document.Node.Name, f: CharSequence => A): A =
   44.44 +  {
   44.45 +    val path = Path.explode(name.node)
   44.46 +    if (!path.is_file) error("No such file: " + path.toString)
   44.47 +
   44.48 +    val text = File.read(path)
   44.49 +    Symbol.decode_strict(text)
   44.50 +    f(text)
   44.51 +  }
   44.52 +
   44.53 +
   44.54 +  /* theory files */
   44.55 +
   44.56 +  def body_files_test(syntax: Outer_Syntax, text: String): Boolean =
   44.57 +    syntax.thy_load_commands.exists({ case (cmd, _) => text.containsSlice(cmd) })
   44.58 +
   44.59 +  def body_files(syntax: Outer_Syntax, text: String): List[String] =
   44.60 +  {
   44.61 +    val spans = Thy_Syntax.parse_spans(syntax.scan(text))
   44.62 +    spans.iterator.map(Thy_Syntax.span_files(syntax, _)).flatten.toList
   44.63 +  }
   44.64 +
   44.65 +  def import_name(master: Document.Node.Name, s: String): Document.Node.Name =
   44.66 +  {
   44.67 +    val theory = Thy_Header.base_name(s)
   44.68 +    if (loaded_theories(theory)) Document.Node.Name(theory + ".thy", "", theory)
   44.69 +    else {
   44.70 +      val path = Path.explode(s)
   44.71 +      val node = append(master.master_dir, Resources.thy_path(path))
   44.72 +      val master_dir = append(master.master_dir, path.dir)
   44.73 +      Document.Node.Name(node, master_dir, theory)
   44.74 +    }
   44.75 +  }
   44.76 +
   44.77 +  def check_thy_text(name: Document.Node.Name, text: CharSequence): Document.Node.Header =
   44.78 +  {
   44.79 +    try {
   44.80 +      val header = Thy_Header.read(text)
   44.81 +
   44.82 +      val name1 = header.name
   44.83 +      if (name.theory != name1)
   44.84 +        error("Bad file name " + Resources.thy_path(Path.basic(name.theory)) +
   44.85 +          " for theory " + quote(name1))
   44.86 +
   44.87 +      val imports = header.imports.map(import_name(name, _))
   44.88 +      Document.Node.Header(imports, header.keywords, Nil)
   44.89 +    }
   44.90 +    catch { case exn: Throwable => Document.Node.bad_header(Exn.message(exn)) }
   44.91 +  }
   44.92 +
   44.93 +  def check_thy(name: Document.Node.Name): Document.Node.Header =
   44.94 +    with_thy_text(name, check_thy_text(name, _))
   44.95 +
   44.96 +
   44.97 +  /* theory text edits */
   44.98 +
   44.99 +  def text_edits(
  44.100 +    reparse_limit: Int,
  44.101 +    previous: Document.Version,
  44.102 +    doc_blobs: Document.Blobs,
  44.103 +    edits: List[Document.Edit_Text]): (Boolean, List[Document.Edit_Command], Document.Version) =
  44.104 +    Thy_Syntax.text_edits(this, reparse_limit, previous, doc_blobs, edits)
  44.105 +
  44.106 +  def syntax_changed() { }
  44.107 +}
  44.108 +
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/src/Pure/PIDE/session.ML	Tue Mar 18 21:02:33 2014 +0100
    45.3 @@ -0,0 +1,80 @@
    45.4 +(*  Title:      Pure/PIDE/session.ML
    45.5 +    Author:     Makarius
    45.6 +
    45.7 +Prover session: persistent state of logic image.
    45.8 +*)
    45.9 +
   45.10 +signature SESSION =
   45.11 +sig
   45.12 +  val name: unit -> string
   45.13 +  val welcome: unit -> string
   45.14 +  val init: bool -> bool -> Path.T -> string -> bool -> string -> (string * string) list ->
   45.15 +    string -> string * string -> bool * string -> bool -> unit
   45.16 +  val finish: unit -> unit
   45.17 +  val protocol_handler: string -> unit
   45.18 +  val init_protocol_handlers: unit -> unit
   45.19 +end;
   45.20 +
   45.21 +structure Session: SESSION =
   45.22 +struct
   45.23 +
   45.24 +(** session identification -- not thread-safe **)
   45.25 +
   45.26 +val session = Unsynchronized.ref {chapter = "Pure", name = "Pure"};
   45.27 +val session_finished = Unsynchronized.ref false;
   45.28 +
   45.29 +fun name () = "Isabelle/" ^ #name (! session);
   45.30 +
   45.31 +fun welcome () =
   45.32 +  if Distribution.is_official then
   45.33 +    "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
   45.34 +  else "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")";
   45.35 +
   45.36 +
   45.37 +(* init *)
   45.38 +
   45.39 +fun init build info info_path doc doc_graph doc_output doc_variants
   45.40 +    parent (chapter, name) doc_dump verbose =
   45.41 +  if #name (! session) <> parent orelse not (! session_finished) then
   45.42 +    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
   45.43 +  else
   45.44 +    let
   45.45 +      val _ = session := {chapter = chapter, name = name};
   45.46 +      val _ = session_finished := false;
   45.47 +    in
   45.48 +      Present.init build info info_path (if doc = "false" then "" else doc)
   45.49 +        doc_graph doc_output doc_variants (chapter, name)
   45.50 +        doc_dump verbose (map Thy_Info.get_theory (Thy_Info.get_names ()))
   45.51 +    end;
   45.52 +
   45.53 +
   45.54 +(* finish *)
   45.55 +
   45.56 +fun finish () =
   45.57 + (Execution.shutdown ();
   45.58 +  Thy_Info.finish ();
   45.59 +  Present.finish ();
   45.60 +  Outer_Syntax.check_syntax ();
   45.61 +  Future.shutdown ();
   45.62 +  Event_Timer.shutdown ();
   45.63 +  Future.shutdown ();
   45.64 +  session_finished := true);
   45.65 +
   45.66 +
   45.67 +
   45.68 +(** protocol handlers **)
   45.69 +
   45.70 +val protocol_handlers = Synchronized.var "protocol_handlers" ([]: string list);
   45.71 +
   45.72 +fun protocol_handler name =
   45.73 +  Synchronized.change protocol_handlers (fn handlers =>
   45.74 +   (Output.try_protocol_message (Markup.protocol_handler name) "";
   45.75 +    if not (member (op =) handlers name) then ()
   45.76 +    else warning ("Redefining protocol handler: " ^ quote name);
   45.77 +    update (op =) name handlers));
   45.78 +
   45.79 +fun init_protocol_handlers () =
   45.80 +  Synchronized.value protocol_handlers
   45.81 +  |> List.app (fn name => Output.try_protocol_message (Markup.protocol_handler name) "");
   45.82 +
   45.83 +end;
    46.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.2 +++ b/src/Pure/PIDE/session.scala	Tue Mar 18 21:02:33 2014 +0100
    46.3 @@ -0,0 +1,598 @@
    46.4 +/*  Title:      Pure/PIDE/session.scala
    46.5 +    Author:     Makarius
    46.6 +    Options:    :folding=explicit:collapseFolds=1:
    46.7 +
    46.8 +PIDE editor session, potentially with running prover process.
    46.9 +*/
   46.10 +
   46.11 +package isabelle
   46.12 +
   46.13 +
   46.14 +import java.util.{Timer, TimerTask}
   46.15 +
   46.16 +import scala.collection.mutable
   46.17 +import scala.collection.immutable.Queue
   46.18 +import scala.actors.TIMEOUT
   46.19 +import scala.actors.Actor._
   46.20 +
   46.21 +
   46.22 +object Session
   46.23 +{
   46.24 +  /* events */
   46.25 +
   46.26 +  //{{{
   46.27 +  case class Statistics(props: Properties.T)
   46.28 +  case class Global_Options(options: Options)
   46.29 +  case object Caret_Focus
   46.30 +  case class Raw_Edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
   46.31 +  case class Dialog_Result(id: Document_ID.Generic, serial: Long, result: String)
   46.32 +  case class Commands_Changed(
   46.33 +    assignment: Boolean, nodes: Set[Document.Node.Name], commands: Set[Command])
   46.34 +
   46.35 +  sealed abstract class Phase
   46.36 +  case object Inactive extends Phase
   46.37 +  case object Startup extends Phase  // transient
   46.38 +  case object Failed extends Phase
   46.39 +  case object Ready extends Phase
   46.40 +  case object Shutdown extends Phase  // transient
   46.41 +  //}}}
   46.42 +
   46.43 +
   46.44 +  /* protocol handlers */
   46.45 +
   46.46 +  type Prover = Isabelle_Process with Protocol
   46.47 +
   46.48 +  abstract class Protocol_Handler
   46.49 +  {
   46.50 +    def stop(prover: Prover): Unit = {}
   46.51 +    val functions: Map[String, (Prover, Isabelle_Process.Protocol_Output) => Boolean]
   46.52 +  }
   46.53 +
   46.54 +  class Protocol_Handlers(
   46.55 +    handlers: Map[String, Session.Protocol_Handler] = Map.empty,
   46.56 +    functions: Map[String, Isabelle_Process.Protocol_Output => Boolean] = Map.empty)
   46.57 +  {
   46.58 +    def get(name: String): Option[Protocol_Handler] = handlers.get(name)
   46.59 +
   46.60 +    def add(prover: Prover, name: String): Protocol_Handlers =
   46.61 +    {
   46.62 +      val (handlers1, functions1) =
   46.63 +        handlers.get(name) match {
   46.64 +          case Some(old_handler) =>
   46.65 +            System.err.println("Redefining protocol handler: " + name)
   46.66 +            old_handler.stop(prover)
   46.67 +            (handlers - name, functions -- old_handler.functions.keys)
   46.68 +          case None => (handlers, functions)
   46.69 +        }
   46.70 +
   46.71 +      val (handlers2, functions2) =
   46.72 +        try {
   46.73 +          val new_handler = Class.forName(name).newInstance.asInstanceOf[Protocol_Handler]
   46.74 +          val new_functions =
   46.75 +            for ((a, f) <- new_handler.functions.toList) yield
   46.76 +              (a, (msg: Isabelle_Process.Protocol_Output) => f(prover, msg))
   46.77 +
   46.78 +          val dups = for ((a, _) <- new_functions if functions1.isDefinedAt(a)) yield a
   46.79 +          if (!dups.isEmpty) error("Duplicate protocol functions: " + commas_quote(dups))
   46.80 +
   46.81 +          (handlers1 + (name -> new_handler), functions1 ++ new_functions)
   46.82 +        }
   46.83 +        catch {
   46.84 +          case exn: Throwable =>
   46.85 +            System.err.println("Failed to initialize protocol handler: " +
   46.86 +              name + "\n" + Exn.message(exn))
   46.87 +            (handlers1, functions1)
   46.88 +        }
   46.89 +
   46.90 +      new Protocol_Handlers(handlers2, functions2)
   46.91 +    }
   46.92 +
   46.93 +    def invoke(msg: Isabelle_Process.Protocol_Output): Boolean =
   46.94 +      msg.properties match {
   46.95 +        case Markup.Function(a) if functions.isDefinedAt(a) =>
   46.96 +          try { functions(a)(msg) }
   46.97 +          catch {
   46.98 +            case exn: Throwable =>
   46.99 +              System.err.println("Failed invocation of protocol function: " +
  46.100 +                quote(a) + "\n" + Exn.message(exn))
  46.101 +            false
  46.102 +          }
  46.103 +        case _ => false
  46.104 +      }
  46.105 +
  46.106 +    def stop(prover: Prover): Protocol_Handlers =
  46.107 +    {
  46.108 +      for ((_, handler) <- handlers) handler.stop(prover)
  46.109 +      new Protocol_Handlers()
  46.110 +    }
  46.111 +  }
  46.112 +}
  46.113 +
  46.114 +
  46.115 +class Session(val resources: Resources)
  46.116 +{
  46.117 +  /* global flags */
  46.118 +
  46.119 +  @volatile var timing: Boolean = false
  46.120 +  @volatile var verbose: Boolean = false
  46.121 +
  46.122 +
  46.123 +  /* tuning parameters */
  46.124 +
  46.125 +  def output_delay: Time = Time.seconds(0.1)  // prover output (markup, common messages)
  46.126 +  def message_delay: Time = Time.seconds(0.1)  // prover input/output messages
  46.127 +  def prune_delay: Time = Time.seconds(60.0)  // prune history -- delete old versions
  46.128 +  def prune_size: Int = 0  // size of retained history
  46.129 +  def syslog_limit: Int = 100
  46.130 +  def reparse_limit: Int = 0
  46.131 +
  46.132 +
  46.133 +  /* pervasive event buses */
  46.134 +
  46.135 +  val statistics = new Event_Bus[Session.Statistics]
  46.136 +  val global_options = new Event_Bus[Session.Global_Options]
  46.137 +  val caret_focus = new Event_Bus[Session.Caret_Focus.type]
  46.138 +  val raw_edits = new Event_Bus[Session.Raw_Edits]
  46.139 +  val commands_changed = new Event_Bus[Session.Commands_Changed]
  46.140 +  val phase_changed = new Event_Bus[Session.Phase]
  46.141 +  val syslog_messages = new Event_Bus[Isabelle_Process.Output]
  46.142 +  val raw_output_messages = new Event_Bus[Isabelle_Process.Output]
  46.143 +  val all_messages = new Event_Bus[Isabelle_Process.Message]  // potential bottle-neck
  46.144 +  val trace_events = new Event_Bus[Simplifier_Trace.Event.type]
  46.145 +
  46.146 +
  46.147 +  /** buffered command changes (delay_first discipline) **/
  46.148 +
  46.149 +  //{{{
  46.150 +  private case object Stop
  46.151 +
  46.152 +  private val (_, commands_changed_buffer) =
  46.153 +    Simple_Thread.actor("commands_changed_buffer", daemon = true)
  46.154 +  {
  46.155 +    var finished = false
  46.156 +    while (!finished) {
  46.157 +      receive {
  46.158 +        case Stop => finished = true; reply(())
  46.159 +        case changed: Session.Commands_Changed => commands_changed.event(changed)
  46.160 +        case bad => System.err.println("commands_changed_buffer: ignoring bad message " + bad)
  46.161 +      }
  46.162 +    }
  46.163 +  }
  46.164 +  //}}}
  46.165 +
  46.166 +
  46.167 +  /** pipelined change parsing **/
  46.168 +
  46.169 +  //{{{
  46.170 +  private case class Text_Edits(
  46.171 +    previous: Future[Document.Version],
  46.172 +    doc_blobs: Document.Blobs,
  46.173 +    text_edits: List[Document.Edit_Text],
  46.174 +    version_result: Promise[Document.Version])
  46.175 +
  46.176 +  private val (_, change_parser) = Simple_Thread.actor("change_parser", daemon = true)
  46.177 +  {
  46.178 +    var finished = false
  46.179 +    while (!finished) {
  46.180 +      receive {
  46.181 +        case Stop => finished = true; reply(())
  46.182 +
  46.183 +        case Text_Edits(previous, doc_blobs, text_edits, version_result) =>
  46.184 +          val prev = previous.get_finished
  46.185 +          val (syntax_changed, doc_edits, version) =
  46.186 +            Timing.timeit("text_edits", timing) {
  46.187 +              resources.text_edits(reparse_limit, prev, doc_blobs, text_edits)
  46.188 +            }
  46.189 +          version_result.fulfill(version)
  46.190 +          sender ! Change(doc_blobs, syntax_changed, doc_edits, prev, version)
  46.191 +
  46.192 +        case bad => System.err.println("change_parser: ignoring bad message " + bad)
  46.193 +      }
  46.194 +    }
  46.195 +  }
  46.196 +  //}}}
  46.197 +
  46.198 +
  46.199 +
  46.200 +  /** main protocol actor **/
  46.201 +
  46.202 +  /* global state */
  46.203 +
  46.204 +  private val syslog = Volatile(Queue.empty[XML.Elem])
  46.205 +  def current_syslog(): String = cat_lines(syslog().iterator.map(XML.content))
  46.206 +
  46.207 +  @volatile private var _phase: Session.Phase = Session.Inactive
  46.208 +  private def phase_=(new_phase: Session.Phase)
  46.209 +  {
  46.210 +    _phase = new_phase
  46.211 +    phase_changed.event(new_phase)
  46.212 +  }
  46.213 +  def phase = _phase
  46.214 +  def is_ready: Boolean = phase == Session.Ready
  46.215 +
  46.216 +  private val global_state = Volatile(Document.State.init)
  46.217 +  def current_state(): Document.State = global_state()
  46.218 +
  46.219 +  def recent_syntax(): Outer_Syntax =
  46.220 +  {
  46.221 +    val version = current_state().recent_finished.version.get_finished
  46.222 +    if (version.is_init) resources.base_syntax
  46.223 +    else version.syntax
  46.224 +  }
  46.225 +
  46.226 +  def snapshot(name: Document.Node.Name = Document.Node.Name.empty,
  46.227 +      pending_edits: List[Text.Edit] = Nil): Document.Snapshot =
  46.228 +    global_state().snapshot(name, pending_edits)
  46.229 +
  46.230 +
  46.231 +  /* protocol handlers */
  46.232 +
  46.233 +  @volatile private var _protocol_handlers = new Session.Protocol_Handlers()
  46.234 +
  46.235 +  def protocol_handler(name: String): Option[Session.Protocol_Handler] =
  46.236 +    _protocol_handlers.get(name)
  46.237 +
  46.238 +
  46.239 +  /* theory files */
  46.240 +
  46.241 +  def header_edit(name: Document.Node.Name, header: Document.Node.Header): Document.Edit_Text =
  46.242 +  {
  46.243 +    val header1 =
  46.244 +      if (resources.loaded_theories(name.theory))
  46.245 +        header.error("Cannot update finished theory " + quote(name.theory))
  46.246 +      else header
  46.247 +    (name, Document.Node.Deps(header1))
  46.248 +  }
  46.249 +
  46.250 +
  46.251 +  /* actor messages */
  46.252 +
  46.253 +  private case class Start(args: List[String])
  46.254 +  private case class Cancel_Exec(exec_id: Document_ID.Exec)
  46.255 +  private case class Change(
  46.256 +    doc_blobs: Document.Blobs,
  46.257 +    syntax_changed: Boolean,
  46.258 +    doc_edits: List[Document.Edit_Command],
  46.259 +    previous: Document.Version,
  46.260 +    version: Document.Version)
  46.261 +  private case class Protocol_Command(name: String, args: List[String])
  46.262 +  private case class Messages(msgs: List[Isabelle_Process.Message])
  46.263 +  private case class Update_Options(options: Options)
  46.264 +
  46.265 +  private val (_, session_actor) = Simple_Thread.actor("session_actor", daemon = true)
  46.266 +  {
  46.267 +    val this_actor = self
  46.268 +
  46.269 +    var prune_next = System.currentTimeMillis() + prune_delay.ms
  46.270 +
  46.271 +
  46.272 +    /* buffered prover messages */
  46.273 +
  46.274 +    object receiver
  46.275 +    {
  46.276 +      private var buffer = new mutable.ListBuffer[Isabelle_Process.Message]
  46.277 +
  46.278 +      private def flush(): Unit = synchronized {
  46.279 +        if (!buffer.isEmpty) {
  46.280 +          val msgs = buffer.toList
  46.281 +          this_actor ! Messages(msgs)
  46.282 +          buffer = new mutable.ListBuffer[Isabelle_Process.Message]
  46.283 +        }
  46.284 +      }
  46.285 +      def invoke(msg: Isabelle_Process.Message): Unit = synchronized {
  46.286 +        msg match {
  46.287 +          case _: Isabelle_Process.Input =>
  46.288 +            buffer += msg
  46.289 +          case output: Isabelle_Process.Protocol_Output if output.properties == Markup.Flush =>
  46.290 +            flush()
  46.291 +          case output: Isabelle_Process.Output =>
  46.292 +            buffer += msg
  46.293 +            if (output.is_syslog)
  46.294 +              syslog >> (queue =>
  46.295 +                {
  46.296 +                  val queue1 = queue.enqueue(output.message)
  46.297 +                  if (queue1.length > syslog_limit) queue1.dequeue._2 else queue1
  46.298 +                })
  46.299 +        }
  46.300 +      }
  46.301 +
  46.302 +      private val timer = new Timer("session_actor.receiver", true)
  46.303 +      timer.schedule(new TimerTask { def run = flush }, message_delay.ms, message_delay.ms)
  46.304 +
  46.305 +      def cancel() { timer.cancel() }
  46.306 +    }
  46.307 +
  46.308 +    var prover: Option[Session.Prover] = None
  46.309 +
  46.310 +
  46.311 +    /* delayed command changes */
  46.312 +
  46.313 +    object delay_commands_changed
  46.314 +    {
  46.315 +      private var changed_assignment: Boolean = false
  46.316 +      private var changed_nodes: Set[Document.Node.Name] = Set.empty
  46.317 +      private var changed_commands: Set[Command] = Set.empty
  46.318 +
  46.319 +      private var flush_time: Option[Long] = None
  46.320 +
  46.321 +      def flush_timeout: Long =
  46.322 +        flush_time match {
  46.323 +          case None => 5000L
  46.324 +          case Some(time) => (time - System.currentTimeMillis()) max 0
  46.325 +        }
  46.326 +
  46.327 +      def flush()
  46.328 +      {
  46.329 +        if (changed_assignment || !changed_nodes.isEmpty || !changed_commands.isEmpty)
  46.330 +          commands_changed_buffer !
  46.331 +            Session.Commands_Changed(changed_assignment, changed_nodes, changed_commands)
  46.332 +        changed_assignment = false
  46.333 +        changed_nodes = Set.empty
  46.334 +        changed_commands = Set.empty
  46.335 +        flush_time = None
  46.336 +      }
  46.337 +
  46.338 +      def invoke(assign: Boolean, commands: List[Command])
  46.339 +      {
  46.340 +        changed_assignment |= assign
  46.341 +        for (command <- commands) {
  46.342 +          changed_nodes += command.node_name
  46.343 +          changed_commands += command
  46.344 +        }
  46.345 +        val now = System.currentTimeMillis()
  46.346 +        flush_time match {
  46.347 +          case None => flush_time = Some(now + output_delay.ms)
  46.348 +          case Some(time) => if (now >= time) flush()
  46.349 +        }
  46.350 +      }
  46.351 +    }
  46.352 +
  46.353 +
  46.354 +    /* raw edits */
  46.355 +
  46.356 +    def handle_raw_edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
  46.357 +    //{{{
  46.358 +    {
  46.359 +      prover.get.discontinue_execution()
  46.360 +
  46.361 +      val previous = global_state().history.tip.version
  46.362 +      val version = Future.promise[Document.Version]
  46.363 +      val change = global_state >>> (_.continue_history(previous, edits, version))
  46.364 +
  46.365 +      raw_edits.event(Session.Raw_Edits(doc_blobs, edits))
  46.366 +      change_parser ! Text_Edits(previous, doc_blobs, edits, version)
  46.367 +    }
  46.368 +    //}}}
  46.369 +
  46.370 +
  46.371 +    /* resulting changes */
  46.372 +
  46.373 +    def handle_change(change: Change)
  46.374 +    //{{{
  46.375 +    {
  46.376 +      val Change(doc_blobs, syntax_changed, doc_edits, previous, version) = change
  46.377 +
  46.378 +      def id_command(command: Command)
  46.379 +      {
  46.380 +        for {
  46.381 +          digest <- command.blobs_digests
  46.382 +          if !global_state().defined_blob(digest)
  46.383 +        } {
  46.384 +          doc_blobs.get(digest) match {
  46.385 +            case Some(blob) =>
  46.386 +              global_state >> (_.define_blob(digest))
  46.387 +              prover.get.define_blob(blob)
  46.388 +            case None =>
  46.389 +              System.err.println("Missing blob for SHA1 digest " + digest)
  46.390 +          }
  46.391 +        }
  46.392 +
  46.393 +        if (!global_state().defined_command(command.id)) {
  46.394 +          global_state >> (_.define_command(command))
  46.395 +          prover.get.define_command(command)
  46.396 +        }
  46.397 +      }
  46.398 +      doc_edits foreach {
  46.399 +        case (_, edit) =>
  46.400 +          edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
  46.401 +      }
  46.402 +
  46.403 +      val assignment = global_state().the_assignment(previous).check_finished
  46.404 +      global_state >> (_.define_version(version, assignment))
  46.405 +      prover.get.update(previous.id, version.id, doc_edits)
  46.406 +
  46.407 +      if (syntax_changed) resources.syntax_changed()
  46.408 +    }
  46.409 +    //}}}
  46.410 +
  46.411 +
  46.412 +    /* prover output */
  46.413 +
  46.414 +    def handle_output(output: Isabelle_Process.Output)
  46.415 +    //{{{
  46.416 +    {
  46.417 +      def bad_output()
  46.418 +      {
  46.419 +        if (verbose)
  46.420 +          System.err.println("Ignoring prover output: " + output.message.toString)
  46.421 +      }
  46.422 +
  46.423 +      def accumulate(state_id: Document_ID.Generic, message: XML.Elem)
  46.424 +      {
  46.425 +        try {
  46.426 +          val st = global_state >>> (_.accumulate(state_id, message))
  46.427 +          delay_commands_changed.invoke(false, List(st.command))
  46.428 +        }
  46.429 +        catch {
  46.430 +          case _: Document.State.Fail => bad_output()
  46.431 +        }
  46.432 +      }
  46.433 +
  46.434 +      output match {
  46.435 +        case msg: Isabelle_Process.Protocol_Output =>
  46.436 +          val handled = _protocol_handlers.invoke(msg)
  46.437 +          if (!handled) {
  46.438 +            msg.properties match {
  46.439 +              case Markup.Protocol_Handler(name) =>
  46.440 +                _protocol_handlers = _protocol_handlers.add(prover.get, name)
  46.441 +
  46.442 +              case Protocol.Command_Timing(state_id, timing) =>
  46.443 +                val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))
  46.444 +                accumulate(state_id, prover.get.xml_cache.elem(message))
  46.445 +
  46.446 +              case Markup.Assign_Update =>
  46.447 +                msg.text match {
  46.448 +                  case Protocol.Assign_Update(id, update) =>
  46.449 +                    try {
  46.450 +                      val cmds = global_state >>> (_.assign(id, update))
  46.451 +                      delay_commands_changed.invoke(true, cmds)
  46.452 +                    }
  46.453 +                    catch { case _: Document.State.Fail => bad_output() }
  46.454 +                  case _ => bad_output()
  46.455 +                }
  46.456 +                // FIXME separate timeout event/message!?
  46.457 +                if (prover.isDefined && System.currentTimeMillis() > prune_next) {
  46.458 +                  val old_versions = global_state >>> (_.prune_history(prune_size))
  46.459 +                  if (!old_versions.isEmpty) prover.get.remove_versions(old_versions)
  46.460 +                  prune_next = System.currentTimeMillis() + prune_delay.ms
  46.461 +                }
  46.462 +
  46.463 +              case Markup.Removed_Versions =>
  46.464 +                msg.text match {
  46.465 +                  case Protocol.Removed(removed) =>
  46.466 +                    try {
  46.467 +                      global_state >> (_.removed_versions(removed))
  46.468 +                    }
  46.469 +                    catch { case _: Document.State.Fail => bad_output() }
  46.470 +                  case _ => bad_output()
  46.471 +                }
  46.472 +
  46.473 +              case Markup.ML_Statistics(props) =>
  46.474 +                statistics.event(Session.Statistics(props))
  46.475 +
  46.476 +              case Markup.Task_Statistics(props) =>
  46.477 +                // FIXME
  46.478 +
  46.479 +              case _ => bad_output()
  46.480 +            }
  46.481 +          }
  46.482 +        case _ =>
  46.483 +          output.properties match {
  46.484 +            case Position.Id(state_id) =>
  46.485 +              accumulate(state_id, output.message)
  46.486 +
  46.487 +            case _ if output.is_init =>
  46.488 +              phase = Session.Ready
  46.489 +
  46.490 +            case Markup.Return_Code(rc) if output.is_exit =>
  46.491 +              if (rc == 0) phase = Session.Inactive
  46.492 +              else phase = Session.Failed
  46.493 +
  46.494 +            case _ => raw_output_messages.event(output)
  46.495 +          }
  46.496 +        }
  46.497 +    }
  46.498 +    //}}}
  46.499 +
  46.500 +
  46.501 +    /* main loop */
  46.502 +
  46.503 +    //{{{
  46.504 +    var finished = false
  46.505 +    while (!finished) {
  46.506 +      receiveWithin(delay_commands_changed.flush_timeout) {
  46.507 +        case TIMEOUT => delay_commands_changed.flush()
  46.508 +
  46.509 +        case Start(args) if prover.isEmpty =>
  46.510 +          if (phase == Session.Inactive || phase == Session.Failed) {
  46.511 +            phase = Session.Startup
  46.512 +            prover = Some(new Isabelle_Process(receiver.invoke _, args) with Protocol)
  46.513 +          }
  46.514 +
  46.515 +        case Stop =>
  46.516 +          if (phase == Session.Ready) {
  46.517 +            _protocol_handlers = _protocol_handlers.stop(prover.get)
  46.518 +            global_state >> (_ => Document.State.init)  // FIXME event bus!?
  46.519 +            phase = Session.Shutdown
  46.520 +            prover.get.terminate
  46.521 +            prover = None
  46.522 +            phase = Session.Inactive
  46.523 +          }
  46.524 +          finished = true
  46.525 +          receiver.cancel()
  46.526 +          reply(())
  46.527 +
  46.528 +        case Update_Options(options) if prover.isDefined =>
  46.529 +          if (is_ready) {
  46.530 +            prover.get.options(options)
  46.531 +            handle_raw_edits(Document.Blobs.empty, Nil)
  46.532 +          }
  46.533 +          global_options.event(Session.Global_Options(options))
  46.534 +          reply(())
  46.535 +
  46.536 +        case Cancel_Exec(exec_id) if prover.isDefined =>
  46.537 +          prover.get.cancel_exec(exec_id)
  46.538 +
  46.539 +        case Session.Raw_Edits(doc_blobs, edits) if prover.isDefined =>
  46.540 +          handle_raw_edits(doc_blobs, edits)
  46.541 +          reply(())
  46.542 +
  46.543 +        case Session.Dialog_Result(id, serial, result) if prover.isDefined =>
  46.544 +          prover.get.dialog_result(serial, result)
  46.545 +          handle_output(new Isabelle_Process.Output(Protocol.Dialog_Result(id, serial, result)))
  46.546 +
  46.547 +        case Protocol_Command(name, args) if prover.isDefined =>
  46.548 +          prover.get.protocol_command(name, args:_*)
  46.549 +
  46.550 +        case Messages(msgs) =>
  46.551 +          msgs foreach {
  46.552 +            case input: Isabelle_Process.Input =>
  46.553 +              all_messages.event(input)
  46.554 +
  46.555 +            case output: Isabelle_Process.Output =>
  46.556 +              if (output.is_stdout || output.is_stderr) raw_output_messages.event(output)
  46.557 +              else handle_output(output)
  46.558 +              if (output.is_syslog) syslog_messages.event(output)
  46.559 +              all_messages.event(output)
  46.560 +          }
  46.561 +
  46.562 +        case change: Change
  46.563 +        if prover.isDefined && global_state().is_assigned(change.previous) =>
  46.564 +          handle_change(change)
  46.565 +
  46.566 +        case bad if !bad.isInstanceOf[Change] =>
  46.567 +          System.err.println("session_actor: ignoring bad message " + bad)
  46.568 +      }
  46.569 +    }
  46.570 +    //}}}
  46.571 +  }
  46.572 +
  46.573 +
  46.574 +  /* actions */
  46.575 +
  46.576 +  def start(args: List[String])
  46.577 +  {
  46.578 +    session_actor ! Start(args)
  46.579 +  }
  46.580 +
  46.581 +  def stop()
  46.582 +  {
  46.583 +    commands_changed_buffer !? Stop
  46.584 +    change_parser !? Stop
  46.585 +    session_actor !? Stop
  46.586 +  }
  46.587 +
  46.588 +  def protocol_command(name: String, args: String*)
  46.589 +  { session_actor ! Protocol_Command(name, args.toList) }
  46.590 +
  46.591 +  def cancel_exec(exec_id: Document_ID.Exec) { session_actor ! Cancel_Exec(exec_id) }
  46.592 +
  46.593 +  def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
  46.594 +  { if (!edits.isEmpty) session_actor !? Session.Raw_Edits(doc_blobs, edits) }
  46.595 +
  46.596 +  def update_options(options: Options)
  46.597 +  { session_actor !? Update_Options(options) }
  46.598 +
  46.599 +  def dialog_result(id: Document_ID.Generic, serial: Long, result: String)
  46.600 +  { session_actor ! Session.Dialog_Result(id, serial, result) }
  46.601 +}
    47.1 --- a/src/Pure/Proof/extraction.ML	Tue Mar 18 09:39:07 2014 -0700
    47.2 +++ b/src/Pure/Proof/extraction.ML	Tue Mar 18 21:02:33 2014 +0100
    47.3 @@ -466,9 +466,9 @@
    47.4        "(realizes (r) (!!x. PROP P (x))) ==  \
    47.5      \  (!!x. PROP realizes (r (x)) (PROP P (x)))"] #>
    47.6  
    47.7 -   Attrib.setup (Binding.name "extraction_expand") (Scan.succeed (extraction_expand false))
    47.8 +   Attrib.setup @{binding extraction_expand} (Scan.succeed (extraction_expand false))
    47.9       "specify theorems to be expanded during extraction" #>
   47.10 -   Attrib.setup (Binding.name "extraction_expand_def") (Scan.succeed (extraction_expand true))
   47.11 +   Attrib.setup @{binding extraction_expand_def} (Scan.succeed (extraction_expand true))
   47.12       "specify definitions to be expanded during extraction");
   47.13  
   47.14  
    48.1 --- a/src/Pure/Proof/proof_syntax.ML	Tue Mar 18 09:39:07 2014 -0700
    48.2 +++ b/src/Pure/Proof/proof_syntax.ML	Tue Mar 18 21:02:33 2014 +0100
    48.3 @@ -63,9 +63,9 @@
    48.4         ("", idtT --> paramsT, Delimfix "_"),
    48.5         ("", paramT --> paramsT, Delimfix "_")]
    48.6    |> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
    48.7 -      [("_Lam", [paramsT, proofT] ---> proofT, Mixfix ("(1\\<^bold>\\<lambda>_./ _)", [0, 3], 3)),
    48.8 -       (Lexicon.mark_const "Appt", [proofT, aT] ---> proofT, Mixfix ("(1_ \\<cdot>/ _)", [4, 5], 4)),
    48.9 -       (Lexicon.mark_const "AppP", [proofT, proofT] ---> proofT, Mixfix ("(1_ \\<bullet>/ _)", [4, 5], 4))]
   48.10 +      [("_Lam", [paramsT, proofT] ---> proofT, Mixfix ("(1\<^bold>\<lambda>_./ _)", [0, 3], 3)),
   48.11 +       (Lexicon.mark_const "Appt", [proofT, aT] ---> proofT, Mixfix ("(1_ \<cdot>/ _)", [4, 5], 4)),
   48.12 +       (Lexicon.mark_const "AppP", [proofT, proofT] ---> proofT, Mixfix ("(1_ \<bullet>/ _)", [4, 5], 4))]
   48.13    |> Sign.add_trrules (map Syntax.Parse_Print_Rule
   48.14        [(Ast.mk_appl (Ast.Constant "_Lam")
   48.15            [Ast.mk_appl (Ast.Constant "_Lam0")
    49.1 --- a/src/Pure/Pure.thy	Tue Mar 18 09:39:07 2014 -0700
    49.2 +++ b/src/Pure/Pure.thy	Tue Mar 18 21:02:33 2014 +0100
    49.3 @@ -103,6 +103,7 @@
    49.4      "ProofGeneral.inform_file_retracted" :: control
    49.5  begin
    49.6  
    49.7 +ML_file "ML/ml_antiquotations.ML"
    49.8  ML_file "ML/ml_thms.ML"
    49.9  ML_file "Isar/isar_syn.ML"
   49.10  ML_file "Isar/calculation.ML"
    50.1 --- a/src/Pure/ROOT	Tue Mar 18 09:39:07 2014 -0700
    50.2 +++ b/src/Pure/ROOT	Tue Mar 18 21:02:33 2014 +0100
    50.3 @@ -161,6 +161,8 @@
    50.4      "PIDE/markup.ML"
    50.5      "PIDE/protocol.ML"
    50.6      "PIDE/query_operation.ML"
    50.7 +    "PIDE/resources.ML"
    50.8 +    "PIDE/session.ML"
    50.9      "PIDE/xml.ML"
   50.10      "PIDE/yxml.ML"
   50.11      "Proof/extraction.ML"
   50.12 @@ -189,7 +191,6 @@
   50.13      "System/isar.ML"
   50.14      "System/message_channel.ML"
   50.15      "System/options.ML"
   50.16 -    "System/session.ML"
   50.17      "System/system_channel.ML"
   50.18      "Thy/html.ML"
   50.19      "Thy/latex.ML"
   50.20 @@ -198,7 +199,6 @@
   50.21      "Thy/thm_deps.ML"
   50.22      "Thy/thy_header.ML"
   50.23      "Thy/thy_info.ML"
   50.24 -    "Thy/thy_load.ML"
   50.25      "Thy/thy_output.ML"
   50.26      "Thy/thy_syntax.ML"
   50.27      "Tools/build.ML"
    51.1 --- a/src/Pure/ROOT.ML	Tue Mar 18 09:39:07 2014 -0700
    51.2 +++ b/src/Pure/ROOT.ML	Tue Mar 18 21:02:33 2014 +0100
    51.3 @@ -39,7 +39,7 @@
    51.4  use "ML/ml_lex.ML";
    51.5  use "ML/ml_parse.ML";
    51.6  use "General/secure.ML";
    51.7 -(*^^^^^ end of basic ML bootstrap ^^^^^*)
    51.8 +(*^^^^^ end of ML bootstrap 0 ^^^^^*)
    51.9  use "General/integer.ML";
   51.10  use "General/stack.ML";
   51.11  use "General/queue.ML";
   51.12 @@ -211,18 +211,11 @@
   51.13  use "Syntax/syntax_phases.ML";
   51.14  use "Isar/local_defs.ML";
   51.15  
   51.16 -(*proof term operations*)
   51.17 -use "Proof/reconstruct.ML";
   51.18 -use "Proof/proof_syntax.ML";
   51.19 -use "Proof/proof_rewrite_rules.ML";
   51.20 -use "Proof/proof_checker.ML";
   51.21 -
   51.22  (*outer syntax*)
   51.23  use "Isar/token.ML";
   51.24  use "Isar/keyword.ML";
   51.25  use "Isar/parse.ML";
   51.26  use "Isar/args.ML";
   51.27 -use "ML/ml_context.ML";
   51.28  
   51.29  (*theory sources*)
   51.30  use "Thy/thy_header.ML";
   51.31 @@ -230,10 +223,15 @@
   51.32  use "Thy/html.ML";
   51.33  use "Thy/latex.ML";
   51.34  
   51.35 +(*ML with context and antiquotations*)
   51.36 +use "ML/ml_context.ML";
   51.37 +use "ML/ml_antiquotation.ML";
   51.38 +val use = ML_Context.eval_file true o Path.explode;
   51.39 +(*^^^^^ end of ML bootstrap 1 ^^^^^*)
   51.40 +
   51.41  (*basic proof engine*)
   51.42  use "Isar/proof_display.ML";
   51.43  use "Isar/attrib.ML";
   51.44 -use "ML/ml_antiquotation.ML";
   51.45  use "Isar/context_rules.ML";
   51.46  use "Isar/method.ML";
   51.47  use "Isar/proof.ML";
   51.48 @@ -267,6 +265,13 @@
   51.49  use "Isar/proof_node.ML";
   51.50  use "Isar/toplevel.ML";
   51.51  
   51.52 +(*proof term operations*)
   51.53 +use "Proof/reconstruct.ML";
   51.54 +use "Proof/proof_syntax.ML";
   51.55 +use "Proof/proof_rewrite_rules.ML";
   51.56 +use "Proof/proof_checker.ML";
   51.57 +use "Proof/extraction.ML";
   51.58 +
   51.59  (*theory documents*)
   51.60  use "System/isabelle_system.ML";
   51.61  use "Thy/term_style.ML";
   51.62 @@ -276,7 +281,7 @@
   51.63  use "Thy/present.ML";
   51.64  use "PIDE/command.ML";
   51.65  use "PIDE/query_operation.ML";
   51.66 -use "Thy/thy_load.ML";
   51.67 +use "PIDE/resources.ML";
   51.68  use "Thy/thy_info.ML";
   51.69  use "PIDE/document.ML";
   51.70  
   51.71 @@ -286,12 +291,10 @@
   51.72  
   51.73  use "subgoal.ML";
   51.74  
   51.75 -use "Proof/extraction.ML";
   51.76 -
   51.77  
   51.78  (* Isabelle/Isar system *)
   51.79  
   51.80 -use "System/session.ML";
   51.81 +use "PIDE/session.ML";
   51.82  use "System/command_line.ML";
   51.83  use "System/system_channel.ML";
   51.84  use "System/message_channel.ML";
    52.1 --- a/src/Pure/System/session.ML	Tue Mar 18 09:39:07 2014 -0700
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,79 +0,0 @@
    52.4 -(*  Title:      Pure/System/session.ML
    52.5 -    Author:     Makarius
    52.6 -
    52.7 -Session management -- internal state of logic images.
    52.8 -*)
    52.9 -
   52.10 -signature SESSION =
   52.11 -sig
   52.12 -  val name: unit -> string
   52.13 -  val welcome: unit -> string
   52.14 -  val init: bool -> bool -> Path.T -> string -> bool -> string -> (string * string) list ->
   52.15 -    string -> string * string -> bool * string -> bool -> unit
   52.16 -  val finish: unit -> unit
   52.17 -  val protocol_handler: string -> unit
   52.18 -  val init_protocol_handlers: unit -> unit
   52.19 -end;
   52.20 -
   52.21 -structure Session: SESSION =
   52.22 -struct
   52.23 -
   52.24 -(** session identification -- not thread-safe **)
   52.25 -
   52.26 -val session = Unsynchronized.ref {chapter = "Pure", name = "Pure"};
   52.27 -val session_finished = Unsynchronized.ref false;
   52.28 -
   52.29 -fun name () = "Isabelle/" ^ #name (! session);
   52.30 -
   52.31 -fun welcome () =
   52.32 -  if Distribution.is_official then
   52.33 -    "Welcome to " ^ name () ^ " (" ^ Distribution.version ^ ")"
   52.34 -  else "Unofficial version of " ^ name () ^ " (" ^ Distribution.version ^ ")";
   52.35 -
   52.36 -
   52.37 -(* init *)
   52.38 -
   52.39 -fun init build info info_path doc doc_graph doc_output doc_variants
   52.40 -    parent (chapter, name) doc_dump verbose =
   52.41 -  if #name (! session) <> parent orelse not (! session_finished) then
   52.42 -    error ("Unfinished parent session " ^ quote parent ^ " for " ^ quote name)
   52.43 -  else
   52.44 -    let
   52.45 -      val _ = session := {chapter = chapter, name = name};
   52.46 -      val _ = session_finished := false;
   52.47 -    in
   52.48 -      Present.init build info info_path (if doc = "false" then "" else doc)
   52.49 -        doc_graph doc_output doc_variants (chapter, name)
   52.50 -        doc_dump verbose (map Thy_Info.get_theory (Thy_Info.get_names ()))
   52.51 -    end;
   52.52 -
   52.53 -
   52.54 -(* finish *)
   52.55 -
   52.56 -fun finish () =
   52.57 - (Execution.shutdown ();
   52.58 -  Thy_Info.finish ();
   52.59 -  Present.finish ();
   52.60 -  Outer_Syntax.check_syntax ();
   52.61 -  Future.shutdown ();
   52.62 -  Event_Timer.shutdown ();
   52.63 -  Future.shutdown ();
   52.64 -  session_finished := true);
   52.65 -
   52.66 -
   52.67 -(** protocol handlers **)
   52.68 -
   52.69 -val protocol_handlers = Synchronized.var "protocol_handlers" ([]: string list);
   52.70 -
   52.71 -fun protocol_handler name =
   52.72 -  Synchronized.change protocol_handlers (fn handlers =>
   52.73 -   (Output.try_protocol_message (Markup.protocol_handler name) "";
   52.74 -    if not (member (op =) handlers name) then ()
   52.75 -    else warning ("Redefining protocol handler: " ^ quote name);
   52.76 -    update (op =) name handlers));
   52.77 -
   52.78 -fun init_protocol_handlers () =
   52.79 -  Synchronized.value protocol_handlers
   52.80 -  |> List.app (fn name => Output.try_protocol_message (Markup.protocol_handler name) "");
   52.81 -
   52.82 -end;
    53.1 --- a/src/Pure/System/session.scala	Tue Mar 18 09:39:07 2014 -0700
    53.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    53.3 @@ -1,598 +0,0 @@
    53.4 -/*  Title:      Pure/System/session.scala
    53.5 -    Author:     Makarius
    53.6 -    Options:    :folding=explicit:collapseFolds=1:
    53.7 -
    53.8 -Main Isabelle/Scala session, potentially with running prover process.
    53.9 -*/
   53.10 -
   53.11 -package isabelle
   53.12 -
   53.13 -
   53.14 -import java.util.{Timer, TimerTask}
   53.15 -
   53.16 -import scala.collection.mutable
   53.17 -import scala.collection.immutable.Queue
   53.18 -import scala.actors.TIMEOUT
   53.19 -import scala.actors.Actor._
   53.20 -
   53.21 -
   53.22 -object Session
   53.23 -{
   53.24 -  /* events */
   53.25 -
   53.26 -  //{{{
   53.27 -  case class Statistics(props: Properties.T)
   53.28 -  case class Global_Options(options: Options)
   53.29 -  case object Caret_Focus
   53.30 -  case class Raw_Edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
   53.31 -  case class Dialog_Result(id: Document_ID.Generic, serial: Long, result: String)
   53.32 -  case class Commands_Changed(
   53.33 -    assignment: Boolean, nodes: Set[Document.Node.Name], commands: Set[Command])
   53.34 -
   53.35 -  sealed abstract class Phase
   53.36 -  case object Inactive extends Phase
   53.37 -  case object Startup extends Phase  // transient
   53.38 -  case object Failed extends Phase
   53.39 -  case object Ready extends Phase
   53.40 -  case object Shutdown extends Phase  // transient
   53.41 -  //}}}
   53.42 -
   53.43 -
   53.44 -  /* protocol handlers */
   53.45 -
   53.46 -  type Prover = Isabelle_Process with Protocol
   53.47 -
   53.48 -  abstract class Protocol_Handler
   53.49 -  {
   53.50 -    def stop(prover: Prover): Unit = {}
   53.51 -    val functions: Map[String, (Prover, Isabelle_Process.Protocol_Output) => Boolean]
   53.52 -  }
   53.53 -
   53.54 -  class Protocol_Handlers(
   53.55 -    handlers: Map[String, Session.Protocol_Handler] = Map.empty,
   53.56 -    functions: Map[String, Isabelle_Process.Protocol_Output => Boolean] = Map.empty)
   53.57 -  {
   53.58 -    def get(name: String): Option[Protocol_Handler] = handlers.get(name)
   53.59 -
   53.60 -    def add(prover: Prover, name: String): Protocol_Handlers =
   53.61 -    {
   53.62 -      val (handlers1, functions1) =
   53.63 -        handlers.get(name) match {
   53.64 -          case Some(old_handler) =>
   53.65 -            System.err.println("Redefining protocol handler: " + name)
   53.66 -            old_handler.stop(prover)
   53.67 -            (handlers - name, functions -- old_handler.functions.keys)
   53.68 -          case None => (handlers, functions)
   53.69 -        }
   53.70 -
   53.71 -      val (handlers2, functions2) =
   53.72 -        try {
   53.73 -          val new_handler = Class.forName(name).newInstance.asInstanceOf[Protocol_Handler]
   53.74 -          val new_functions =
   53.75 -            for ((a, f) <- new_handler.functions.toList) yield
   53.76 -              (a, (msg: Isabelle_Process.Protocol_Output) => f(prover, msg))
   53.77 -
   53.78 -          val dups = for ((a, _) <- new_functions if functions1.isDefinedAt(a)) yield a
   53.79 -          if (!dups.isEmpty) error("Duplicate protocol functions: " + commas_quote(dups))
   53.80 -
   53.81 -          (handlers1 + (name -> new_handler), functions1 ++ new_functions)
   53.82 -        }
   53.83 -        catch {
   53.84 -          case exn: Throwable =>
   53.85 -            System.err.println("Failed to initialize protocol handler: " +
   53.86 -              name + "\n" + Exn.message(exn))
   53.87 -            (handlers1, functions1)
   53.88 -        }
   53.89 -
   53.90 -      new Protocol_Handlers(handlers2, functions2)
   53.91 -    }
   53.92 -
   53.93 -    def invoke(msg: Isabelle_Process.Protocol_Output): Boolean =
   53.94 -      msg.properties match {
   53.95 -        case Markup.Function(a) if functions.isDefinedAt(a) =>
   53.96 -          try { functions(a)(msg) }
   53.97 -          catch {
   53.98 -            case exn: Throwable =>
   53.99 -              System.err.println("Failed invocation of protocol function: " +
  53.100 -                quote(a) + "\n" + Exn.message(exn))
  53.101 -            false
  53.102 -          }
  53.103 -        case _ => false
  53.104 -      }
  53.105 -
  53.106 -    def stop(prover: Prover): Protocol_Handlers =
  53.107 -    {
  53.108 -      for ((_, handler) <- handlers) handler.stop(prover)
  53.109 -      new Protocol_Handlers()
  53.110 -    }
  53.111 -  }
  53.112 -}
  53.113 -
  53.114 -
  53.115 -class Session(val thy_load: Thy_Load)
  53.116 -{
  53.117 -  /* global flags */
  53.118 -
  53.119 -  @volatile var timing: Boolean = false
  53.120 -  @volatile var verbose: Boolean = false
  53.121 -
  53.122 -
  53.123 -  /* tuning parameters */
  53.124 -
  53.125 -  def output_delay: Time = Time.seconds(0.1)  // prover output (markup, common messages)
  53.126 -  def message_delay: Time = Time.seconds(0.1)  // prover input/output messages
  53.127 -  def prune_delay: Time = Time.seconds(60.0)  // prune history -- delete old versions
  53.128 -  def prune_size: Int = 0  // size of retained history
  53.129 -  def syslog_limit: Int = 100
  53.130 -  def reparse_limit: Int = 0
  53.131 -
  53.132 -
  53.133 -  /* pervasive event buses */
  53.134 -
  53.135 -  val statistics = new Event_Bus[Session.Statistics]
  53.136 -  val global_options = new Event_Bus[Session.Global_Options]
  53.137 -  val caret_focus = new Event_Bus[Session.Caret_Focus.type]
  53.138 -  val raw_edits = new Event_Bus[Session.Raw_Edits]
  53.139 -  val commands_changed = new Event_Bus[Session.Commands_Changed]
  53.140 -  val phase_changed = new Event_Bus[Session.Phase]
  53.141 -  val syslog_messages = new Event_Bus[Isabelle_Process.Output]
  53.142 -  val raw_output_messages = new Event_Bus[Isabelle_Process.Output]
  53.143 -  val all_messages = new Event_Bus[Isabelle_Process.Message]  // potential bottle-neck
  53.144 -  val trace_events = new Event_Bus[Simplifier_Trace.Event.type]
  53.145 -
  53.146 -
  53.147 -  /** buffered command changes (delay_first discipline) **/
  53.148 -
  53.149 -  //{{{
  53.150 -  private case object Stop
  53.151 -
  53.152 -  private val (_, commands_changed_buffer) =
  53.153 -    Simple_Thread.actor("commands_changed_buffer", daemon = true)
  53.154 -  {
  53.155 -    var finished = false
  53.156 -    while (!finished) {
  53.157 -      receive {
  53.158 -        case Stop => finished = true; reply(())
  53.159 -        case changed: Session.Commands_Changed => commands_changed.event(changed)
  53.160 -        case bad => System.err.println("commands_changed_buffer: ignoring bad message " + bad)
  53.161 -      }
  53.162 -    }
  53.163 -  }
  53.164 -  //}}}
  53.165 -
  53.166 -
  53.167 -  /** pipelined change parsing **/
  53.168 -
  53.169 -  //{{{
  53.170 -  private case class Text_Edits(
  53.171 -    previous: Future[Document.Version],
  53.172 -    doc_blobs: Document.Blobs,
  53.173 -    text_edits: List[Document.Edit_Text],
  53.174 -    version_result: Promise[Document.Version])
  53.175 -
  53.176 -  private val (_, change_parser) = Simple_Thread.actor("change_parser", daemon = true)
  53.177 -  {
  53.178 -    var finished = false
  53.179 -    while (!finished) {
  53.180 -      receive {
  53.181 -        case Stop => finished = true; reply(())
  53.182 -
  53.183 -        case Text_Edits(previous, doc_blobs, text_edits, version_result) =>
  53.184 -          val prev = previous.get_finished
  53.185 -          val (syntax_changed, doc_edits, version) =
  53.186 -            Timing.timeit("Thy_Load.text_edits", timing) {
  53.187 -              thy_load.text_edits(reparse_limit, prev, doc_blobs, text_edits)
  53.188 -            }
  53.189 -          version_result.fulfill(version)
  53.190 -          sender ! Change(doc_blobs, syntax_changed, doc_edits, prev, version)
  53.191 -
  53.192 -        case bad => System.err.println("change_parser: ignoring bad message " + bad)
  53.193 -      }
  53.194 -    }
  53.195 -  }
  53.196 -  //}}}
  53.197 -
  53.198 -
  53.199 -
  53.200 -  /** main protocol actor **/
  53.201 -
  53.202 -  /* global state */
  53.203 -
  53.204 -  private val syslog = Volatile(Queue.empty[XML.Elem])
  53.205 -  def current_syslog(): String = cat_lines(syslog().iterator.map(XML.content))
  53.206 -
  53.207 -  @volatile private var _phase: Session.Phase = Session.Inactive
  53.208 -  private def phase_=(new_phase: Session.Phase)
  53.209 -  {
  53.210 -    _phase = new_phase
  53.211 -    phase_changed.event(new_phase)
  53.212 -  }
  53.213 -  def phase = _phase
  53.214 -  def is_ready: Boolean = phase == Session.Ready
  53.215 -
  53.216 -  private val global_state = Volatile(Document.State.init)
  53.217 -  def current_state(): Document.State = global_state()
  53.218 -
  53.219 -  def recent_syntax(): Outer_Syntax =
  53.220 -  {
  53.221 -    val version = current_state().recent_finished.version.get_finished
  53.222 -    if (version.is_init) thy_load.base_syntax
  53.223 -    else version.syntax
  53.224 -  }
  53.225 -
  53.226 -  def snapshot(name: Document.Node.Name = Document.Node.Name.empty,
  53.227 -      pending_edits: List[Text.Edit] = Nil): Document.Snapshot =
  53.228 -    global_state().snapshot(name, pending_edits)
  53.229 -
  53.230 -
  53.231 -  /* protocol handlers */
  53.232 -
  53.233 -  @volatile private var _protocol_handlers = new Session.Protocol_Handlers()
  53.234 -
  53.235 -  def protocol_handler(name: String): Option[Session.Protocol_Handler] =
  53.236 -    _protocol_handlers.get(name)
  53.237 -
  53.238 -
  53.239 -  /* theory files */
  53.240 -
  53.241 -  def header_edit(name: Document.Node.Name, header: Document.Node.Header): Document.Edit_Text =
  53.242 -  {
  53.243 -    val header1 =
  53.244 -      if (thy_load.loaded_theories(name.theory))
  53.245 -        header.error("Cannot update finished theory " + quote(name.theory))
  53.246 -      else header
  53.247 -    (name, Document.Node.Deps(header1))
  53.248 -  }
  53.249 -
  53.250 -
  53.251 -  /* actor messages */
  53.252 -
  53.253 -  private case class Start(args: List[String])
  53.254 -  private case class Cancel_Exec(exec_id: Document_ID.Exec)
  53.255 -  private case class Change(
  53.256 -    doc_blobs: Document.Blobs,
  53.257 -    syntax_changed: Boolean,
  53.258 -    doc_edits: List[Document.Edit_Command],
  53.259 -    previous: Document.Version,
  53.260 -    version: Document.Version)
  53.261 -  private case class Protocol_Command(name: String, args: List[String])
  53.262 -  private case class Messages(msgs: List[Isabelle_Process.Message])
  53.263 -  private case class Update_Options(options: Options)
  53.264 -
  53.265 -  private val (_, session_actor) = Simple_Thread.actor("session_actor", daemon = true)
  53.266 -  {
  53.267 -    val this_actor = self
  53.268 -
  53.269 -    var prune_next = System.currentTimeMillis() + prune_delay.ms
  53.270 -
  53.271 -
  53.272 -    /* buffered prover messages */
  53.273 -
  53.274 -    object receiver
  53.275 -    {
  53.276 -      private var buffer = new mutable.ListBuffer[Isabelle_Process.Message]
  53.277 -
  53.278 -      private def flush(): Unit = synchronized {
  53.279 -        if (!buffer.isEmpty) {
  53.280 -          val msgs = buffer.toList
  53.281 -          this_actor ! Messages(msgs)
  53.282 -          buffer = new mutable.ListBuffer[Isabelle_Process.Message]
  53.283 -        }
  53.284 -      }
  53.285 -      def invoke(msg: Isabelle_Process.Message): Unit = synchronized {
  53.286 -        msg match {
  53.287 -          case _: Isabelle_Process.Input =>
  53.288 -            buffer += msg
  53.289 -          case output: Isabelle_Process.Protocol_Output if output.properties == Markup.Flush =>
  53.290 -            flush()
  53.291 -          case output: Isabelle_Process.Output =>
  53.292 -            buffer += msg
  53.293 -            if (output.is_syslog)
  53.294 -              syslog >> (queue =>
  53.295 -                {
  53.296 -                  val queue1 = queue.enqueue(output.message)
  53.297 -                  if (queue1.length > syslog_limit) queue1.dequeue._2 else queue1
  53.298 -                })
  53.299 -        }
  53.300 -      }
  53.301 -
  53.302 -      private val timer = new Timer("session_actor.receiver", true)
  53.303 -      timer.schedule(new TimerTask { def run = flush }, message_delay.ms, message_delay.ms)
  53.304 -
  53.305 -      def cancel() { timer.cancel() }
  53.306 -    }
  53.307 -
  53.308 -    var prover: Option[Session.Prover] = None
  53.309 -
  53.310 -
  53.311 -    /* delayed command changes */
  53.312 -
  53.313 -    object delay_commands_changed
  53.314 -    {
  53.315 -      private var changed_assignment: Boolean = false
  53.316 -      private var changed_nodes: Set[Document.Node.Name] = Set.empty
  53.317 -      private var changed_commands: Set[Command] = Set.empty
  53.318 -
  53.319 -      private var flush_time: Option[Long] = None
  53.320 -
  53.321 -      def flush_timeout: Long =
  53.322 -        flush_time match {
  53.323 -          case None => 5000L
  53.324 -          case Some(time) => (time - System.currentTimeMillis()) max 0
  53.325 -        }
  53.326 -
  53.327 -      def flush()
  53.328 -      {
  53.329 -        if (changed_assignment || !changed_nodes.isEmpty || !changed_commands.isEmpty)
  53.330 -          commands_changed_buffer !
  53.331 -            Session.Commands_Changed(changed_assignment, changed_nodes, changed_commands)
  53.332 -        changed_assignment = false
  53.333 -        changed_nodes = Set.empty
  53.334 -        changed_commands = Set.empty
  53.335 -        flush_time = None
  53.336 -      }
  53.337 -
  53.338 -      def invoke(assign: Boolean, commands: List[Command])
  53.339 -      {
  53.340 -        changed_assignment |= assign
  53.341 -        for (command <- commands) {
  53.342 -          changed_nodes += command.node_name
  53.343 -          changed_commands += command
  53.344 -        }
  53.345 -        val now = System.currentTimeMillis()
  53.346 -        flush_time match {
  53.347 -          case None => flush_time = Some(now + output_delay.ms)
  53.348 -          case Some(time) => if (now >= time) flush()
  53.349 -        }
  53.350 -      }
  53.351 -    }
  53.352 -
  53.353 -
  53.354 -    /* raw edits */
  53.355 -
  53.356 -    def handle_raw_edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
  53.357 -    //{{{
  53.358 -    {
  53.359 -      prover.get.discontinue_execution()
  53.360 -
  53.361 -      val previous = global_state().history.tip.version
  53.362 -      val version = Future.promise[Document.Version]
  53.363 -      val change = global_state >>> (_.continue_history(previous, edits, version))
  53.364 -
  53.365 -      raw_edits.event(Session.Raw_Edits(doc_blobs, edits))
  53.366 -      change_parser ! Text_Edits(previous, doc_blobs, edits, version)
  53.367 -    }
  53.368 -    //}}}
  53.369 -
  53.370 -
  53.371 -    /* resulting changes */
  53.372 -
  53.373 -    def handle_change(change: Change)
  53.374 -    //{{{
  53.375 -    {
  53.376 -      val Change(doc_blobs, syntax_changed, doc_edits, previous, version) = change
  53.377 -
  53.378 -      def id_command(command: Command)
  53.379 -      {
  53.380 -        for {
  53.381 -          digest <- command.blobs_digests
  53.382 -          if !global_state().defined_blob(digest)
  53.383 -        } {
  53.384 -          doc_blobs.get(digest) match {
  53.385 -            case Some(blob) =>
  53.386 -              global_state >> (_.define_blob(digest))
  53.387 -              prover.get.define_blob(blob)
  53.388 -            case None =>
  53.389 -              System.err.println("Missing blob for SHA1 digest " + digest)
  53.390 -          }
  53.391 -        }
  53.392 -
  53.393 -        if (!global_state().defined_command(command.id)) {
  53.394 -          global_state >> (_.define_command(command))
  53.395 -          prover.get.define_command(command)
  53.396 -        }
  53.397 -      }
  53.398 -      doc_edits foreach {
  53.399 -        case (_, edit) =>
  53.400 -          edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
  53.401 -      }
  53.402 -
  53.403 -      val assignment = global_state().the_assignment(previous).check_finished
  53.404 -      global_state >> (_.define_version(version, assignment))
  53.405 -      prover.get.update(previous.id, version.id, doc_edits)
  53.406 -
  53.407 -      if (syntax_changed) thy_load.syntax_changed()
  53.408 -    }
  53.409 -    //}}}
  53.410 -
  53.411 -
  53.412 -    /* prover output */
  53.413 -
  53.414 -    def handle_output(output: Isabelle_Process.Output)
  53.415 -    //{{{
  53.416 -    {
  53.417 -      def bad_output()
  53.418 -      {
  53.419 -        if (verbose)
  53.420 -          System.err.println("Ignoring prover output: " + output.message.toString)
  53.421 -      }
  53.422 -
  53.423 -      def accumulate(state_id: Document_ID.Generic, message: XML.Elem)
  53.424 -      {
  53.425 -        try {
  53.426 -          val st = global_state >>> (_.accumulate(state_id, message))
  53.427 -          delay_commands_changed.invoke(false, List(st.command))
  53.428 -        }
  53.429 -        catch {
  53.430 -          case _: Document.State.Fail => bad_output()
  53.431 -        }
  53.432 -      }
  53.433 -
  53.434 -      output match {
  53.435 -        case msg: Isabelle_Process.Protocol_Output =>
  53.436 -          val handled = _protocol_handlers.invoke(msg)
  53.437 -          if (!handled) {
  53.438 -            msg.properties match {
  53.439 -              case Markup.Protocol_Handler(name) =>
  53.440 -                _protocol_handlers = _protocol_handlers.add(prover.get, name)
  53.441 -
  53.442 -              case Protocol.Command_Timing(state_id, timing) =>
  53.443 -                val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))
  53.444 -                accumulate(state_id, prover.get.xml_cache.elem(message))
  53.445 -
  53.446 -              case Markup.Assign_Update =>
  53.447 -                msg.text match {
  53.448 -                  case Protocol.Assign_Update(id, update) =>
  53.449 -                    try {
  53.450 -                      val cmds = global_state >>> (_.assign(id, update))
  53.451 -                      delay_commands_changed.invoke(true, cmds)
  53.452 -                    }
  53.453 -                    catch { case _: Document.State.Fail => bad_output() }
  53.454 -                  case _ => bad_output()
  53.455 -                }
  53.456 -                // FIXME separate timeout event/message!?
  53.457 -                if (prover.isDefined && System.currentTimeMillis() > prune_next) {
  53.458 -                  val old_versions = global_state >>> (_.prune_history(prune_size))
  53.459 -                  if (!old_versions.isEmpty) prover.get.remove_versions(old_versions)
  53.460 -                  prune_next = System.currentTimeMillis() + prune_delay.ms
  53.461 -                }
  53.462 -
  53.463 -              case Markup.Removed_Versions =>
  53.464 -                msg.text match {
  53.465 -                  case Protocol.Removed(removed) =>
  53.466 -                    try {
  53.467 -                      global_state >> (_.removed_versions(removed))
  53.468 -                    }
  53.469 -                    catch { case _: Document.State.Fail => bad_output() }
  53.470 -                  case _ => bad_output()
  53.471 -                }
  53.472 -
  53.473 -              case Markup.ML_Statistics(props) =>
  53.474 -                statistics.event(Session.Statistics(props))
  53.475 -
  53.476 -              case Markup.Task_Statistics(props) =>
  53.477 -                // FIXME
  53.478 -
  53.479 -              case _ => bad_output()
  53.480 -            }
  53.481 -          }
  53.482 -        case _ =>
  53.483 -          output.properties match {
  53.484 -            case Position.Id(state_id) =>
  53.485 -              accumulate(state_id, output.message)
  53.486 -  
  53.487 -            case _ if output.is_init =>
  53.488 -              phase = Session.Ready
  53.489 -  
  53.490 -            case Markup.Return_Code(rc) if output.is_exit =>
  53.491 -              if (rc == 0) phase = Session.Inactive
  53.492 -              else phase = Session.Failed
  53.493 -  
  53.494 -            case _ => raw_output_messages.event(output)
  53.495 -          }
  53.496 -        }
  53.497 -    }
  53.498 -    //}}}
  53.499 -
  53.500 -
  53.501 -    /* main loop */
  53.502 -
  53.503 -    //{{{
  53.504 -    var finished = false
  53.505 -    while (!finished) {
  53.506 -      receiveWithin(delay_commands_changed.flush_timeout) {
  53.507 -        case TIMEOUT => delay_commands_changed.flush()
  53.508 -
  53.509 -        case Start(args) if prover.isEmpty =>
  53.510 -          if (phase == Session.Inactive || phase == Session.Failed) {
  53.511 -            phase = Session.Startup
  53.512 -            prover = Some(new Isabelle_Process(receiver.invoke _, args) with Protocol)
  53.513 -          }
  53.514 -
  53.515 -        case Stop =>
  53.516 -          if (phase == Session.Ready) {
  53.517 -            _protocol_handlers = _protocol_handlers.stop(prover.get)
  53.518 -            global_state >> (_ => Document.State.init)  // FIXME event bus!?
  53.519 -            phase = Session.Shutdown
  53.520 -            prover.get.terminate
  53.521 -            prover = None
  53.522 -            phase = Session.Inactive
  53.523 -          }
  53.524 -          finished = true
  53.525 -          receiver.cancel()
  53.526 -          reply(())
  53.527 -
  53.528 -        case Update_Options(options) if prover.isDefined =>
  53.529 -          if (is_ready) {
  53.530 -            prover.get.options(options)
  53.531 -            handle_raw_edits(Document.Blobs.empty, Nil)
  53.532 -          }
  53.533 -          global_options.event(Session.Global_Options(options))
  53.534 -          reply(())
  53.535 -
  53.536 -        case Cancel_Exec(exec_id) if prover.isDefined =>
  53.537 -          prover.get.cancel_exec(exec_id)
  53.538 -
  53.539 -        case Session.Raw_Edits(doc_blobs, edits) if prover.isDefined =>
  53.540 -          handle_raw_edits(doc_blobs, edits)
  53.541 -          reply(())
  53.542 -
  53.543 -        case Session.Dialog_Result(id, serial, result) if prover.isDefined =>
  53.544 -          prover.get.dialog_result(serial, result)
  53.545 -          handle_output(new Isabelle_Process.Output(Protocol.Dialog_Result(id, serial, result)))
  53.546 -
  53.547 -        case Protocol_Command(name, args) if prover.isDefined =>
  53.548 -          prover.get.protocol_command(name, args:_*)
  53.549 -
  53.550 -        case Messages(msgs) =>
  53.551 -          msgs foreach {
  53.552 -            case input: Isabelle_Process.Input =>
  53.553 -              all_messages.event(input)
  53.554 -
  53.555 -            case output: Isabelle_Process.Output =>
  53.556 -              if (output.is_stdout || output.is_stderr) raw_output_messages.event(output)
  53.557 -              else handle_output(output)
  53.558 -              if (output.is_syslog) syslog_messages.event(output)
  53.559 -              all_messages.event(output)
  53.560 -          }
  53.561 -
  53.562 -        case change: Change
  53.563 -        if prover.isDefined && global_state().is_assigned(change.previous) =>
  53.564 -          handle_change(change)
  53.565 -
  53.566 -        case bad if !bad.isInstanceOf[Change] =>
  53.567 -          System.err.println("session_actor: ignoring bad message " + bad)
  53.568 -      }
  53.569 -    }
  53.570 -    //}}}
  53.571 -  }
  53.572 -
  53.573 -
  53.574 -  /* actions */
  53.575 -
  53.576 -  def start(args: List[String])
  53.577 -  {
  53.578 -    session_actor ! Start(args)
  53.579 -  }
  53.580 -
  53.581 -  def stop()
  53.582 -  {
  53.583 -    commands_changed_buffer !? Stop
  53.584 -    change_parser !? Stop
  53.585 -    session_actor !? Stop
  53.586 -  }
  53.587 -
  53.588 -  def protocol_command(name: String, args: String*)
  53.589 -  { session_actor ! Protocol_Command(name, args.toList) }
  53.590 -
  53.591 -  def cancel_exec(exec_id: Document_ID.Exec) { session_actor ! Cancel_Exec(exec_id) }
  53.592 -
  53.593 -  def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
  53.594 -  { if (!edits.isEmpty) session_actor !? Session.Raw_Edits(doc_blobs, edits) }
  53.595 -
  53.596 -  def update_options(options: Options)
  53.597 -  { session_actor !? Update_Options(options) }
  53.598 -
  53.599 -  def dialog_result(id: Document_ID.Generic, serial: Long, result: String)
  53.600 -  { session_actor ! Session.Dialog_Result(id, serial, result) }
  53.601 -}
    54.1 --- a/src/Pure/Thy/term_style.ML	Tue Mar 18 09:39:07 2014 -0700
    54.2 +++ b/src/Pure/Thy/term_style.ML	Tue Mar 18 21:02:33 2014 +0100
    54.3 @@ -33,7 +33,7 @@
    54.4  (* style parsing *)
    54.5  
    54.6  fun parse_single ctxt =
    54.7 -  Parse.position Parse.xname -- Args.parse >> (fn (name, args) =>
    54.8 +  Parse.position Parse.xname -- Parse.args >> (fn (name, args) =>
    54.9      let
   54.10        val (src, parse) = Args.check_src ctxt (get_data ctxt) (Args.src name args);
   54.11        val (f, _) = Args.syntax (Scan.lift parse) src ctxt;
   54.12 @@ -68,8 +68,8 @@
   54.13    end);
   54.14  
   54.15  fun sub_symbols (d :: s :: ss) =
   54.16 -      if Symbol.is_ascii_digit d andalso not (String.isPrefix ("\\<^") s)
   54.17 -      then d :: "\\<^sub>" :: sub_symbols (s :: ss)
   54.18 +      if Symbol.is_ascii_digit d andalso not (String.isPrefix ("\<^") s)
   54.19 +      then d :: "\<^sub>" :: sub_symbols (s :: ss)
   54.20        else d :: s :: ss
   54.21    | sub_symbols cs = cs;
   54.22  
   54.23 @@ -84,10 +84,10 @@
   54.24    | sub_term t = t;
   54.25  
   54.26  val _ = Theory.setup
   54.27 - (setup (Binding.name "lhs") (style_lhs_rhs fst) #>
   54.28 -  setup (Binding.name "rhs") (style_lhs_rhs snd) #>
   54.29 -  setup (Binding.name "prem") style_prem #>
   54.30 -  setup (Binding.name "concl") (Scan.succeed (K Logic.strip_imp_concl)) #>
   54.31 -  setup (Binding.name "sub") (Scan.succeed (K sub_term)));
   54.32 + (setup @{binding lhs} (style_lhs_rhs fst) #>
   54.33 +  setup @{binding rhs} (style_lhs_rhs snd) #>
   54.34 +  setup @{binding prem} style_prem #>
   54.35 +  setup @{binding concl} (Scan.succeed (K Logic.strip_imp_concl)) #>
   54.36 +  setup @{binding sub} (Scan.succeed (K sub_term)));
   54.37  
   54.38  end;
    55.1 --- a/src/Pure/Thy/thy_info.ML	Tue Mar 18 09:39:07 2014 -0700
    55.2 +++ b/src/Pure/Thy/thy_info.ML	Tue Mar 18 21:02:33 2014 +0100
    55.3 @@ -123,13 +123,13 @@
    55.4      SOME theory => theory
    55.5    | _ => error ("Theory loader: undefined entry for theory " ^ quote name));
    55.6  
    55.7 -val get_imports = Thy_Load.imports_of o get_theory;
    55.8 +val get_imports = Resources.imports_of o get_theory;
    55.9  
   55.10  (*Proof General legacy*)
   55.11  fun loaded_files name = NAMED_CRITICAL "Thy_Info" (fn () =>
   55.12    (case get_deps name of
   55.13      NONE => []
   55.14 -  | SOME {master = (thy_path, _), ...} => thy_path :: Thy_Load.loaded_files (get_theory name)));
   55.15 +  | SOME {master = (thy_path, _), ...} => thy_path :: Resources.loaded_files (get_theory name)));
   55.16  
   55.17  
   55.18  
   55.19 @@ -284,7 +284,7 @@
   55.20  
   55.21      val text_pos = Position.put_id (Document_ID.print exec_id) (Path.position thy_path);
   55.22      val (theory, present, weight) =
   55.23 -      Thy_Load.load_thy document last_timing update_time dir header text_pos text
   55.24 +      Resources.load_thy document last_timing update_time dir header text_pos text
   55.25          (if name = Context.PureN then [ML_Context.the_global_context ()] else parents);
   55.26      fun commit () = update_thy deps theory;
   55.27    in
   55.28 @@ -295,18 +295,18 @@
   55.29    (case lookup_deps name of
   55.30      SOME NONE => (true, NONE, Position.none, get_imports name, [])
   55.31    | NONE =>
   55.32 -      let val {master, text, theory_pos, imports, keywords} = Thy_Load.check_thy dir name
   55.33 +      let val {master, text, theory_pos, imports, keywords} = Resources.check_thy dir name
   55.34        in (false, SOME (make_deps master imports, text), theory_pos, imports, keywords) end
   55.35    | SOME (SOME {master, ...}) =>
   55.36        let
   55.37          val {master = master', text = text', theory_pos = theory_pos', imports = imports',
   55.38 -          keywords = keywords'} = Thy_Load.check_thy dir name;
   55.39 +          keywords = keywords'} = Resources.check_thy dir name;
   55.40          val deps' = SOME (make_deps master' imports', text');
   55.41          val current =
   55.42            #2 master = #2 master' andalso
   55.43              (case lookup_theory name of
   55.44                NONE => false
   55.45 -            | SOME theory => Thy_Load.loaded_files_current theory);
   55.46 +            | SOME theory => Resources.loaded_files_current theory);
   55.47        in (current, deps', theory_pos', imports', keywords') end);
   55.48  
   55.49  in
   55.50 @@ -317,7 +317,7 @@
   55.51    let
   55.52      val path = Path.expand (Path.explode str);
   55.53      val name = Path.implode (Path.base path);
   55.54 -    val node_name = File.full_path dir (Thy_Load.thy_path path);
   55.55 +    val node_name = File.full_path dir (Resources.thy_path path);
   55.56      fun check_entry (Task (node_name', _, _)) =
   55.57            if node_name = node_name' then ()
   55.58            else
   55.59 @@ -384,7 +384,7 @@
   55.60      val _ = use_theories {document = false, last_timing = K NONE, master_dir = master_dir} imports;
   55.61      val _ = Thy_Header.define_keywords header;
   55.62      val parents = map (get_theory o base_name o fst) imports;
   55.63 -  in Thy_Load.begin_theory master_dir header parents end;
   55.64 +  in Resources.begin_theory master_dir header parents end;
   55.65  
   55.66  
   55.67  (* register theory *)
   55.68 @@ -392,8 +392,8 @@
   55.69  fun register_thy theory =
   55.70    let
   55.71      val name = Context.theory_name theory;
   55.72 -    val {master, ...} = Thy_Load.check_thy (Thy_Load.master_directory theory) name;
   55.73 -    val imports = Thy_Load.imports_of theory;
   55.74 +    val {master, ...} = Resources.check_thy (Resources.master_directory theory) name;
   55.75 +    val imports = Resources.imports_of theory;
   55.76    in
   55.77      NAMED_CRITICAL "Thy_Info" (fn () =>
   55.78       (kill_thy name;
    56.1 --- a/src/Pure/Thy/thy_info.scala	Tue Mar 18 09:39:07 2014 -0700
    56.2 +++ b/src/Pure/Thy/thy_info.scala	Tue Mar 18 21:02:33 2014 +0100
    56.3 @@ -10,7 +10,7 @@
    56.4  import java.util.concurrent.{Future => JFuture}
    56.5  
    56.6  
    56.7 -class Thy_Info(thy_load: Thy_Load)
    56.8 +class Thy_Info(resources: Resources)
    56.9  {
   56.10    /* messages */
   56.11  
   56.12 @@ -33,9 +33,9 @@
   56.13    {
   56.14      def load_files(syntax: Outer_Syntax): List[String] =
   56.15      {
   56.16 -      val string = thy_load.with_thy_text(name, _.toString)
   56.17 -      if (thy_load.body_files_test(syntax, string))
   56.18 -        thy_load.body_files(syntax, string)
   56.19 +      val string = resources.with_thy_text(name, _.toString)
   56.20 +      if (resources.body_files_test(syntax, string))
   56.21 +        resources.body_files(syntax, string)
   56.22        else Nil
   56.23      }
   56.24    }
   56.25 @@ -71,7 +71,7 @@
   56.26        val import_errors =
   56.27          (for {
   56.28            (theory, names) <- seen_names.iterator_list
   56.29 -          if !thy_load.loaded_theories(theory)
   56.30 +          if !resources.loaded_theories(theory)
   56.31            if names.length > 1
   56.32          } yield
   56.33            "Incoherent imports for theory " + quote(theory) + ":\n" +
   56.34 @@ -82,10 +82,10 @@
   56.35        header_errors ::: import_errors
   56.36      }
   56.37  
   56.38 -    lazy val syntax: Outer_Syntax = thy_load.base_syntax.add_keywords(keywords)
   56.39 +    lazy val syntax: Outer_Syntax = resources.base_syntax.add_keywords(keywords)
   56.40  
   56.41      def loaded_theories: Set[String] =
   56.42 -      (thy_load.loaded_theories /: rev_deps) { case (loaded, dep) => loaded + dep.name.theory }
   56.43 +      (resources.loaded_theories /: rev_deps) { case (loaded, dep) => loaded + dep.name.theory }
   56.44  
   56.45      def load_files: List[Path] =
   56.46      {
   56.47 @@ -115,13 +115,13 @@
   56.48          required_by(initiators) + Position.here(require_pos)
   56.49  
   56.50      val required1 = required + thy
   56.51 -    if (required.seen_names.isDefinedAt(theory) || thy_load.loaded_theories(theory))
   56.52 +    if (required.seen_names.isDefinedAt(theory) || resources.loaded_theories(theory))
   56.53        required1
   56.54      else {
   56.55        try {
   56.56          if (initiators.contains(name)) error(cycle_msg(initiators))
   56.57          val header =
   56.58 -          try { thy_load.check_thy(name).cat_errors(message) }
   56.59 +          try { resources.check_thy(name).cat_errors(message) }
   56.60            catch { case ERROR(msg) => cat_error(msg, message) }
   56.61          val imports = header.imports.map((_, Position.File(name.node)))
   56.62          Dep(name, header) :: require_thys(name :: initiators, required1, imports)
    57.1 --- a/src/Pure/Thy/thy_load.ML	Tue Mar 18 09:39:07 2014 -0700
    57.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.3 @@ -1,243 +0,0 @@
    57.4 -(*  Title:      Pure/Thy/thy_load.ML
    57.5 -    Author:     Makarius
    57.6 -
    57.7 -Management of theory sources and auxiliary files.
    57.8 -*)
    57.9 -
   57.10 -signature THY_LOAD =
   57.11 -sig
   57.12 -  val master_directory: theory -> Path.T
   57.13 -  val imports_of: theory -> (string * Position.T) list
   57.14 -  val thy_path: Path.T -> Path.T
   57.15 -  val check_thy: Path.T -> string ->
   57.16 -   {master: Path.T * SHA1.digest, text: string, theory_pos: Position.T,
   57.17 -    imports: (string * Position.T) list, keywords: Thy_Header.keywords}
   57.18 -  val parse_files: string -> (theory -> Token.file list) parser
   57.19 -  val provide: Path.T * SHA1.digest -> theory -> theory
   57.20 -  val provide_parse_files: string -> (theory -> Token.file list * theory) parser
   57.21 -  val load_file: theory -> Path.T -> (Path.T * SHA1.digest) * string
   57.22 -  val loaded_files: theory -> Path.T list
   57.23 -  val loaded_files_current: theory -> bool
   57.24 -  val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory
   57.25 -  val load_thy: bool -> (Toplevel.transition -> Time.time option) -> int -> Path.T ->
   57.26 -    Thy_Header.header -> Position.T -> string -> theory list -> theory * (unit -> unit) * int
   57.27 -end;
   57.28 -
   57.29 -structure Thy_Load: THY_LOAD =
   57.30 -struct
   57.31 -
   57.32 -(* manage source files *)
   57.33 -
   57.34 -type files =
   57.35 - {master_dir: Path.T,  (*master directory of theory source*)
   57.36 -  imports: (string * Position.T) list,  (*source specification of imports*)
   57.37 -  provided: (Path.T * SHA1.digest) list};  (*source path, digest*)
   57.38 -
   57.39 -fun make_files (master_dir, imports, provided): files =
   57.40 - {master_dir = master_dir, imports = imports, provided = provided};
   57.41 -
   57.42 -structure Files = Theory_Data
   57.43 -(
   57.44 -  type T = files;
   57.45 -  val empty = make_files (Path.current, [], []);
   57.46 -  fun extend _ = empty;
   57.47 -  fun merge _ = empty;
   57.48 -);
   57.49 -
   57.50 -fun map_files f =
   57.51 -  Files.map (fn {master_dir, imports, provided} =>
   57.52 -    make_files (f (master_dir, imports, provided)));
   57.53 -
   57.54 -
   57.55 -val master_directory = #master_dir o Files.get;
   57.56 -val imports_of = #imports o Files.get;
   57.57 -
   57.58 -fun put_deps master_dir imports = map_files (fn _ => (master_dir, imports, []));
   57.59 -
   57.60 -
   57.61 -(* theory files *)
   57.62 -
   57.63 -val thy_path = Path.ext "thy";
   57.64 -
   57.65 -fun check_file dir file = File.check_file (File.full_path dir file);
   57.66 -
   57.67 -fun check_thy dir thy_name =
   57.68 -  let
   57.69 -    val path = thy_path (Path.basic thy_name);
   57.70 -    val master_file = check_file dir path;
   57.71 -    val text = File.read master_file;
   57.72 -
   57.73 -    val {name = (name, pos), imports, keywords} =
   57.74 -      Thy_Header.read (Path.position master_file) text;
   57.75 -    val _ = thy_name <> name andalso
   57.76 -      error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name ^ Position.here pos);
   57.77 -  in
   57.78 -   {master = (master_file, SHA1.digest text), text = text, theory_pos = pos,
   57.79 -    imports = imports, keywords = keywords}
   57.80 -  end;
   57.81 -
   57.82 -
   57.83 -(* load files *)
   57.84 -
   57.85 -fun parse_files cmd =
   57.86 -  Scan.ahead Parse.not_eof -- Parse.path >> (fn (tok, name) => fn thy =>
   57.87 -    (case Token.get_files tok of
   57.88 -      [] =>
   57.89 -        let
   57.90 -          val master_dir = master_directory thy;
   57.91 -          val pos = Token.pos_of tok;
   57.92 -          val src_paths = Keyword.command_files cmd (Path.explode name);
   57.93 -        in map (Command.read_file master_dir pos) src_paths end
   57.94 -    | files => map Exn.release files));
   57.95 -
   57.96 -fun provide (src_path, id) =
   57.97 -  map_files (fn (master_dir, imports, provided) =>
   57.98 -    if AList.defined (op =) provided src_path then
   57.99 -      error ("Duplicate use of source file: " ^ Path.print src_path)
  57.100 -    else (master_dir, imports, (src_path, id) :: provided));
  57.101 -
  57.102 -fun provide_parse_files cmd =
  57.103 -  parse_files cmd >> (fn files => fn thy =>
  57.104 -    let
  57.105 -      val fs = files thy;
  57.106 -      val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy;
  57.107 -    in (fs, thy') end);
  57.108 -
  57.109 -fun load_file thy src_path =
  57.110 -  let
  57.111 -    val full_path = check_file (master_directory thy) src_path;
  57.112 -    val text = File.read full_path;
  57.113 -    val id = SHA1.digest text;
  57.114 -  in ((full_path, id), text) end;
  57.115 -
  57.116 -fun loaded_files_current thy =
  57.117 -  #provided (Files.get thy) |>
  57.118 -    forall (fn (src_path, id) =>
  57.119 -      (case try (load_file thy) src_path of
  57.120 -        NONE => false
  57.121 -      | SOME ((_, id'), _) => id = id'));
  57.122 -
  57.123 -(*Proof General legacy*)
  57.124 -fun loaded_files thy =
  57.125 -  let val {master_dir, provided, ...} = Files.get thy
  57.126 -  in map (File.full_path master_dir o #1) provided end;
  57.127 -
  57.128 -
  57.129 -(* load theory *)
  57.130 -
  57.131 -fun begin_theory master_dir {name, imports, keywords} parents =
  57.132 -  Theory.begin_theory name parents
  57.133 -  |> put_deps master_dir imports
  57.134 -  |> fold Thy_Header.declare_keyword keywords;
  57.135 -
  57.136 -fun excursion master_dir last_timing init elements =
  57.137 -  let
  57.138 -    fun prepare_span span =
  57.139 -      Thy_Syntax.span_content span
  57.140 -      |> Command.read init master_dir []
  57.141 -      |> (fn tr => Toplevel.put_timing (last_timing tr) tr);
  57.142 -
  57.143 -    fun element_result span_elem (st, _) =
  57.144 -      let
  57.145 -        val elem = Thy_Syntax.map_element prepare_span span_elem;
  57.146 -        val (results, st') = Toplevel.element_result elem st;
  57.147 -        val pos' = Toplevel.pos_of (Thy_Syntax.last_element elem);
  57.148 -      in (results, (st', pos')) end;
  57.149 -
  57.150 -    val (results, (end_state, end_pos)) =
  57.151 -      fold_map element_result elements (Toplevel.toplevel, Position.none);
  57.152 -
  57.153 -    val thy = Toplevel.end_theory end_pos end_state;
  57.154 -  in (results, thy) end;
  57.155 -
  57.156 -fun load_thy document last_timing update_time master_dir header text_pos text parents =
  57.157 -  let
  57.158 -    val time = ! Toplevel.timing;
  57.159 -
  57.160 -    val {name = (name, _), ...} = header;
  57.161 -    val _ = Thy_Header.define_keywords header;
  57.162 -
  57.163 -    val lexs = Keyword.get_lexicons ();
  57.164 -    val toks = Thy_Syntax.parse_tokens lexs text_pos text;
  57.165 -    val spans = Thy_Syntax.parse_spans toks;
  57.166 -    val elements = Thy_Syntax.parse_elements spans;
  57.167 -
  57.168 -    fun init () =
  57.169 -      begin_theory master_dir header parents
  57.170 -      |> Present.begin_theory update_time
  57.171 -          (fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans);
  57.172 -
  57.173 -    val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else ();
  57.174 -    val (results, thy) =
  57.175 -      cond_timeit time "" (fn () => excursion master_dir last_timing init elements);
  57.176 -    val _ = if time then writeln ("**** Finished theory " ^ quote name ^ " ****\n") else ();
  57.177 -
  57.178 -    fun present () =
  57.179 -      let
  57.180 -        val res = filter_out (Toplevel.is_ignored o #1) (maps Toplevel.join_results results);
  57.181 -        val ((minor, _), outer_syntax) = Outer_Syntax.get_syntax ();
  57.182 -      in
  57.183 -        if exists (Toplevel.is_skipped_proof o #2) res then
  57.184 -          warning ("Cannot present theory with skipped proofs: " ^ quote name)
  57.185 -        else
  57.186 -          let val tex_source =
  57.187 -            Thy_Output.present_thy minor Keyword.command_tags
  57.188 -              (Outer_Syntax.is_markup outer_syntax) res toks
  57.189 -            |> Buffer.content;
  57.190 -          in if document then Present.theory_output name tex_source else () end
  57.191 -      end;
  57.192 -
  57.193 -  in (thy, present, size text) end;
  57.194 -
  57.195 -
  57.196 -(* antiquotations *)
  57.197 -
  57.198 -local
  57.199 -
  57.200 -fun check_path strict ctxt dir (name, pos) =
  57.201 -  let
  57.202 -    val _ = Context_Position.report ctxt pos Markup.language_path;
  57.203 -
  57.204 -    val path = Path.append dir (Path.explode name)
  57.205 -      handle ERROR msg => error (msg ^ Position.here pos);
  57.206 -
  57.207 -    val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path));
  57.208 -    val _ =
  57.209 -      if can Path.expand path andalso File.exists path then ()
  57.210 -      else
  57.211 -        let
  57.212 -          val path' = perhaps (try Path.expand) path;
  57.213 -          val msg = "Bad file: " ^ Path.print path' ^ Position.here pos;
  57.214 -        in
  57.215 -          if strict then error msg
  57.216 -          else
  57.217 -            Context_Position.if_visible ctxt Output.report
  57.218 -              (Markup.markup (Markup.bad |> Markup.properties (Position.properties_of pos)) msg)
  57.219 -        end;
  57.220 -  in path end;
  57.221 -
  57.222 -fun file_antiq strict ctxt (name, pos) =
  57.223 -  let
  57.224 -    val dir = master_directory (Proof_Context.theory_of ctxt);
  57.225 -    val _ = check_path strict ctxt dir (name, pos);
  57.226 -  in
  57.227 -    space_explode "/" name
  57.228 -    |> map Thy_Output.verb_text
  57.229 -    |> space_implode (Thy_Output.verb_text "/" ^ "\\discretionary{}{}{}")
  57.230 -  end;
  57.231 -
  57.232 -in
  57.233 -
  57.234 -val _ = Theory.setup
  57.235 - (Thy_Output.antiquotation (Binding.name "file") (Scan.lift (Parse.position Parse.path))
  57.236 -    (file_antiq true o #context) #>
  57.237 -  Thy_Output.antiquotation (Binding.name "file_unchecked") (Scan.lift (Parse.position Parse.path))
  57.238 -    (file_antiq false o #context) #>
  57.239 -  ML_Antiquotation.value (Binding.name "path")
  57.240 -    (Args.context -- Scan.lift (Parse.position Parse.path) >> (fn (ctxt, arg) =>
  57.241 -      let val path = check_path true ctxt Path.current arg
  57.242 -      in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end)));
  57.243 -
  57.244 -end;
  57.245 -
  57.246 -end;
    58.1 --- a/src/Pure/Thy/thy_load.scala	Tue Mar 18 09:39:07 2014 -0700
    58.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.3 @@ -1,111 +0,0 @@
    58.4 -/*  Title:      Pure/Thy/thy_load.scala
    58.5 -    Author:     Makarius
    58.6 -
    58.7 -Primitives for loading theory files.
    58.8 -*/
    58.9 -
   58.10 -package isabelle
   58.11 -
   58.12 -
   58.13 -import scala.annotation.tailrec
   58.14 -
   58.15 -import java.io.{File => JFile}
   58.16 -
   58.17 -
   58.18 -object Thy_Load
   58.19 -{
   58.20 -  /* paths */
   58.21 -
   58.22 -  def thy_path(path: Path): Path = path.ext("thy")
   58.23 -
   58.24 -  def is_wellformed(str: String): Boolean =
   58.25 -    try { thy_path(Path.explode(str)); true }
   58.26 -    catch { case ERROR(_) => false }
   58.27 -}
   58.28 -
   58.29 -
   58.30 -class Thy_Load(val loaded_theories: Set[String] = Set.empty, val base_syntax: Outer_Syntax)
   58.31 -{
   58.32 -  /* document node names */
   58.33 -
   58.34 -  def node_name(raw_path: Path): Document.Node.Name =
   58.35 -  {
   58.36 -    val path = raw_path.expand
   58.37 -    val node = path.implode
   58.38 -    val theory = Thy_Header.thy_name(node).getOrElse("")
   58.39 -    val master_dir = if (theory == "") "" else path.dir.implode
   58.40 -    Document.Node.Name(node, master_dir, theory)
   58.41 -  }
   58.42 -
   58.43 -
   58.44 -  /* file-system operations */
   58.45 -
   58.46 -  def append(dir: String, source_path: Path): String =
   58.47 -    (Path.explode(dir) + source_path).expand.implode
   58.48 -
   58.49 -  def with_thy_text[A](name: Document.Node.Name, f: CharSequence => A): A =
   58.50 -  {
   58.51 -    val path = Path.explode(name.node)
   58.52 -    if (!path.is_file) error("No such file: " + path.toString)
   58.53 -
   58.54 -    val text = File.read(path)
   58.55 -    Symbol.decode_strict(text)
   58.56 -    f(text)
   58.57 -  }
   58.58 -
   58.59 -
   58.60 -  /* theory files */
   58.61 -
   58.62 -  def body_files_test(syntax: Outer_Syntax, text: String): Boolean =
   58.63 -    syntax.thy_load_commands.exists({ case (cmd, _) => text.containsSlice(cmd) })
   58.64 -
   58.65 -  def body_files(syntax: Outer_Syntax, text: String): List[String] =
   58.66 -  {
   58.67 -    val spans = Thy_Syntax.parse_spans(syntax.scan(text))
   58.68 -    spans.iterator.map(Thy_Syntax.span_files(syntax, _)).flatten.toList
   58.69 -  }
   58.70 -
   58.71 -  def import_name(master: Document.Node.Name, s: String): Document.Node.Name =
   58.72 -  {
   58.73 -    val theory = Thy_Header.base_name(s)
   58.74 -    if (loaded_theories(theory)) Document.Node.Name(theory + ".thy", "", theory)
   58.75 -    else {
   58.76 -      val path = Path.explode(s)
   58.77 -      val node = append(master.master_dir, Thy_Load.thy_path(path))
   58.78 -      val master_dir = append(master.master_dir, path.dir)
   58.79 -      Document.Node.Name(node, master_dir, theory)
   58.80 -    }
   58.81 -  }
   58.82 -
   58.83 -  def check_thy_text(name: Document.Node.Name, text: CharSequence): Document.Node.Header =
   58.84 -  {
   58.85 -    try {
   58.86 -      val header = Thy_Header.read(text)
   58.87 -
   58.88 -      val name1 = header.name
   58.89 -      if (name.theory != name1)
   58.90 -        error("Bad file name " + Thy_Load.thy_path(Path.basic(name.theory)) +
   58.91 -          " for theory " + quote(name1))
   58.92 -
   58.93 -      val imports = header.imports.map(import_name(name, _))
   58.94 -      Document.Node.Header(imports, header.keywords, Nil)
   58.95 -    }
   58.96 -    catch { case exn: Throwable => Document.Node.bad_header(Exn.message(exn)) }
   58.97 -  }
   58.98 -
   58.99 -  def check_thy(name: Document.Node.Name): Document.Node.Header =
  58.100 -    with_thy_text(name, check_thy_text(name, _))
  58.101 -
  58.102 -
  58.103 -  /* theory text edits */
  58.104 -
  58.105 -  def text_edits(
  58.106 -    reparse_limit: Int,
  58.107 -    previous: Document.Version,
  58.108 -    doc_blobs: Document.Blobs,
  58.109 -    edits: List[Document.Edit_Text]): (Boolean, List[Document.Edit_Command], Document.Version) =
  58.110 -    Thy_Syntax.text_edits(this, reparse_limit, previous, doc_blobs, edits)
  58.111 -
  58.112 -  def syntax_changed() { }
  58.113 -}
  58.114 -
    59.1 --- a/src/Pure/Thy/thy_output.ML	Tue Mar 18 09:39:07 2014 -0700
    59.2 +++ b/src/Pure/Thy/thy_output.ML	Tue Mar 18 21:02:33 2014 +0100
    59.3 @@ -151,7 +151,7 @@
    59.4  
    59.5  val antiq =
    59.6    Parse.!!!
    59.7 -    (Parse.position Parse.liberal_name -- properties -- Args.parse --| Scan.ahead Parse.eof)
    59.8 +    (Parse.position Parse.liberal_name -- properties -- Parse.args --| Scan.ahead Parse.eof)
    59.9    >> (fn ((name, props), args) => (props, Args.src name args));
   59.10  
   59.11  end;
   59.12 @@ -437,23 +437,23 @@
   59.13  (* options *)
   59.14  
   59.15  val _ = Theory.setup
   59.16 - (add_option (Binding.name "show_types") (Config.put show_types o boolean) #>
   59.17 -  add_option (Binding.name "show_sorts") (Config.put show_sorts o boolean) #>
   59.18 -  add_option (Binding.name "show_structs") (Config.put show_structs o boolean) #>
   59.19 -  add_option (Binding.name "show_question_marks") (Config.put show_question_marks o boolean) #>
   59.20 -  add_option (Binding.name "show_abbrevs") (Config.put show_abbrevs o boolean) #>
   59.21 -  add_option (Binding.name "names_long") (Config.put Name_Space.names_long o boolean) #>
   59.22 -  add_option (Binding.name "names_short") (Config.put Name_Space.names_short o boolean) #>
   59.23 -  add_option (Binding.name "names_unique") (Config.put Name_Space.names_unique o boolean) #>
   59.24 -  add_option (Binding.name "eta_contract") (Config.put Syntax_Trans.eta_contract o boolean) #>
   59.25 -  add_option (Binding.name "display") (Config.put display o boolean) #>
   59.26 -  add_option (Binding.name "break") (Config.put break o boolean) #>
   59.27 -  add_option (Binding.name "quotes") (Config.put quotes o boolean) #>
   59.28 -  add_option (Binding.name "mode") (add_wrapper o Print_Mode.with_modes o single) #>
   59.29 -  add_option (Binding.name "margin") (add_wrapper o setmp_CRITICAL Pretty.margin_default o integer) #>
   59.30 -  add_option (Binding.name "indent") (Config.put indent o integer) #>
   59.31 -  add_option (Binding.name "source") (Config.put source o boolean) #>
   59.32 -  add_option (Binding.name "goals_limit") (Config.put Goal_Display.goals_limit o integer));
   59.33 + (add_option @{binding show_types} (Config.put show_types o boolean) #>
   59.34 +  add_option @{binding show_sorts} (Config.put show_sorts o boolean) #>
   59.35 +  add_option @{binding show_structs} (Config.put show_structs o boolean) #>
   59.36 +  add_option @{binding show_question_marks} (Config.put show_question_marks o boolean) #>
   59.37 +  add_option @{binding show_abbrevs} (Config.put show_abbrevs o boolean) #>
   59.38 +  add_option @{binding names_long} (Config.put Name_Space.names_long o boolean) #>
   59.39 +  add_option @{binding names_short} (Config.put Name_Space.names_short o boolean) #>
   59.40 +  add_option @{binding names_unique} (Config.put Name_Space.names_unique o boolean) #>
   59.41 +  add_option @{binding eta_contract} (Config.put Syntax_Trans.eta_contract o boolean) #>
   59.42 +  add_option @{binding display} (Config.put display o boolean) #>
   59.43 +  add_option @{binding break} (Config.put break o boolean) #>
   59.44 +  add_option @{binding quotes} (Config.put quotes o boolean) #>
   59.45 +  add_option @{binding mode} (add_wrapper o Print_Mode.with_modes o single) #>
   59.46 +  add_option @{binding margin} (add_wrapper o setmp_CRITICAL Pretty.margin_default o integer) #>
   59.47 +  add_option @{binding indent} (Config.put indent o integer) #>
   59.48 +  add_option @{binding source} (Config.put source o boolean) #>
   59.49 +  add_option @{binding goals_limit} (Config.put Goal_Display.goals_limit o integer));
   59.50  
   59.51  
   59.52  (* basic pretty printing *)
   59.53 @@ -565,20 +565,20 @@
   59.54  in
   59.55  
   59.56  val _ = Theory.setup
   59.57 - (basic_entities_style (Binding.name "thm") (Term_Style.parse -- Attrib.thms) pretty_thm_style #>
   59.58 -  basic_entity (Binding.name "prop") (Term_Style.parse -- Args.prop) pretty_term_style #>
   59.59 -  basic_entity (Binding.name "term") (Term_Style.parse -- Args.term) pretty_term_style #>
   59.60 -  basic_entity (Binding.name "term_type") (Term_Style.parse -- Args.term) pretty_term_typ #>
   59.61 -  basic_entity (Binding.name "typeof") (Term_Style.parse -- Args.term) pretty_term_typeof #>
   59.62 -  basic_entity (Binding.name "const") (Args.const {proper = true, strict = false}) pretty_const #>
   59.63 -  basic_entity (Binding.name "abbrev") (Scan.lift Args.name_inner_syntax) pretty_abbrev #>
   59.64 -  basic_entity (Binding.name "typ") Args.typ_abbrev Syntax.pretty_typ #>
   59.65 -  basic_entity (Binding.name "class") (Scan.lift Args.name_inner_syntax) pretty_class #>
   59.66 -  basic_entity (Binding.name "type") (Scan.lift Args.name) pretty_type #>
   59.67 -  basic_entity (Binding.name "text") (Scan.lift Args.name_source_position) pretty_text_report #>
   59.68 -  basic_entities (Binding.name "prf") Attrib.thms (pretty_prf false) #>
   59.69 -  basic_entities (Binding.name "full_prf") Attrib.thms (pretty_prf true) #>
   59.70 -  basic_entity (Binding.name "theory") (Scan.lift (Parse.position Args.name)) pretty_theory);
   59.71 + (basic_entities_style @{binding thm} (Term_Style.parse -- Attrib.thms) pretty_thm_style #>
   59.72 +  basic_entity @{binding prop} (Term_Style.parse -- Args.prop) pretty_term_style #>
   59.73 +  basic_entity @{binding term} (Term_Style.parse -- Args.term) pretty_term_style #>
   59.74 +  basic_entity @{binding term_type} (Term_Style.parse -- Args.term) pretty_term_typ #>
   59.75 +  basic_entity @{binding typeof} (Term_Style.parse -- Args.term) pretty_term_typeof #>
   59.76 +  basic_entity @{binding const} (Args.const {proper = true, strict = false}) pretty_const #>
   59.77 +  basic_entity @{binding abbrev} (Scan.lift Args.name_inner_syntax) pretty_abbrev #>
   59.78 +  basic_entity @{binding typ} Args.typ_abbrev Syntax.pretty_typ #>
   59.79 +  basic_entity @{binding class} (Scan.lift Args.name_inner_syntax) pretty_class #>
   59.80 +  basic_entity @{binding type} (Scan.lift Args.name) pretty_type #>
   59.81 +  basic_entity @{binding text} (Scan.lift Args.name_source_position) pretty_text_report #>
   59.82 +  basic_entities @{binding prf} Attrib.thms (pretty_prf false) #>
   59.83 +  basic_entities @{binding full_prf} Attrib.thms (pretty_prf true) #>
   59.84 +  basic_entity @{binding theory} (Scan.lift (Parse.position Args.name)) pretty_theory);
   59.85  
   59.86  end;
   59.87  
   59.88 @@ -600,8 +600,8 @@
   59.89  in
   59.90  
   59.91  val _ = Theory.setup
   59.92 - (goal_state (Binding.name "goals") true #>
   59.93 -  goal_state (Binding.name "subgoals") false);
   59.94 + (goal_state @{binding goals} true #>
   59.95 +  goal_state @{binding subgoals} false);
   59.96  
   59.97  end;
   59.98  
   59.99 @@ -611,7 +611,7 @@
  59.100  val _ = Keyword.define ("by", NONE);  (*overlap with command category*)
  59.101  
  59.102  val _ = Theory.setup
  59.103 -  (antiquotation (Binding.name "lemma")
  59.104 +  (antiquotation @{binding lemma}
  59.105      (Scan.lift (Scan.ahead Parse.not_eof) -- Args.prop --
  59.106        Scan.lift (Parse.position (Args.$$$ "by") -- Method.parse -- Scan.option Method.parse))
  59.107      (fn {source, context = ctxt, ...} => fn ((prop_token, prop), (((_, by_pos), m1), m2)) =>
  59.108 @@ -654,18 +654,18 @@
  59.109  in
  59.110  
  59.111  val _ = Theory.setup
  59.112 - (ml_text (Binding.name "ML") (ml_enclose "fn _ => (" ");") #>
  59.113 -  ml_text (Binding.name "ML_op") (ml_enclose "fn _ => (op " ");") #>
  59.114 -  ml_text (Binding.name "ML_type") (ml_enclose "val _ = NONE : (" ") option;") #>
  59.115 -  ml_text (Binding.name "ML_structure")
  59.116 + (ml_text @{binding ML} (ml_enclose "fn _ => (" ");") #>
  59.117 +  ml_text @{binding ML_op} (ml_enclose "fn _ => (op " ");") #>
  59.118 +  ml_text @{binding ML_type} (ml_enclose "val _ = NONE : (" ") option;") #>
  59.119 +  ml_text @{binding ML_structure}
  59.120      (ml_enclose "functor XXX() = struct structure XX = " " end;") #>
  59.121  
  59.122 -  ml_text (Binding.name "ML_functor")   (* FIXME formal treatment of functor name (!?) *)
  59.123 +  ml_text @{binding ML_functor}   (* FIXME formal treatment of functor name (!?) *)
  59.124      (fn source =>
  59.125        ML_Lex.read Position.none ("ML_Env.check_functor " ^
  59.126          ML_Syntax.print_string (#1 (Symbol_Pos.source_content source)))) #>
  59.127  
  59.128 -  ml_text (Binding.name "ML_text") (K []));
  59.129 +  ml_text @{binding ML_text} (K []));
  59.130  
  59.131  end;
  59.132  
  59.133 @@ -673,7 +673,7 @@
  59.134  (* URLs *)
  59.135  
  59.136  val _ = Theory.setup
  59.137 -  (antiquotation (Binding.name "url") (Scan.lift (Parse.position Parse.name))
  59.138 +  (antiquotation @{binding url} (Scan.lift (Parse.position Parse.name))
  59.139      (fn {context = ctxt, ...} => fn (name, pos) =>
  59.140        (Context_Position.reports ctxt [(pos, Markup.language_path), (pos, Markup.url name)];
  59.141         enclose "\\url{" "}" name)));
    60.1 --- a/src/Pure/Thy/thy_syntax.scala	Tue Mar 18 09:39:07 2014 -0700
    60.2 +++ b/src/Pure/Thy/thy_syntax.scala	Tue Mar 18 21:02:33 2014 +0100
    60.3 @@ -257,7 +257,7 @@
    60.4      }
    60.5  
    60.6    def resolve_files(
    60.7 -      thy_load: Thy_Load,
    60.8 +      resources: Resources,
    60.9        syntax: Outer_Syntax,
   60.10        node_name: Document.Node.Name,
   60.11        span: List[Token],
   60.12 @@ -267,7 +267,7 @@
   60.13      span_files(syntax, span).map(file_name =>
   60.14        Exn.capture {
   60.15          val name =
   60.16 -          Document.Node.Name(thy_load.append(node_name.master_dir, Path.explode(file_name)))
   60.17 +          Document.Node.Name(resources.append(node_name.master_dir, Path.explode(file_name)))
   60.18          val blob = doc_blobs.get(name).map(blob => ((blob.bytes.sha1_digest, blob.file)))
   60.19          (name, blob)
   60.20        })
   60.21 @@ -289,7 +289,7 @@
   60.22    }
   60.23  
   60.24    private def reparse_spans(
   60.25 -    thy_load: Thy_Load,
   60.26 +    resources: Resources,
   60.27      syntax: Outer_Syntax,
   60.28      doc_blobs: Document.Blobs,
   60.29      name: Document.Node.Name,
   60.30 @@ -299,7 +299,7 @@
   60.31      val cmds0 = commands.iterator(first, last).toList
   60.32      val blobs_spans0 =
   60.33        parse_spans(syntax.scan(cmds0.iterator.map(_.source).mkString)).
   60.34 -        map(span => (resolve_files(thy_load, syntax, name, span, doc_blobs), span))
   60.35 +        map(span => (resolve_files(resources, syntax, name, span, doc_blobs), span))
   60.36  
   60.37      val (cmds1, blobs_spans1) = chop_common(cmds0, blobs_spans0)
   60.38  
   60.39 @@ -324,7 +324,7 @@
   60.40  
   60.41    // FIXME somewhat slow
   60.42    private def recover_spans(
   60.43 -    thy_load: Thy_Load,
   60.44 +    resources: Resources,
   60.45      syntax: Outer_Syntax,
   60.46      doc_blobs: Document.Blobs,
   60.47      name: Document.Node.Name,
   60.48 @@ -342,7 +342,7 @@
   60.49          case Some(first_unparsed) =>
   60.50            val first = next_invisible_command(cmds.reverse, first_unparsed)
   60.51            val last = next_invisible_command(cmds, first_unparsed)
   60.52 -          recover(reparse_spans(thy_load, syntax, doc_blobs, name, cmds, first, last))
   60.53 +          recover(reparse_spans(resources, syntax, doc_blobs, name, cmds, first, last))
   60.54          case None => cmds
   60.55        }
   60.56      recover(commands)
   60.57 @@ -352,7 +352,7 @@
   60.58    /* consolidate unfinished spans */
   60.59  
   60.60    private def consolidate_spans(
   60.61 -    thy_load: Thy_Load,
   60.62 +    resources: Resources,
   60.63      syntax: Outer_Syntax,
   60.64      doc_blobs: Document.Blobs,
   60.65      reparse_limit: Int,
   60.66 @@ -374,7 +374,7 @@
   60.67                  last = it.next
   60.68                  i += last.length
   60.69                }
   60.70 -              reparse_spans(thy_load, syntax, doc_blobs, name, commands, first_unfinished, last)
   60.71 +              reparse_spans(resources, syntax, doc_blobs, name, commands, first_unfinished, last)
   60.72              case None => commands
   60.73            }
   60.74          case None => commands
   60.75 @@ -396,7 +396,7 @@
   60.76    }
   60.77  
   60.78    private def text_edit(
   60.79 -    thy_load: Thy_Load,
   60.80 +    resources: Resources,
   60.81      syntax: Outer_Syntax,
   60.82      doc_blobs: Document.Blobs,
   60.83      reparse_limit: Int,
   60.84 @@ -413,7 +413,7 @@
   60.85            val commands0 = node.commands
   60.86            val commands1 = edit_text(text_edits, commands0)
   60.87            val commands2 =
   60.88 -            recover_spans(thy_load, syntax, doc_blobs, name, node.perspective.visible, commands1)
   60.89 +            recover_spans(resources, syntax, doc_blobs, name, node.perspective.visible, commands1)
   60.90            node.update_commands(commands2)
   60.91          }
   60.92  
   60.93 @@ -426,13 +426,13 @@
   60.94          if (node.same_perspective(perspective)) node
   60.95          else
   60.96            node.update_perspective(perspective).update_commands(
   60.97 -            consolidate_spans(thy_load, syntax, doc_blobs, reparse_limit,
   60.98 +            consolidate_spans(resources, syntax, doc_blobs, reparse_limit,
   60.99                name, visible, node.commands))
  60.100      }
  60.101    }
  60.102  
  60.103    def text_edits(
  60.104 -      thy_load: Thy_Load,
  60.105 +      resources: Resources,
  60.106        reparse_limit: Int,
  60.107        previous: Document.Version,
  60.108        doc_blobs: Document.Blobs,
  60.109 @@ -440,7 +440,7 @@
  60.110      : (Boolean, List[Document.Edit_Command], Document.Version) =
  60.111    {
  60.112      val ((syntax, syntax_changed), reparse0, nodes0, doc_edits0) =
  60.113 -      header_edits(thy_load.base_syntax, previous, edits)
  60.114 +      header_edits(resources.base_syntax, previous, edits)
  60.115  
  60.116      if (edits.isEmpty)
  60.117        (false, Nil, Document.Version.make(syntax, previous.nodes))
  60.118 @@ -469,10 +469,10 @@
  60.119            val node1 =
  60.120              if (reparse_set(name) && !commands.isEmpty)
  60.121                node.update_commands(
  60.122 -                reparse_spans(thy_load, syntax, doc_blobs,
  60.123 +                reparse_spans(resources, syntax, doc_blobs,
  60.124                    name, commands, commands.head, commands.last))
  60.125              else node
  60.126 -          val node2 = (node1 /: edits)(text_edit(thy_load, syntax, doc_blobs, reparse_limit, _, _))
  60.127 +          val node2 = (node1 /: edits)(text_edit(resources, syntax, doc_blobs, reparse_limit, _, _))
  60.128  
  60.129            if (!(node.same_perspective(node2.perspective)))
  60.130              doc_edits += (name -> node2.perspective)
    61.1 --- a/src/Pure/Tools/build.scala	Tue Mar 18 09:39:07 2014 -0700
    61.2 +++ b/src/Pure/Tools/build.scala	Tue Mar 18 21:02:33 2014 +0100
    61.3 @@ -419,8 +419,8 @@
    61.4                    val parent = deps(parent_name)
    61.5                    (parent.loaded_theories, parent.syntax)
    61.6                }
    61.7 -            val thy_load = new Thy_Load(preloaded, parent_syntax)
    61.8 -            val thy_info = new Thy_Info(thy_load)
    61.9 +            val resources = new Resources(preloaded, parent_syntax)
   61.10 +            val thy_info = new Thy_Info(resources)
   61.11  
   61.12              if (verbose || list_files) {
   61.13                val groups =
   61.14 @@ -432,7 +432,7 @@
   61.15              val thy_deps =
   61.16                thy_info.dependencies(
   61.17                  info.theories.map(_._2).flatten.
   61.18 -                  map(thy => (thy_load.node_name(info.dir + Thy_Load.thy_path(thy)), info.pos)))
   61.19 +                  map(thy => (resources.node_name(info.dir + Resources.thy_path(thy)), info.pos)))
   61.20  
   61.21              thy_deps.errors match {
   61.22                case Nil =>
    62.1 --- a/src/Pure/Tools/proof_general.ML	Tue Mar 18 09:39:07 2014 -0700
    62.2 +++ b/src/Pure/Tools/proof_general.ML	Tue Mar 18 21:02:33 2014 +0100
    62.3 @@ -337,7 +337,7 @@
    62.4        Thy_Info.register_thy (Toplevel.end_theory Position.none (Isar.state ()))
    62.5          handle ERROR msg =>
    62.6            (warning (cat_lines ["Failed to register theory: " ^ quote name, msg]);
    62.7 -            tell_file_retracted (Thy_Load.thy_path (Path.basic name)))
    62.8 +            tell_file_retracted (Resources.thy_path (Path.basic name)))
    62.9      val _ = Isar.init ();
   62.10    in () end;
   62.11  
    63.1 --- a/src/Pure/build-jars	Tue Mar 18 09:39:07 2014 -0700
    63.2 +++ b/src/Pure/build-jars	Tue Mar 18 21:02:33 2014 +0100
    63.3 @@ -53,6 +53,8 @@
    63.4    PIDE/markup_tree.scala
    63.5    PIDE/protocol.scala
    63.6    PIDE/query_operation.scala
    63.7 +  PIDE/resources.scala
    63.8 +  PIDE/session.scala
    63.9    PIDE/text.scala
   63.10    PIDE/xml.scala
   63.11    PIDE/yxml.scala
   63.12 @@ -66,14 +68,12 @@
   63.13    System/isabelle_system.scala
   63.14    System/options.scala
   63.15    System/platform.scala
   63.16 -  System/session.scala
   63.17    System/system_channel.scala
   63.18    System/utf8.scala
   63.19    Thy/html.scala
   63.20    Thy/present.scala
   63.21    Thy/thy_header.scala
   63.22    Thy/thy_info.scala
   63.23 -  Thy/thy_load.scala
   63.24    Thy/thy_syntax.scala
   63.25    Tools/build.scala
   63.26    Tools/doc.scala
    64.1 --- a/src/Pure/pure_syn.ML	Tue Mar 18 09:39:07 2014 -0700
    64.2 +++ b/src/Pure/pure_syn.ML	Tue Mar 18 21:02:33 2014 +0100
    64.3 @@ -9,8 +9,7 @@
    64.4  
    64.5  val _ =
    64.6    Outer_Syntax.command
    64.7 -    (("theory", Keyword.tag_theory Keyword.thy_begin), Position.file "pure_syn.ML")
    64.8 -    "begin theory context"
    64.9 +    (("theory", Keyword.tag_theory Keyword.thy_begin), @{here}) "begin theory"
   64.10      (Thy_Header.args >> (fn header =>
   64.11        Toplevel.print o
   64.12          Toplevel.init_theory
   64.13 @@ -18,12 +17,11 @@
   64.14  
   64.15  val _ =
   64.16    Outer_Syntax.command
   64.17 -    (("ML_file", Keyword.tag_ml Keyword.thy_load), Position.file "pure_syn.ML")
   64.18 -    "ML text from file"
   64.19 -    (Thy_Load.parse_files "ML_file" >> (fn files => Toplevel.generic_theory (fn gthy =>
   64.20 +    (("ML_file", Keyword.tag_ml Keyword.thy_load), @{here}) "ML text from file"
   64.21 +    (Resources.parse_files "ML_file" >> (fn files => Toplevel.generic_theory (fn gthy =>
   64.22          let
   64.23            val [{src_path, lines, digest, pos}] = files (Context.theory_of gthy);
   64.24 -          val provide = Thy_Load.provide (src_path, digest);
   64.25 +          val provide = Resources.provide (src_path, digest);
   64.26            val source = {delimited = true, text = cat_lines lines, pos = pos};
   64.27          in
   64.28            gthy
    65.1 --- a/src/Pure/simplifier.ML	Tue Mar 18 09:39:07 2014 -0700
    65.2 +++ b/src/Pure/simplifier.ML	Tue Mar 18 21:02:33 2014 +0100
    65.3 @@ -144,7 +144,7 @@
    65.4  val the_simproc = Name_Space.get o get_simprocs;
    65.5  
    65.6  val _ = Theory.setup
    65.7 -  (ML_Antiquotation.value (Binding.name "simproc")
    65.8 +  (ML_Antiquotation.value @{binding simproc}
    65.9      (Args.context -- Scan.lift (Parse.position Args.name)
   65.10        >> (fn (ctxt, name) =>
   65.11          "Simplifier.the_simproc ML_context " ^ ML_Syntax.print_string (check_simproc ctxt name))));
   65.12 @@ -315,13 +315,13 @@
   65.13  (* setup attributes *)
   65.14  
   65.15  val _ = Theory.setup
   65.16 - (Attrib.setup (Binding.name simpN) (Attrib.add_del simp_add simp_del)
   65.17 + (Attrib.setup @{binding simp} (Attrib.add_del simp_add simp_del)
   65.18      "declaration of Simplifier rewrite rule" #>
   65.19 -  Attrib.setup (Binding.name congN) (Attrib.add_del cong_add cong_del)
   65.20 +  Attrib.setup @{binding cong} (Attrib.add_del cong_add cong_del)
   65.21      "declaration of Simplifier congruence rule" #>
   65.22 -  Attrib.setup (Binding.name "simproc") simproc_att
   65.23 +  Attrib.setup @{binding simproc} simproc_att
   65.24      "declaration of simplification procedures" #>
   65.25 -  Attrib.setup (Binding.name "simplified") simplified "simplified rule");
   65.26 +  Attrib.setup @{binding simplified} simplified "simplified rule");
   65.27  
   65.28  
   65.29  
   65.30 @@ -362,12 +362,12 @@
   65.31  (** setup **)
   65.32  
   65.33  fun method_setup more_mods =
   65.34 -  Method.setup (Binding.name simpN)
   65.35 +  Method.setup @{binding simp}
   65.36      (simp_method more_mods (fn ctxt => fn tac => fn facts =>
   65.37        HEADGOAL (Method.insert_tac facts THEN'
   65.38          (CHANGED_PROP oo tac) ctxt)))
   65.39      "simplification" #>
   65.40 -  Method.setup (Binding.name "simp_all")
   65.41 +  Method.setup @{binding simp_all}
   65.42      (simp_method more_mods (fn ctxt => fn tac => fn facts =>
   65.43        ALLGOALS (Method.insert_tac facts) THEN
   65.44          (CHANGED_PROP o PARALLEL_GOALS o ALLGOALS o tac) ctxt))
    66.1 --- a/src/Sequents/Washing.thy	Tue Mar 18 09:39:07 2014 -0700
    66.2 +++ b/src/Sequents/Washing.thy	Tue Mar 18 21:02:33 2014 +0100
    66.3 @@ -32,10 +32,10 @@
    66.4  
    66.5  (* "activate" definitions for use in proof *)
    66.6  
    66.7 -ML {* bind_thms ("changeI", [@{thm context1}] RL ([@{thm change}] RLN (2,[@{thm cut}]))) *}
    66.8 -ML {* bind_thms ("load1I", [@{thm context1}] RL ([@{thm load1}] RLN (2,[@{thm cut}]))) *}
    66.9 -ML {* bind_thms ("washI", [@{thm context1}] RL ([@{thm wash}] RLN (2,[@{thm cut}]))) *}
   66.10 -ML {* bind_thms ("dryI", [@{thm context1}] RL ([@{thm dry}] RLN (2,[@{thm cut}]))) *}
   66.11 +ML {* ML_Thms.bind_thms ("changeI", [@{thm context1}] RL ([@{thm change}] RLN (2,[@{thm cut}]))) *}
   66.12 +ML {* ML_Thms.bind_thms ("load1I", [@{thm context1}] RL ([@{thm load1}] RLN (2,[@{thm cut}]))) *}
   66.13 +ML {* ML_Thms.bind_thms ("washI", [@{thm context1}] RL ([@{thm wash}] RLN (2,[@{thm cut}]))) *}
   66.14 +ML {* ML_Thms.bind_thms ("dryI", [@{thm context1}] RL ([@{thm dry}] RLN (2,[@{thm cut}]))) *}
   66.15  
   66.16  (* a load of dirty clothes and two dollars gives you clean clothes *)
   66.17  
    67.1 --- a/src/Tools/Code/code_runtime.ML	Tue Mar 18 09:39:07 2014 -0700
    67.2 +++ b/src/Tools/Code/code_runtime.ML	Tue Mar 18 21:02:33 2014 +0100
    67.3 @@ -325,7 +325,7 @@
    67.4        let
    67.5          val preamble =
    67.6            "(* Generated from " ^
    67.7 -            Path.implode (Thy_Load.thy_path (Path.basic (Context.theory_name thy))) ^
    67.8 +            Path.implode (Resources.thy_path (Path.basic (Context.theory_name thy))) ^
    67.9            "; DO NOT EDIT! *)";
   67.10          val _ = File.write (Path.explode file_name) (preamble ^ "\n\n" ^ code);
   67.11        in
   67.12 @@ -354,7 +354,7 @@
   67.13  (** Isar setup **)
   67.14  
   67.15  val _ =
   67.16 -  Theory.setup (ML_Context.antiquotation @{binding code} Args.term (fn _ => ml_code_antiq));
   67.17 +  Theory.setup (ML_Antiquotation.declaration @{binding code} Args.term (fn _ => ml_code_antiq));
   67.18  
   67.19  local
   67.20  
    68.1 --- a/src/Tools/Code/code_target.ML	Tue Mar 18 09:39:07 2014 -0700
    68.2 +++ b/src/Tools/Code/code_target.ML	Tue Mar 18 21:02:33 2014 +0100
    68.3 @@ -380,7 +380,8 @@
    68.4    | assert_module_name module_name = module_name;
    68.5  
    68.6  fun using_master_directory ctxt =
    68.7 -  Option.map (Path.append (File.pwd ()) o Path.append (Thy_Load.master_directory (Proof_Context.theory_of ctxt)));
    68.8 +  Option.map (Path.append (File.pwd ()) o
    68.9 +    Path.append (Resources.master_directory (Proof_Context.theory_of ctxt)));
   68.10  
   68.11  in
   68.12  
   68.13 @@ -646,7 +647,7 @@
   68.14    Parse.enum1 "|" (Parse.group (fn () => "code symbol pragma")
   68.15      (parse_symbol_pragma parse_const parse_tyco parse_class parse_classrel parse_inst parse_module));
   68.16  
   68.17 -val code_expr_argsP = Scan.optional (@{keyword "("} |-- Args.parse --| @{keyword ")"}) [];
   68.18 +val code_expr_argsP = Scan.optional (@{keyword "("} |-- Parse.args --| @{keyword ")"}) [];
   68.19  
   68.20  fun code_expr_inP all_public raw_cs =
   68.21    Scan.repeat (@{keyword "in"} |-- Parse.!!! (Parse.name
    69.1 --- a/src/Tools/jEdit/etc/options	Tue Mar 18 09:39:07 2014 -0700
    69.2 +++ b/src/Tools/jEdit/etc/options	Tue Mar 18 21:02:33 2014 +0100
    69.3 @@ -45,9 +45,6 @@
    69.4  public option jedit_completion_delay : real = 0.5
    69.5    -- "delay for completion popup (seconds)"
    69.6  
    69.7 -public option jedit_completion_dismiss_delay : real = 0.0
    69.8 -  -- "delay for dismissing obsolete completion popup (seconds)"
    69.9 -
   69.10  public option jedit_completion_immediate : bool = false
   69.11    -- "insert unique completion immediately into buffer (if delay = 0)"
   69.12  
   69.13 @@ -85,6 +82,7 @@
   69.14  option keyword2_color : string = "009966FF"
   69.15  option keyword3_color : string = "0099FFFF"
   69.16  option quasi_keyword_color : string = "9966FFFF"
   69.17 +option improper_color : string = "FF5050FF"
   69.18  option operator_color : string = "323232FF"
   69.19  option caret_invisible_color : string = "50000080"
   69.20  option completion_color : string = "0000FFFF"
    70.1 --- a/src/Tools/jEdit/lib/Tools/jedit	Tue Mar 18 09:39:07 2014 -0700
    70.2 +++ b/src/Tools/jEdit/lib/Tools/jedit	Tue Mar 18 21:02:33 2014 +0100
    70.3 @@ -27,7 +27,7 @@
    70.4    "src/jedit_editor.scala"
    70.5    "src/jedit_lib.scala"
    70.6    "src/jedit_options.scala"
    70.7 -  "src/jedit_thy_load.scala"
    70.8 +  "src/jedit_resources.scala"
    70.9    "src/monitor_dockable.scala"
   70.10    "src/output_dockable.scala"
   70.11    "src/plugin.scala"
    71.1 --- a/src/Tools/jEdit/src/completion_popup.scala	Tue Mar 18 09:39:07 2014 -0700
    71.2 +++ b/src/Tools/jEdit/src/completion_popup.scala	Tue Mar 18 21:02:33 2014 +0100
    71.3 @@ -112,7 +112,7 @@
    71.4        completion_popup match {
    71.5          case Some(completion) =>
    71.6            completion.active_range match {
    71.7 -            case Some((range, _)) if completion.isDisplayable => Some(range)
    71.8 +            case Some(range) if completion.isDisplayable => Some(range)
    71.9              case _ => None
   71.10            }
   71.11          case None => None
   71.12 @@ -236,21 +236,35 @@
   71.13  
   71.14            val items = result.items.map(new Item(_))
   71.15            val completion =
   71.16 -            new Completion_Popup(Some((range, invalidate _)), layered, loc2, font, items)
   71.17 +            new Completion_Popup(Some(range), layered, loc2, font, items)
   71.18              {
   71.19                override def complete(item: Completion.Item) {
   71.20                  PIDE.completion_history.update(item)
   71.21                  insert(item)
   71.22                }
   71.23                override def propagate(evt: KeyEvent) {
   71.24 -                JEdit_Lib.propagate_key(view, evt)
   71.25 +                if (view.getKeyEventInterceptor == inner_key_listener) {
   71.26 +                  try {
   71.27 +                    view.setKeyEventInterceptor(null)
   71.28 +                    JEdit_Lib.propagate_key(view, evt)
   71.29 +                  }
   71.30 +                  finally {
   71.31 +                    if (isDisplayable) view.setKeyEventInterceptor(inner_key_listener)
   71.32 +                  }
   71.33 +                }
   71.34                  if (evt.getID == KeyEvent.KEY_TYPED) input(evt)
   71.35                }
   71.36 -              override def refocus() { text_area.requestFocus }
   71.37 +              override def shutdown(focus: Boolean) {
   71.38 +                if (view.getKeyEventInterceptor == inner_key_listener)
   71.39 +                  view.setKeyEventInterceptor(null)
   71.40 +                if (focus) text_area.requestFocus
   71.41 +                invalidate()
   71.42 +              }
   71.43              }
   71.44            completion_popup = Some(completion)
   71.45 +          view.setKeyEventInterceptor(completion.inner_key_listener)
   71.46            invalidate()
   71.47 -          completion.show_popup()
   71.48 +          completion.show_popup(false)
   71.49          }
   71.50        }
   71.51  
   71.52 @@ -448,10 +462,10 @@
   71.53                    override def propagate(evt: KeyEvent) {
   71.54                      if (!evt.isConsumed) text_field.processKeyEvent(evt)
   71.55                    }
   71.56 -                  override def refocus() { text_field.requestFocus }
   71.57 +                  override def shutdown(focus: Boolean) { if (focus) text_field.requestFocus }
   71.58                  }
   71.59                completion_popup = Some(completion)
   71.60 -              completion.show_popup()
   71.61 +              completion.show_popup(true)
   71.62  
   71.63              case None =>
   71.64            }
   71.65 @@ -506,7 +520,7 @@
   71.66  
   71.67  
   71.68  class Completion_Popup private(
   71.69 -  val active_range: Option[(Text.Range, () => Unit)],
   71.70 +  val active_range: Option[Text.Range],
   71.71    layered: JLayeredPane,
   71.72    location: Point,
   71.73    font: Font,
   71.74 @@ -524,7 +538,7 @@
   71.75  
   71.76    def complete(item: Completion.Item) { }
   71.77    def propagate(evt: KeyEvent) { }
   71.78 -  def refocus() { }
   71.79 +  def shutdown(focus: Boolean) { }
   71.80  
   71.81  
   71.82    /* list view */
   71.83 @@ -568,7 +582,7 @@
   71.84  
   71.85    /* event handling */
   71.86  
   71.87 -  private val inner_key_listener =
   71.88 +  val inner_key_listener =
   71.89      JEdit_Lib.key_listener(
   71.90        key_pressed = (e: KeyEvent) =>
   71.91          {
   71.92 @@ -639,27 +653,16 @@
   71.93      new Popup(layered, completion, screen.relative(layered, size), size)
   71.94    }
   71.95  
   71.96 -  private def show_popup()
   71.97 +  private def show_popup(focus: Boolean)
   71.98    {
   71.99      popup.show
  71.100 -    list_view.requestFocus
  71.101 +    if (focus) list_view.requestFocus
  71.102    }
  71.103  
  71.104 -  private val hide_popup_delay =
  71.105 -    Swing_Thread.delay_last(PIDE.options.seconds("jedit_completion_dismiss_delay")) {
  71.106 -      active_range match { case Some((_, invalidate)) => invalidate() case _ => }
  71.107 -      popup.hide
  71.108 -    }
  71.109 -
  71.110    private def hide_popup()
  71.111    {
  71.112 -    if (list_view.peer.isFocusOwner) refocus()
  71.113 -
  71.114 -    if (PIDE.options.seconds("jedit_completion_dismiss_delay").is_zero) {
  71.115 -      active_range match { case Some((_, invalidate)) => invalidate() case _ => }
  71.116 -      popup.hide
  71.117 -    }
  71.118 -    else hide_popup_delay.invoke()
  71.119 +    shutdown(list_view.peer.isFocusOwner)
  71.120 +    popup.hide
  71.121    }
  71.122  }
  71.123  
    72.1 --- a/src/Tools/jEdit/src/document_model.scala	Tue Mar 18 09:39:07 2014 -0700
    72.2 +++ b/src/Tools/jEdit/src/document_model.scala	Tue Mar 18 21:02:33 2014 +0100
    72.3 @@ -70,7 +70,7 @@
    72.4      if (is_theory) {
    72.5        JEdit_Lib.buffer_lock(buffer) {
    72.6          Exn.capture {
    72.7 -          PIDE.thy_load.check_thy_text(node_name, buffer.getSegment(0, buffer.getLength))
    72.8 +          PIDE.resources.check_thy_text(node_name, buffer.getSegment(0, buffer.getLength))
    72.9          } match {
   72.10            case Exn.Res(header) => header
   72.11            case Exn.Exn(exn) => Document.Node.bad_header(Exn.message(exn))
   72.12 @@ -150,7 +150,7 @@
   72.13            _blob match {
   72.14              case Some(x) => x
   72.15              case None =>
   72.16 -              val bytes = PIDE.thy_load.file_content(buffer)
   72.17 +              val bytes = PIDE.resources.file_content(buffer)
   72.18                val file = new Command.File(node_name.node, buffer.getSegment(0, buffer.getLength))
   72.19                _blob = Some((bytes, file))
   72.20                (bytes, file)
    73.1 --- a/src/Tools/jEdit/src/find_dockable.scala	Tue Mar 18 09:39:07 2014 -0700
    73.2 +++ b/src/Tools/jEdit/src/find_dockable.scala	Tue Mar 18 21:02:33 2014 +0100
    73.3 @@ -131,7 +131,7 @@
    73.4  
    73.5    private val context_entries =
    73.6      new Context_Entry("", "current context") ::
    73.7 -      PIDE.thy_load.loaded_theories.toList.sorted.map(name => Context_Entry(name, name))
    73.8 +      PIDE.resources.loaded_theories.toList.sorted.map(name => Context_Entry(name, name))
    73.9  
   73.10    private val context = new ComboBox[Context_Entry](context_entries) {
   73.11      tooltip = "Search in pre-loaded theory (default: context of current command)"
    74.1 --- a/src/Tools/jEdit/src/isabelle_sidekick.scala	Tue Mar 18 09:39:07 2014 -0700
    74.2 +++ b/src/Tools/jEdit/src/isabelle_sidekick.scala	Tue Mar 18 21:02:33 2014 +0100
    74.3 @@ -133,7 +133,7 @@
    74.4  
    74.5  
    74.6  class Isabelle_Sidekick_Default extends
    74.7 -  Isabelle_Sidekick_Structure("isabelle", PIDE.thy_load.theory_node_name)
    74.8 +  Isabelle_Sidekick_Structure("isabelle", PIDE.resources.theory_node_name)
    74.9  
   74.10  
   74.11  class Isabelle_Sidekick_Options extends
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/src/Tools/jEdit/src/jedit_resources.scala	Tue Mar 18 21:02:33 2014 +0100
    75.3 @@ -0,0 +1,123 @@
    75.4 +/*  Title:      Tools/jEdit/src/jedit_resources.scala
    75.5 +    Author:     Makarius
    75.6 +
    75.7 +Resources for theories and auxiliary files, based on jEdit buffer
    75.8 +content and virtual file-systems.
    75.9 +*/
   75.10 +
   75.11 +package isabelle.jedit
   75.12 +
   75.13 +
   75.14 +import isabelle._
   75.15 +
   75.16 +import java.io.{File => JFile, IOException, ByteArrayOutputStream}
   75.17 +import javax.swing.text.Segment
   75.18 +
   75.19 +import org.gjt.sp.jedit.io.{VFS, FileVFS, VFSFile, VFSManager}
   75.20 +import org.gjt.sp.jedit.MiscUtilities
   75.21 +import org.gjt.sp.jedit.{jEdit, View, Buffer}
   75.22 +import org.gjt.sp.jedit.bufferio.BufferIORequest
   75.23 +
   75.24 +
   75.25 +class JEdit_Resources(loaded_theories: Set[String] = Set.empty, base_syntax: Outer_Syntax)
   75.26 +  extends Resources(loaded_theories, base_syntax)
   75.27 +{
   75.28 +  /* document node names */
   75.29 +
   75.30 +  def node_name(buffer: Buffer): Document.Node.Name =
   75.31 +  {
   75.32 +    val node = JEdit_Lib.buffer_name(buffer)
   75.33 +    val theory = Thy_Header.thy_name(node).getOrElse("")
   75.34 +    val master_dir = if (theory == "") "" else buffer.getDirectory
   75.35 +    Document.Node.Name(node, master_dir, theory)
   75.36 +  }
   75.37 +
   75.38 +  def theory_node_name(buffer: Buffer): Option[Document.Node.Name] =
   75.39 +  {
   75.40 +    val name = node_name(buffer)
   75.41 +    if (name.is_theory) Some(name) else None
   75.42 +  }
   75.43 +
   75.44 +
   75.45 +  /* file-system operations */
   75.46 +
   75.47 +  override def append(dir: String, source_path: Path): String =
   75.48 +  {
   75.49 +    val path = source_path.expand
   75.50 +    if (dir == "" || path.is_absolute) Isabelle_System.platform_path(path)
   75.51 +    else {
   75.52 +      val vfs = VFSManager.getVFSForPath(dir)
   75.53 +      if (vfs.isInstanceOf[FileVFS])
   75.54 +        MiscUtilities.resolveSymlinks(
   75.55 +          vfs.constructPath(dir, Isabelle_System.platform_path(path)))
   75.56 +      else vfs.constructPath(dir, Isabelle_System.standard_path(path))
   75.57 +    }
   75.58 +  }
   75.59 +
   75.60 +  override def with_thy_text[A](name: Document.Node.Name, f: CharSequence => A): A =
   75.61 +  {
   75.62 +    Swing_Thread.now {
   75.63 +      JEdit_Lib.jedit_buffer(name.node) match {
   75.64 +        case Some(buffer) =>
   75.65 +          JEdit_Lib.buffer_lock(buffer) {
   75.66 +            Some(f(buffer.getSegment(0, buffer.getLength)))
   75.67 +          }
   75.68 +        case None => None
   75.69 +      }
   75.70 +    } getOrElse {
   75.71 +      val file = new JFile(name.node)  // FIXME load URL via jEdit VFS (!?)
   75.72 +      if (!file.exists || !file.isFile) error("No such file: " + quote(file.toString))
   75.73 +      f(File.read(file))
   75.74 +    }
   75.75 +  }
   75.76 +
   75.77 +  def check_file(view: View, path: String): Boolean =
   75.78 +  {
   75.79 +    val vfs = VFSManager.getVFSForPath(path)
   75.80 +    val session = vfs.createVFSSession(path, view)
   75.81 +
   75.82 +    try {
   75.83 +      session != null && {
   75.84 +        try {
   75.85 +          val file = vfs._getFile(session, path, view)
   75.86 +          file != null && file.isReadable && file.getType == VFSFile.FILE
   75.87 +        }
   75.88 +        catch { case _: IOException => false }
   75.89 +      }
   75.90 +    }
   75.91 +    finally {
   75.92 +      try { vfs._endVFSSession(session, view) }
   75.93 +      catch { case _: IOException => }
   75.94 +    }
   75.95 +  }
   75.96 +
   75.97 +
   75.98 +  /* file content */
   75.99 +
  75.100 +  def file_content(buffer: Buffer): Bytes =
  75.101 +  {
  75.102 +    val path = buffer.getPath
  75.103 +    val vfs = VFSManager.getVFSForPath(path)
  75.104 +    val content =
  75.105 +      new BufferIORequest(null, buffer, null, vfs, path) {
  75.106 +        def _run() { }
  75.107 +        def apply(): Bytes =
  75.108 +        {
  75.109 +          val out =
  75.110 +            new ByteArrayOutputStream(buffer.getLength + 1) {
  75.111 +              def content(): Bytes = Bytes(this.buf, 0, this.count)
  75.112 +            }
  75.113 +          write(buffer, out)
  75.114 +          out.content()
  75.115 +        }
  75.116 +      }
  75.117 +    content()
  75.118 +  }
  75.119 +
  75.120 +
  75.121 +  /* theory text edits */
  75.122 +
  75.123 +  override def syntax_changed(): Unit =
  75.124 +    Swing_Thread.later { jEdit.propertiesChanged() }
  75.125 +}
  75.126 +
    76.1 --- a/src/Tools/jEdit/src/jedit_thy_load.scala	Tue Mar 18 09:39:07 2014 -0700
    76.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.3 @@ -1,121 +0,0 @@
    76.4 -/*  Title:      Tools/jEdit/src/jedit_thy_load.scala
    76.5 -    Author:     Makarius
    76.6 -
    76.7 -Primitives for loading theory files, based on jEdit buffer content.
    76.8 -*/
    76.9 -
   76.10 -package isabelle.jedit
   76.11 -
   76.12 -
   76.13 -import isabelle._
   76.14 -
   76.15 -import java.io.{File => JFile, IOException, ByteArrayOutputStream}
   76.16 -import javax.swing.text.Segment
   76.17 -
   76.18 -import org.gjt.sp.jedit.io.{VFS, FileVFS, VFSFile, VFSManager}
   76.19 -import org.gjt.sp.jedit.MiscUtilities
   76.20 -import org.gjt.sp.jedit.{jEdit, View, Buffer}
   76.21 -import org.gjt.sp.jedit.bufferio.BufferIORequest
   76.22 -
   76.23 -class JEdit_Thy_Load(loaded_theories: Set[String] = Set.empty, base_syntax: Outer_Syntax)
   76.24 -  extends Thy_Load(loaded_theories, base_syntax)
   76.25 -{
   76.26 -  /* document node names */
   76.27 -
   76.28 -  def node_name(buffer: Buffer): Document.Node.Name =
   76.29 -  {
   76.30 -    val node = JEdit_Lib.buffer_name(buffer)
   76.31 -    val theory = Thy_Header.thy_name(node).getOrElse("")
   76.32 -    val master_dir = if (theory == "") "" else buffer.getDirectory
   76.33 -    Document.Node.Name(node, master_dir, theory)
   76.34 -  }
   76.35 -
   76.36 -  def theory_node_name(buffer: Buffer): Option[Document.Node.Name] =
   76.37 -  {
   76.38 -    val name = node_name(buffer)
   76.39 -    if (name.is_theory) Some(name) else None
   76.40 -  }
   76.41 -
   76.42 -
   76.43 -  /* file-system operations */
   76.44 -
   76.45 -  override def append(dir: String, source_path: Path): String =
   76.46 -  {
   76.47 -    val path = source_path.expand
   76.48 -    if (dir == "" || path.is_absolute) Isabelle_System.platform_path(path)
   76.49 -    else {
   76.50 -      val vfs = VFSManager.getVFSForPath(dir)
   76.51 -      if (vfs.isInstanceOf[FileVFS])
   76.52 -        MiscUtilities.resolveSymlinks(
   76.53 -          vfs.constructPath(dir, Isabelle_System.platform_path(path)))
   76.54 -      else vfs.constructPath(dir, Isabelle_System.standard_path(path))
   76.55 -    }
   76.56 -  }
   76.57 -
   76.58 -  override def with_thy_text[A](name: Document.Node.Name, f: CharSequence => A): A =
   76.59 -  {
   76.60 -    Swing_Thread.now {
   76.61 -      JEdit_Lib.jedit_buffer(name.node) match {
   76.62 -        case Some(buffer) =>
   76.63 -          JEdit_Lib.buffer_lock(buffer) {
   76.64 -            Some(f(buffer.getSegment(0, buffer.getLength)))
   76.65 -          }
   76.66 -        case None => None
   76.67 -      }
   76.68 -    } getOrElse {
   76.69 -      val file = new JFile(name.node)  // FIXME load URL via jEdit VFS (!?)
   76.70 -      if (!file.exists || !file.isFile) error("No such file: " + quote(file.toString))
   76.71 -      f(File.read(file))
   76.72 -    }
   76.73 -  }
   76.74 -
   76.75 -  def check_file(view: View, path: String): Boolean =
   76.76 -  {
   76.77 -    val vfs = VFSManager.getVFSForPath(path)
   76.78 -    val session = vfs.createVFSSession(path, view)
   76.79 -
   76.80 -    try {
   76.81 -      session != null && {
   76.82 -        try {
   76.83 -          val file = vfs._getFile(session, path, view)
   76.84 -          file != null && file.isReadable && file.getType == VFSFile.FILE
   76.85 -        }
   76.86 -        catch { case _: IOException => false }
   76.87 -      }
   76.88 -    }
   76.89 -    finally {
   76.90 -      try { vfs._endVFSSession(session, view) }
   76.91 -      catch { case _: IOException => }
   76.92 -    }
   76.93 -  }
   76.94 -
   76.95 -
   76.96 -  /* file content */
   76.97 -
   76.98 -  def file_content(buffer: Buffer): Bytes =
   76.99 -  {
  76.100 -    val path = buffer.getPath
  76.101 -    val vfs = VFSManager.getVFSForPath(path)
  76.102 -    val content =
  76.103 -      new BufferIORequest(null, buffer, null, vfs, path) {
  76.104 -        def _run() { }
  76.105 -        def apply(): Bytes =
  76.106 -        {
  76.107 -          val out =
  76.108 -            new ByteArrayOutputStream(buffer.getLength + 1) {
  76.109 -              def content(): Bytes = Bytes(this.buf, 0, this.count)
  76.110 -            }
  76.111 -          write(buffer, out)
  76.112 -          out.content()
  76.113 -        }
  76.114 -      }
  76.115 -    content()
  76.116 -  }
  76.117 -
  76.118 -
  76.119 -  /* theory text edits */
  76.120 -
  76.121 -  override def syntax_changed(): Unit =
  76.122 -    Swing_Thread.later { jEdit.propertiesChanged() }
  76.123 -}
  76.124 -
    77.1 --- a/src/Tools/jEdit/src/plugin.scala	Tue Mar 18 09:39:07 2014 -0700
    77.2 +++ b/src/Tools/jEdit/src/plugin.scala	Tue Mar 18 21:02:33 2014 +0100
    77.3 @@ -36,12 +36,12 @@
    77.4    @volatile var startup_notified = false
    77.5  
    77.6    @volatile var plugin: Plugin = null
    77.7 -  @volatile var session: Session = new Session(new JEdit_Thy_Load(Set.empty, Outer_Syntax.empty))
    77.8 +  @volatile var session: Session = new Session(new JEdit_Resources(Set.empty, Outer_Syntax.empty))
    77.9  
   77.10    def options_changed() { plugin.options_changed() }
   77.11  
   77.12 -  def thy_load(): JEdit_Thy_Load =
   77.13 -    session.thy_load.asInstanceOf[JEdit_Thy_Load]
   77.14 +  def resources(): JEdit_Resources =
   77.15 +    session.resources.asInstanceOf[JEdit_Resources]
   77.16  
   77.17    lazy val editor = new JEdit_Editor
   77.18  
   77.19 @@ -109,7 +109,7 @@
   77.20          if buffer != null && !buffer.isLoading && !buffer.getBooleanProperty(Buffer.GZIPPED)
   77.21        } {
   77.22          JEdit_Lib.buffer_lock(buffer) {
   77.23 -          val node_name = thy_load.node_name(buffer)
   77.24 +          val node_name = resources.node_name(buffer)
   77.25            val model =
   77.26              document_model(buffer) match {
   77.27                case Some(model) if model.node_name == node_name => model
   77.28 @@ -202,10 +202,10 @@
   77.29                if model.is_theory
   77.30              } yield (model.node_name, Position.none)
   77.31  
   77.32 -          val thy_info = new Thy_Info(PIDE.thy_load)
   77.33 +          val thy_info = new Thy_Info(PIDE.resources)
   77.34            // FIXME avoid I/O in Swing thread!?!
   77.35            val files = thy_info.dependencies(thys).deps.map(_.name.node).
   77.36 -            filter(file => !loaded_buffer(file) && PIDE.thy_load.check_file(view, file))
   77.37 +            filter(file => !loaded_buffer(file) && PIDE.resources.check_file(view, file))
   77.38  
   77.39            if (!files.isEmpty) {
   77.40              if (PIDE.options.bool("jedit_auto_load")) {
   77.41 @@ -349,9 +349,9 @@
   77.42        JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.init _)
   77.43  
   77.44        val content = Isabelle_Logic.session_content(false)
   77.45 -      val thy_load = new JEdit_Thy_Load(content.loaded_theories, content.syntax)
   77.46 +      val resources = new JEdit_Resources(content.loaded_theories, content.syntax)
   77.47  
   77.48 -      PIDE.session = new Session(thy_load) {
   77.49 +      PIDE.session = new Session(resources) {
   77.50          override def output_delay = PIDE.options.seconds("editor_output_delay")
   77.51          override def reparse_limit = PIDE.options.int("editor_reparse_limit")
   77.52        }
    78.1 --- a/src/Tools/jEdit/src/rendering.scala	Tue Mar 18 09:39:07 2014 -0700
    78.2 +++ b/src/Tools/jEdit/src/rendering.scala	Tue Mar 18 21:02:33 2014 +0100
    78.3 @@ -239,6 +239,7 @@
    78.4    val keyword2_color = color_value("keyword2_color")
    78.5    val keyword3_color = color_value("keyword3_color")
    78.6    val quasi_keyword_color = color_value("quasi_keyword_color")
    78.7 +  val improper_color = color_value("improper_color")
    78.8    val operator_color = color_value("operator_color")
    78.9    val caret_invisible_color = color_value("caret_invisible_color")
   78.10    val completion_color = color_value("completion_color")
   78.11 @@ -335,7 +336,7 @@
   78.12          {
   78.13            case (links, Text.Info(info_range, XML.Elem(Markup.Path(name), _)))
   78.14            if Path.is_valid(name) =>
   78.15 -            val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
   78.16 +            val jedit_file = PIDE.resources.append(snapshot.node_name.master_dir, Path.explode(name))
   78.17              val link = PIDE.editor.hyperlink_file(jedit_file)
   78.18              Some(links :+ Text.Info(snapshot.convert(info_range), link))
   78.19  
   78.20 @@ -469,7 +470,7 @@
   78.21              Some(add(prev, r, (true, XML.Text(txt1 + txt2))))
   78.22            case (prev, Text.Info(r, XML.Elem(Markup.Path(name), _)))
   78.23            if Path.is_valid(name) =>
   78.24 -            val jedit_file = PIDE.thy_load.append(snapshot.node_name.master_dir, Path.explode(name))
   78.25 +            val jedit_file = PIDE.resources.append(snapshot.node_name.master_dir, Path.explode(name))
   78.26              val text = "path " + quote(name) + "\nfile " + quote(jedit_file)
   78.27              Some(add(prev, r, (true, XML.Text(text))))
   78.28            case (prev, Text.Info(r, XML.Elem(Markup.Url(name), _))) =>
   78.29 @@ -654,6 +655,7 @@
   78.30        Markup.KEYWORD2 -> keyword2_color,
   78.31        Markup.KEYWORD3 -> keyword3_color,
   78.32        Markup.QUASI_KEYWORD -> quasi_keyword_color,
   78.33 +      Markup.IMPROPER -> improper_color,
   78.34        Markup.OPERATOR -> operator_color,
   78.35        Markup.STRING -> Color.BLACK,
   78.36        Markup.ALTSTRING -> Color.BLACK,
    79.1 --- a/src/Tools/jEdit/src/theories_dockable.scala	Tue Mar 18 09:39:07 2014 -0700
    79.2 +++ b/src/Tools/jEdit/src/theories_dockable.scala	Tue Mar 18 21:02:33 2014 +0100
    79.3 @@ -192,7 +192,7 @@
    79.4        }).filter(_._1.is_theory)
    79.5      val nodes_status1 =
    79.6        (nodes_status /: iterator)({ case (status, (name, node)) =>
    79.7 -          if (PIDE.thy_load.loaded_theories(name.theory)) status
    79.8 +          if (PIDE.resources.loaded_theories(name.theory)) status
    79.9            else status + (name -> Protocol.node_status(snapshot.state, snapshot.version, node)) })
   79.10  
   79.11      if (nodes_status != nodes_status1) {
    80.1 --- a/src/Tools/jEdit/src/timing_dockable.scala	Tue Mar 18 09:39:07 2014 -0700
    80.2 +++ b/src/Tools/jEdit/src/timing_dockable.scala	Tue Mar 18 21:02:33 2014 +0100
    80.3 @@ -186,7 +186,7 @@
    80.4        }
    80.5      val nodes_timing1 =
    80.6        (nodes_timing /: iterator)({ case (timing1, (name, node)) =>
    80.7 -          if (PIDE.thy_load.loaded_theories(name.theory)) timing1
    80.8 +          if (PIDE.resources.loaded_theories(name.theory)) timing1
    80.9            else {
   80.10              val node_timing =
   80.11                Protocol.node_timing(snapshot.state, snapshot.version, node, timing_threshold)