src/Pure/PIDE/markup_kind.ML
author wenzelm
Sun, 12 Jan 2025 13:27:47 +0100
changeset 81776 c6d8db03dfdc
parent 81631 2d4838ffb67e
permissions -rw-r--r--
tuned headers;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
81776
c6d8db03dfdc tuned headers;
wenzelm
parents: 81631
diff changeset
     1
(*  Title:      Pure/PIDE/markup_kind.ML
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
     3
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
     4
Formally defined kind for Markup.notation and Markup.expression.
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
     5
*)
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
     6
80919
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
     7
signature MARKUP_KIND =
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
     8
sig
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
     9
  val get_notation_kinds: Proof.context -> string list
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    10
  val check_notation_kind: Proof.context -> xstring * Position.T -> string
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    11
  val setup_notation_kind: binding -> theory -> string * theory
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    12
  val check_notation: Proof.context -> xstring * Position.T -> Markup.T
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    13
  val setup_notation: binding -> Markup.T
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    14
  val get_expression_kinds: Proof.context -> string list
80919
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    15
  val check_expression_kind: Proof.context -> xstring * Position.T -> string
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    16
  val setup_expression_kind: binding -> theory -> string * theory
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    17
  val check_expression: Proof.context -> xstring * Position.T -> Markup.T
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    18
  val setup_expression: binding -> Markup.T
80941
fd7a70babec1 more markup <expression kind="item"> in Isabelle/Scala, with pro-forma Markup_Kind.setup in Isabelle/ML;
wenzelm
parents: 80923
diff changeset
    19
  val markup_item: Markup.T
81631
2d4838ffb67e more markup: for diagnostic purposes of ambig_msgs;
wenzelm
parents: 81571
diff changeset
    20
  val markup_syntax: Markup.T
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    21
  val markup_mixfix: Markup.T
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    22
  val markup_prefix: Markup.T
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    23
  val markup_postfix: Markup.T
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    24
  val markup_infix: Markup.T
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    25
  val markup_binder: Markup.T
81125
ec121999a9cb more inner-syntax markup;
wenzelm
parents: 81124
diff changeset
    26
  val markup_pattern: Markup.T
81124
6ce0c8d59f5a more inner-syntax markup, without pretty blocks;
wenzelm
parents: 81118
diff changeset
    27
  val markup_type_literal: Markup.T
81118
9e2eb05cc2b7 more inner-syntax markup;
wenzelm
parents: 80941
diff changeset
    28
  val markup_literal: Markup.T
81571
a180b070d4f8 tuned markup;
wenzelm
parents: 81125
diff changeset
    29
  val markup_index: Markup.T
80912
b2eaa342aae5 support more markup elements;
wenzelm
parents: 80902
diff changeset
    30
  val markup_type_application: Markup.T
80921
a37ed1aeb163 clarified inner syntax markup: use "notation" uniformly;
wenzelm
parents: 80920
diff changeset
    31
  val markup_application: Markup.T
a37ed1aeb163 clarified inner syntax markup: use "notation" uniformly;
wenzelm
parents: 80920
diff changeset
    32
  val markup_abstraction: Markup.T
