src/Pure/Isar/keyword.ML
author wenzelm
Thu, 02 Aug 2012 12:36:54 +0200
changeset 48646 91281e9472d8
parent 46969 481b7d9ad6fe
child 48709 719f458cd89e
permissions -rw-r--r--
more official command specifications, including source position;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 36681
diff changeset
     1
(*  Title:      Pure/Isar/keyword.ML
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
     3
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
     4
Isar command keyword classification and global keyword tables.
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
     5
*)
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
     6
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 36681
diff changeset
     7
signature KEYWORD =
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
     8
sig
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
     9
  type T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    10
  val kind_of: T -> string
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    11
  val control: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    12
  val diag: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    13
  val thy_begin: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    14
  val thy_end: T
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    15
  val thy_heading1: T
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    16
  val thy_heading2: T
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    17
  val thy_heading3: T
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    18
  val thy_heading4: T
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    19
  val thy_decl: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    20
  val thy_script: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    21
  val thy_goal: T
36315
e859879079c8 added keyword category "schematic goal", which prevents any attempt to fork the proof;
wenzelm
parents: 34243
diff changeset
    22
  val thy_schematic_goal: T
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    23
  val qed: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    24
  val qed_block: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    25
  val qed_global: T
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    26
  val prf_heading2: T
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    27
  val prf_heading3: T
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    28
  val prf_heading4: T
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    29
  val prf_goal: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    30
  val prf_block: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    31
  val prf_open: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    32
  val prf_close: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    33
  val prf_chain: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    34
  val prf_decl: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    35
  val prf_asm: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    36
  val prf_asm_goal: T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    37
  val prf_script: T
46968
38aaa08fb37f less redundant data;
wenzelm
parents: 46967
diff changeset
    38
  val kinds: T list
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    39
  val tag: string -> T -> T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    40
  val tags_of: T -> string list
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    41
  val tag_theory: T -> T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    42
  val tag_proof: T -> T
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    43
  val tag_ml: T -> T
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    44
  type spec = string * string list
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    45
  val spec: spec -> T
48646
91281e9472d8 more official command specifications, including source position;
wenzelm
parents: 46969
diff changeset
    46
  val command_spec: (string * spec) * Position.T -> (string * T) * Position.T
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
    47
  val get_lexicons: unit -> Scan.lexicon * Scan.lexicon
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
    48
  val is_keyword: string -> bool
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
    49
  val command_keyword: string -> T option
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
    50
  val command_tags: string -> string list
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
    51
  val dest: unit -> string list * string list
38236
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
    52
  val keyword_statusN: string
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
    53
  val status: unit -> unit
46958
0ec8f04e753a define keywords early when processing the theory header, before running the body commands;
wenzelm
parents: 46957
diff changeset
    54
  val define: string * T option -> unit
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
    55
  val is_diag: string -> bool
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
    56
  val is_control: string -> bool
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
    57
  val is_regular: string -> bool
40397
4ad71312a192 added Keyword.is_heading (cf. Scala version);
wenzelm
parents: 38413
diff changeset
    58
  val is_heading: string -> bool
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
    59
  val is_theory_begin: string -> bool
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
    60
  val is_theory: string -> bool
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
    61
  val is_proof: string -> bool
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
    62
  val is_theory_goal: string -> bool
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
    63
  val is_proof_goal: string -> bool
36315
e859879079c8 added keyword category "schematic goal", which prevents any attempt to fork the proof;
wenzelm
parents: 34243
diff changeset
    64
  val is_schematic_goal: string -> bool
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
    65
  val is_qed: string -> bool
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
    66
  val is_qed_global: string -> bool
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    67
end;
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    68
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 36681
diff changeset
    69
structure Keyword: KEYWORD =
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    70
struct
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    71
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
    72
(** keyword classification **)
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    73
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    74
datatype T = Keyword of string * string list;  (*kind, tags (in canonical reverse order)*)
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    75
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    76
fun kind s = Keyword (s, []);
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    77
fun kind_of (Keyword (s, _)) = s;
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    78
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    79
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    80
(* kinds *)
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    81
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    82
val control = kind "control";
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    83
val diag = kind "diag";
46967
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    84
val thy_begin = kind "thy_begin";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    85
val thy_end = kind "thy_end";
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    86
val thy_heading1 = kind "thy_heading1";
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    87
val thy_heading2 = kind "thy_heading2";
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    88
val thy_heading3 = kind "thy_heading3";
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    89
val thy_heading4 = kind "thy_heading4";
46967
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    90
val thy_decl = kind "thy_decl";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    91
val thy_script = kind "thy_script";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    92
val thy_goal = kind "thy_goal";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    93
val thy_schematic_goal = kind "thy_schematic_goal";
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    94
val qed = kind "qed";
46967
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    95
val qed_block = kind "qed_block";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
    96
val qed_global = kind "qed_global";
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    97
val prf_heading2 = kind "prf_heading2";
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    98
val prf_heading3 = kind "prf_heading3";
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
    99
