--- a/src/Pure/Isar/isar_cmd.ML Sat Dec 14 22:26:27 2024 +0100
+++ b/src/Pure/Isar/isar_cmd.ML Sat Dec 14 23:48:45 2024 +0100
@@ -15,9 +15,9 @@
val print_ast_translation: Input.source -> theory -> theory
val translations: bool -> (string * string) Syntax.trrule list -> theory -> theory
val syntax_consts: ((string * Position.T) list * (xstring * Position.T) list) list ->
- theory -> theory
+ local_theory -> local_theory
val syntax_types: ((string * Position.T) list * (xstring * Position.T) list) list ->
- theory -> theory
+ local_theory -> local_theory
val oracle: bstring * Position.range -> Input.source -> theory -> theory
val declaration: {syntax: bool, pervasive: bool} -> Input.source -> local_theory -> local_theory
val qed: Method.text_range option -> Toplevel.transition -> Toplevel.transition
@@ -108,15 +108,13 @@
local
-fun syntax_deps_cmd f args thy =
+fun syntax_deps_cmd f args lthy =
let
- val ctxt = Proof_Context.init_global thy;
-
- val check_lhs = Proof_Context.check_syntax_const ctxt;
+ val check_lhs = Proof_Context.check_syntax_const lthy;
fun check_rhs (b: xstring, pos: Position.T) =
let
- val (c: string, reports) = f ctxt (b, pos);
- val _ = Context_Position.reports ctxt reports;
+ val (c: string, reports) = f lthy (b, pos);
+ val _ = Context_Position.reports lthy reports;
in c end;
fun check (raw_lhs, raw_rhs) =
@@ -124,15 +122,15 @@
val lhs = map check_lhs raw_lhs;
val rhs = map check_rhs raw_rhs;
in map (fn l => (l, rhs)) lhs end;
- in Sign.syntax_deps (maps check args) thy end;
+ in Local_Theory.syntax_deps (maps check args) lthy end;
fun check_const ctxt (s, pos) =
Proof_Context.check_const {proper = true, strict = false} ctxt (s, [pos])
- |>> (Term.dest_Const_name #> Lexicon.mark_const);
+ |>> (Term.dest_Const_name #> Lexicon.mark_const #> tap (Sign.check_syntax_dep ctxt));
fun check_type_name ctxt arg =
Proof_Context.check_type_name {proper = true, strict = false} ctxt arg
- |>> (Term.dest_Type_name #> Lexicon.mark_type);
+ |>> (Term.dest_Type_name #> Lexicon.mark_type #> tap (Sign.check_syntax_dep ctxt));
in
--- a/src/Pure/Syntax/local_syntax.ML Sat Dec 14 22:26:27 2024 +0100
+++ b/src/Pure/Syntax/local_syntax.ML Sat Dec 14 23:48:45 2024 +0100
@@ -14,6 +14,7 @@
datatype kind = Type | Const | Fixed
val add_syntax: Proof.context -> (kind * (string * typ * mixfix)) list ->
T -> {structs: string list, fixes: string list} option * T
+ val syntax_deps: Proof.context -> (string * string list) list -> T -> T
val translations: Proof.context -> bool -> Ast.ast Syntax.trrule list -> T -> T
val set_mode: Syntax.mode -> T -> T
val restore_mode: T -> T -> T
@@ -36,14 +37,15 @@
local_syntax: Syntax.syntax,
mode: Syntax.mode,
mixfixes: local_mixfix list,
+ consts: (string * string list) list,
translations: (bool * Ast.ast Syntax.trrule list) list};
-fun make_syntax (thy_syntax, local_syntax, mode, mixfixes, translations) =
+fun make_syntax (thy_syntax, local_syntax, mode, mixfixes, consts, translations) =
Syntax {thy_syntax = thy_syntax, local_syntax = local_syntax, mode = mode,
- mixfixes = mixfixes, translations = translations};
+ mixfixes = mixfixes, consts = consts, translations = translations};
-fun map_syntax f (Syntax {thy_syntax, local_syntax, mode, mixfixes, translations}) =
- make_syntax (f (thy_syntax, local_syntax, mode, mixfixes, translations));
+fun map_syntax f (Syntax {thy_syntax, local_syntax, mode, mixfixes, consts, translations}) =
+ make_syntax (f (thy_syntax, local_syntax, mode, mixfixes, consts, translations));
fun is_consistent ctxt (Syntax {thy_syntax, ...}) =
Syntax.eq_syntax (Sign.syntax_of (Proof_Context.theory_of ctxt), thy_syntax);
@@ -53,7 +55,7 @@
(* build syntax *)
-fun build_syntax ctxt mode mixfixes translations =
+fun build_syntax ctxt mode mixfixes consts translations =
let
val thy = Proof_Context.theory_of ctxt;
val thy_syntax = Sign.syntax_of thy;
@@ -64,16 +66,17 @@
val local_syntax = thy_syntax
|> fold update_gram (AList.coalesce (op =) (rev (map snd mixfixes)))
+ |> Syntax.update_consts ctxt consts
|> fold_rev (uncurry (Syntax.update_trrules ctxt)) translations;
- in make_syntax (thy_syntax, local_syntax, mode, mixfixes, translations) end;
+ in make_syntax (thy_syntax, local_syntax, mode, mixfixes, consts, translations) end;
fun init thy =
let val thy_syntax = Sign.syntax_of thy
- in make_syntax (thy_syntax, thy_syntax, Syntax.mode_default, [], []) end;
+ in make_syntax (thy_syntax, thy_syntax, Syntax.mode_default, [], [], []) end;
-fun rebuild ctxt (syntax as Syntax {mode, mixfixes, translations, ...}) =
+fun rebuild ctxt (syntax as Syntax {mode, mixfixes, consts, translations, ...}) =
if is_consistent ctxt syntax then syntax
- else build_syntax ctxt mode mixfixes translations;
+ else build_syntax ctxt mode mixfixes consts translations;
(* mixfix declarations *)
@@ -97,7 +100,7 @@
in
-fun update_syntax ctxt add raw_decls (syntax as (Syntax {mode, mixfixes, translations, ...})) =
+fun update_syntax ctxt add raw_decls (syntax as (Syntax {mode, mixfixes, consts, translations, ...})) =
(case filter_out (Mixfix.is_empty o #3 o #2) raw_decls of
[] => (NONE, syntax)
| decls =>
@@ -113,7 +116,7 @@
else subtract (op =) new_structs (#structs idents),
fixes = fold (fn ({name = x, is_fixed = true}, _) => cons x | _ => I) mixfixes' []};
- val syntax' = build_syntax ctxt mode mixfixes' translations;
+ val syntax' = build_syntax ctxt mode mixfixes' consts translations;
in (if idents = idents' then NONE else SOME idents', syntax') end);
fun add_syntax ctxt = update_syntax ctxt true;
@@ -123,14 +126,18 @@
(* translations *)
-fun translations ctxt add args (Syntax {thy_syntax, local_syntax, mode, mixfixes, translations}) =
- (Sign.check_translations ctxt args; build_syntax ctxt mode mixfixes ((add, args) :: translations));
+fun syntax_deps ctxt args (Syntax {mode, mixfixes, consts, translations, ...}) =
+ build_syntax ctxt mode mixfixes (args @ consts) translations;
+
+fun translations ctxt add args (Syntax {mode, mixfixes, consts, translations, ...}) =
+ (Sign.check_translations ctxt args;
+ build_syntax ctxt mode mixfixes consts ((add, args) :: translations));
(* syntax mode *)
-fun set_mode mode = map_syntax (fn (thy_syntax, local_syntax, _, mixfixes, translations) =>
- (thy_syntax, local_syntax, mode, mixfixes, translations));
+fun set_mode mode = map_syntax (fn (thy_syntax, local_syntax, _, mixfixes, consts, translations) =>
+ (thy_syntax, local_syntax, mode, mixfixes, consts, translations));
fun restore_mode (Syntax {mode, ...}) = set_mode mode;