80923
6c9628a116cc more specific markup for "judgment";
wenzelm
parents: 80921
diff changeset
    33
  val markup_judgment: Markup.T
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    34
end;
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    35
80919
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    36
structure Markup_Kind: MARKUP_KIND =
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    37
struct
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    38
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    39
(* theory data *)
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    40
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    41
structure Data = Theory_Data
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    42
(
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    43
  type T = unit Name_Space.table * unit Name_Space.table;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    44
  val empty : T =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    45
   (Name_Space.empty_table "markup_notation_kind",
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    46
    Name_Space.empty_table "markup_expression_kind");
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    47
  fun merge ((tab1, tab2), (tab1', tab2')) : T =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    48
   (Name_Space.merge_tables (tab1, tab1'),
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    49
    Name_Space.merge_tables (tab2, tab2'));
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    50
);
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    51
80902
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    52
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    53
(* kind *)
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    54
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    55
local
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    56
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    57
fun get_kinds which ctxt =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    58
  which (Data.get (Proof_Context.theory_of ctxt))
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    59
  |> Name_Space.dest_table
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    60
  |> map #1
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    61
  |> sort_strings;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    62
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    63
fun check_kind which ctxt =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    64
  Name_Space.check (Context.Proof ctxt) (which (Data.get (Proof_Context.theory_of ctxt))) #> #1;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    65
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    66
fun setup_kind which ap binding thy =
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    67
  let
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    68
    val context = Name_Space.map_naming (K Name_Space.global_naming) (Context.Theory thy);
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    69
    val (name, tab') = Name_Space.define context true (binding, ()) (which (Data.get thy));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    70
  in (name, (Data.map o ap) (K tab') thy) end;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    71
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    72
in
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    73
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    74
val get_notation_kinds = get_kinds #1;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    75
val get_expression_kinds = get_kinds #2;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    76
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    77
val check_notation_kind = check_kind #1;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    78
val check_expression_kind = check_kind #2;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    79
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    80
val setup_notation_kind = setup_kind #1 apfst;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    81
val setup_expression_kind = setup_kind #2 apsnd;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    82
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    83
end;
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    84
80902
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    85
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    86
(* markup *)
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    87
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    88
fun check_notation ctxt = check_notation_kind ctxt #> Markup.notation;
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    89
80919
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    90
fun check_expression ctxt = check_expression_kind ctxt #> Markup.expression;
80902
ac1e8686e523 more operations;
wenzelm
parents: 80889
diff changeset
    91
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    92
fun setup_notation binding =
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    93
  Context.>>> (Context.map_theory_result (setup_notation_kind binding #>> Markup.notation));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
    94
80919
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    95
fun setup_expression binding =
1a52cc1c3274 clarified modules and signature;
wenzelm
parents: 80915
diff changeset
    96
  Context.>>> (Context.map_theory_result (setup_expression_kind binding #>> Markup.expression));
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
    97
80912
b2eaa342aae5 support more markup elements;
wenzelm
parents: 80902
diff changeset
    98
b2eaa342aae5 support more markup elements;
wenzelm
parents: 80902
diff changeset
    99
(* concrete markup *)
b2eaa342aae5 support more markup elements;
wenzelm
parents: 80902
diff changeset
   100
80941
fd7a70babec1 more markup <expression kind="item"> in Isabelle/Scala, with pro-forma Markup_Kind.setup in Isabelle/ML;
wenzelm
parents: 80923
diff changeset
   101
val markup_item = setup_expression (Binding.make ("item", \<^here>));
fd7a70babec1 more markup <expression kind="item"> in Isabelle/Scala, with pro-forma Markup_Kind.setup in Isabelle/ML;
wenzelm
parents: 80923
diff changeset
   102
81631
2d4838ffb67e more markup: for diagnostic purposes of ambig_msgs;
wenzelm
parents: 81571
diff changeset
   103
val markup_syntax = setup_expression (Binding.make ("syntax", \<^here>));
2d4838ffb67e more markup: for diagnostic purposes of ambig_msgs;
wenzelm
parents: 81571
diff changeset
   104
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   105
val markup_mixfix = setup_notation (Binding.make ("mixfix", \<^here>));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   106
val markup_prefix = setup_notation (Binding.make ("prefix", \<^here>));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   107
val markup_postfix = setup_notation (Binding.make ("postfix", \<^here>));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   108
val markup_infix = setup_notation (Binding.make ("infix", \<^here>));
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   109
val markup_binder = setup_notation (Binding.make ("binder", \<^here>));
81125
ec121999a9cb more inner-syntax markup;
wenzelm
parents: 81124
diff changeset
   110
val markup_pattern = setup_notation (Binding.make ("pattern", \<^here>));
81124
6ce0c8d59f5a more inner-syntax markup, without pretty blocks;
wenzelm
parents: 81118
diff changeset
   111
val markup_type_literal = setup_notation (Binding.make ("type_literal", \<^here>));
81118
9e2eb05cc2b7 more inner-syntax markup;
wenzelm
parents: 80941
diff changeset
   112
val markup_literal = setup_notation (Binding.make ("literal", \<^here>));
81571
a180b070d4f8 tuned markup;
wenzelm
parents: 81125
diff changeset
   113
val markup_index = setup_notation (Binding.make ("index", \<^here>));
80920
bbe2c56fe255 more uniform treatment of Markup.notation and Markup.expression: manage kinds via context;
wenzelm
parents: 80919
diff changeset
   114
80921
a37ed1aeb163 clarified inner syntax markup: use "notation" uniformly;
wenzelm
parents: 80920
diff changeset
   115
val markup_type_application = setup_notation (Binding.make ("type_application", \<^here>));
a37ed1aeb163 clarified inner syntax markup: use "notation" uniformly;
wenzelm
parents: 80920
diff changeset
   116
val markup_application = setup_notation (Binding.make ("application", \<^here>));
a37ed1aeb163 clarified inner syntax markup: use "notation" uniformly;
wenzelm
parents: 80920
diff changeset
   117
val markup_abstraction = setup_notation (Binding.make ("abstraction", \<^here>));
80912
b2eaa342aae5 support more markup elements;
wenzelm
parents: 80902
diff changeset
   118
80923
6c9628a116cc more specific markup for "judgment";
wenzelm
parents: 80921
diff changeset
   119
val markup_judgment = setup_notation (Binding.make ("judgment", \<^here>));
6c9628a116cc more specific markup for "judgment";
wenzelm
parents: 80921
diff changeset
   120
80889
510f6cb6721e more formal Markup.expression;
wenzelm
parents:
diff changeset
   121
end;