val prf_heading4 = kind "prf_heading4";
46967
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   100
val prf_goal = kind "prf_goal";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   101
val prf_block = kind "prf_block";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   102
val prf_open = kind "prf_open";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   103
val prf_close = kind "prf_close";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   104
val prf_chain = kind "prf_chain";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   105
val prf_decl = kind "prf_decl";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   106
val prf_asm = kind "prf_asm";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   107
val prf_asm_goal = kind "prf_asm_goal";
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   108
val prf_script = kind "prf_script";
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   109
36315
e859879079c8 added keyword category "schematic goal", which prevents any attempt to fork the proof;
wenzelm
parents: 34243
diff changeset
   110
val kinds =
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   111
  [control, diag, thy_begin, thy_end, thy_heading1, thy_heading2, thy_heading3, thy_heading4,
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   112
    thy_decl, thy_script, thy_goal, thy_schematic_goal, qed, qed_block, qed_global,
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   113
    prf_heading2, prf_heading3, prf_heading4, prf_goal, prf_block, prf_open,
46968
38aaa08fb37f less redundant data;
wenzelm
parents: 46967
diff changeset
   114
    prf_close, prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script];
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   115
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   116
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   117
(* tags *)
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   118
46924
wenzelm
parents: 46774
diff changeset
   119
fun tag t (Keyword (s, ts)) = Keyword (s, update (op =) t ts);
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   120
fun tags_of (Keyword (_, ts)) = ts;
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   121
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   122
val tag_theory = tag "theory";
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   123
val tag_proof = tag "proof";
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   124
val tag_ml = tag "ML";
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   125
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   126
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   127
(* external names *)
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   128
46968
38aaa08fb37f less redundant data;
wenzelm
parents: 46967
diff changeset
   129
val name_table = Symtab.make (map (`kind_of) kinds);
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   130
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   131
type spec = string * string list;
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   132
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   133
fun spec (kind, tags) =
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   134
  (case Symtab.lookup name_table kind of
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   135
    SOME k => k |> fold tag tags
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   136
  | NONE => error ("Unknown outer syntax keyword kind " ^ quote kind));
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   137
48646
91281e9472d8 more official command specifications, including source position;
wenzelm
parents: 46969
diff changeset
   138
fun command_spec ((name, s), pos) = ((name, spec s), pos);
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   139
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   140
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   141
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   142
(** global keyword tables **)
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   143
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   144
type keywords =
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   145
 {lexicons: Scan.lexicon * Scan.lexicon,  (*minor, major*)
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   146
  commands: T Symtab.table};  (*command classification*)
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   147
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   148
fun make_keywords (lexicons, commands) : keywords =
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   149
  {lexicons = lexicons, commands = commands};
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   150
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   151
local
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   152
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   153
val global_keywords =
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   154
  Unsynchronized.ref (make_keywords ((Scan.empty_lexicon, Scan.empty_lexicon), Symtab.empty));
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   155
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   156
in
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   157
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   158
fun get_keywords () = ! global_keywords;
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   159
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   160
fun change_keywords f = CRITICAL (fn () =>
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   161
  Unsynchronized.change global_keywords
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   162
    (fn {lexicons, commands} => make_keywords (f (lexicons, commands))));
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   163
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   164
end;
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   165
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   166
fun get_lexicons () = #lexicons (get_keywords ());
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   167
fun get_commands () = #commands (get_keywords ());
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   168
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   169
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   170
(* lookup *)
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   171
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   172
fun is_keyword s =
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   173
  let
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   174
    val (minor, major) = get_lexicons ();
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   175
    val syms = Symbol.explode s;
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   176
  in Scan.is_literal minor syms orelse Scan.is_literal major syms end;
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   177
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   178
fun command_keyword name = Symtab.lookup (get_commands ()) name;
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   179
fun command_tags name = these (Option.map tags_of (command_keyword name));
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   180
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   181
fun dest () = pairself (sort_strings o Scan.dest_lexicon) (get_lexicons ());
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   182
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   183
38236
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
   184
(* status *)
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   185
38236
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
   186
val keyword_statusN = "keyword_status";
34243
8821e3293702 report keywords as singleton messages, control message kind via print mode;
wenzelm
parents: 33223
diff changeset
   187
46123
aa5c367ee579 prefer raw_message for protocol implementation;
wenzelm
parents: 45666
diff changeset
   188
fun status_message m s =
38413
224efb14f258 Keyword.status: always suppress position;
wenzelm
parents: 38236
diff changeset
   189
  Position.setmp_thread_data Position.none
46774
38f113b052b1 clarified terminology of raw protocol messages;
wenzelm
parents: 46123
diff changeset
   190
    (if print_mode_active keyword_statusN then Output.protocol_message m else writeln) s;
34243
8821e3293702 report keywords as singleton messages, control message kind via print mode;
wenzelm
parents: 33223
diff changeset
   191
38236
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
   192
fun keyword_status name =
46123
aa5c367ee579 prefer raw_message for protocol implementation;
wenzelm
parents: 45666
diff changeset
   193
  status_message (Isabelle_Markup.keyword_decl name)
46967
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   194
    ("Outer syntax keyword " ^ quote name);
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   195
38236
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
   196
fun command_status (name, kind) =
46123
aa5c367ee579 prefer raw_message for protocol implementation;
wenzelm
parents: 45666
diff changeset
   197
  status_message (Isabelle_Markup.command_decl name (kind_of kind))
46967
499d9bbd8de9 uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents: 46961
diff changeset
   198
    ("Outer syntax keyword " ^ quote name ^ " :: " ^ kind_of kind);
30670
9bb872667af6 suppress status output for traditional tty modes (including Proof General);
wenzelm
parents: 29347
diff changeset
   199
38236
d8c7be27e01d explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents: 36955
diff changeset
   200
fun status () =
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   201
  let
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   202
    val {lexicons = (minor, _), commands} = get_keywords ();
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   203
    val _ = List.app keyword_status (sort_strings (Scan.dest_lexicon minor));
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   204
    val _ = List.app command_status (sort_wrt #1 (Symtab.dest commands));
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   205
  in () end;
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   206
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   207
46958
0ec8f04e753a define keywords early when processing the theory header, before running the body commands;
wenzelm
parents: 46957
diff changeset
   208
(* define *)
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   209
46958
0ec8f04e753a define keywords early when processing the theory header, before running the body commands;
wenzelm
parents: 46957
diff changeset
   210
fun define (name, NONE) =
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   211
     (change_keywords (fn ((minor, major), commands) =>
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   212
        let
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   213
          val minor' = Scan.extend_lexicon (Symbol.explode name) minor;
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   214
        in ((minor', major), commands) end);
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   215
      keyword_status name)
46958
0ec8f04e753a define keywords early when processing the theory header, before running the body commands;
wenzelm
parents: 46957
diff changeset
   216
  | define (name, SOME kind) =
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   217
     (change_keywords (fn ((minor, major), commands) =>
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   218
        let
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   219
          val major' = Scan.extend_lexicon (Symbol.explode name) major;
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   220
          val commands' = Symtab.update (name, kind) commands;
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   221
        in ((minor, major'), commands') end);
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   222
      command_status (name, kind));
46945
26007caf6e9c declare keywords as side-effect of header edit;
wenzelm
parents: 46938
diff changeset
   223
27433
b82c12e57e79 added datatype category;
wenzelm
parents: 27357
diff changeset
   224
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   225
(* command categories *)
27433
b82c12e57e79 added datatype category;
wenzelm
parents: 27357
diff changeset
   226
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   227
fun command_category ks name =
27433
b82c12e57e79 added datatype category;
wenzelm
parents: 27357
diff changeset
   228
  (case command_keyword name of
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   229
    NONE => false
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   230
  | SOME k => member (op = o pairself kind_of) ks k);
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   231
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   232
val is_diag = command_category [diag];
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   233
val is_control = command_category [control];
40397
4ad71312a192 added Keyword.is_heading (cf. Scala version);
wenzelm
parents: 38413
diff changeset
   234
val is_regular = not o command_category [diag, control];
4ad71312a192 added Keyword.is_heading (cf. Scala version);
wenzelm
parents: 38413
diff changeset
   235
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   236
val is_heading =
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   237
  command_category [thy_heading1, thy_heading2, thy_heading3, thy_heading4,
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   238
    prf_heading2, prf_heading3, prf_heading4];
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   239
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   240
val is_theory_begin = command_category [thy_begin];
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   241
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   242
val is_theory = command_category
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   243
  [thy_begin, thy_end, thy_heading1, thy_heading2, thy_heading3, thy_heading4,
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   244
    thy_decl, thy_script, thy_goal, thy_schematic_goal];
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   245
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   246
val is_proof = command_category
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   247
  [qed, qed_block, qed_global, prf_heading2, prf_heading3, prf_heading4,
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   248
    prf_goal, prf_block, prf_open, prf_close, prf_chain, prf_decl,
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46968
diff changeset
   249
    prf_asm, prf_asm_goal, prf_script];
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   250
36315
e859879079c8 added keyword category "schematic goal", which prevents any attempt to fork the proof;
wenzelm
parents: 34243
diff changeset
   251
val is_theory_goal = command_category [thy_goal, thy_schematic_goal];
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   252
val is_proof_goal = command_category [prf_goal, prf_asm_goal];
36315
e859879079c8 added keyword category "schematic goal", which prevents any attempt to fork the proof;
wenzelm
parents: 34243
diff changeset
   253
val is_schematic_goal = command_category [thy_schematic_goal];
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   254
val is_qed = command_category [qed, qed_block];
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   255
val is_qed_global = command_category [qed_global];
27520
fb07f3b32863 added is_diag;
wenzelm
parents: 27440
diff changeset
   256
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   257
end;
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 36681
diff changeset
   258