src/Pure/Isar/keyword.ML
author wenzelm
Sat, 01 Jun 2019 11:29:59 +0200
changeset 70299 83774d669b51
parent 69913 ca515cf61651
child 72747 5f9d66155081
permissions -rw-r--r--
Added tag Isabelle2019-RC4 for changeset ad2d84c42380
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
58900
1435cc20b022 explicit type Keyword.Keywords;
wenzelm
parents: 58868
diff changeset
     4
Isar keyword classification.
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
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
     9
  val diag: string
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    10
  val document_heading: string
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    11
  val document_body: string
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    12
  val document_raw: string
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    13
  val thy_begin: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    14
  val thy_end: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    15
  val thy_decl: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    16
  val thy_decl_block: string
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
    17
  val thy_defn: string
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
    18
  val thy_stmt: string
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    19
  val thy_load: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    20
  val thy_goal: string
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
    21
  val thy_goal_defn: string
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
    22
  val thy_goal_stmt: string
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    23
  val qed: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    24
  val qed_script: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    25
  val qed_block: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    26
  val qed_global: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    27
  val prf_goal: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    28
  val prf_block: string
60694
b3fa4a8cdb5f clarified text folds: proof ... qed counts as extra block;
wenzelm
parents: 60693
diff changeset
    29
  val next_block: string
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    30
  val prf_open: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    31
  val prf_close: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    32
  val prf_chain: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    33
  val prf_decl: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    34
  val prf_asm: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    35
  val prf_asm_goal: string
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    36
  val prf_script: string
60624
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
    37
  val prf_script_goal: string
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
    38
  val prf_script_asm_goal: string
63441
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63430
diff changeset
    39
  val before_command: string
63430
9c5fcd355a2d support for quasi_command keywords;
wenzelm
parents: 63429
diff changeset
    40
  val quasi_command: string
48864
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48709
diff changeset
    41
  type spec = (string * string list) * string list
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
    42
  val no_spec: spec
63441
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63430
diff changeset
    43
  val before_command_spec: spec
63430
9c5fcd355a2d support for quasi_command keywords;
wenzelm
parents: 63429
diff changeset
    44
  val quasi_command_spec: spec
67139
8fe0aba577af explicit tag for document commands: avoid implicit use of document_tags;
wenzelm
parents: 63441
diff changeset
    45
  val document_heading_spec: spec
8fe0aba577af explicit tag for document commands: avoid implicit use of document_tags;
wenzelm
parents: 63441
diff changeset
    46
  val document_body_spec: spec
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
    47
  type keywords
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
    48
  val minor_keywords: keywords -> Scan.lexicon
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
    49
  val major_keywords: keywords -> Scan.lexicon
58920
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
    50
  val no_command_keywords: keywords -> keywords
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
    51
  val empty_keywords: keywords
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
    52
  val merge_keywords: keywords * keywords -> keywords
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
    53
  val add_keywords: ((string * Position.T) * spec) list -> keywords -> keywords
58931
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
    54
  val is_keyword: keywords -> string -> bool
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
    55
  val is_command: keywords -> string -> bool
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    56
  val is_literal: keywords -> string -> bool
61618
27af754f50ca more thorough check_command, including completion;
wenzelm
parents: 60694
diff changeset
    57
  val dest_commands: keywords -> string list
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
    58
  val command_markup: keywords -> string -> Markup.T option
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
    59
  val command_kind: keywords -> string -> string option
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    60
  val command_files: keywords -> string -> Path.T -> Path.T list
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    61
  val command_tags: keywords -> string -> string list
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    62
  val is_vacuous: keywords -> string -> bool
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    63
  val is_diag: keywords -> string -> bool
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    64
  val is_document_heading: keywords -> string -> bool
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    65
  val is_document_body: keywords -> string -> bool
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    66
  val is_document_raw: keywords -> string -> bool
59033
9d5662acb19c tuned signature;
wenzelm
parents: 58999
diff changeset
    67
  val is_document: keywords -> string -> bool
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59123
diff changeset
    68
  val is_theory_end: keywords -> string -> bool
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    69
  val is_theory_load: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    70
  val is_theory: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    71
  val is_theory_body: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    72
  val is_proof: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    73
  val is_proof_body: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    74
  val is_theory_goal: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    75
  val is_proof_goal: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    76
  val is_qed: keywords -> string -> bool
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    77
  val is_qed_global: keywords -> string -> bool
60693
044f8bb3dd30 more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents: 60624
diff changeset
    78
  val is_proof_open: keywords -> string -> bool
044f8bb3dd30 more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents: 60624
diff changeset
    79
  val is_proof_close: keywords -> string -> bool
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59123
diff changeset
    80
  val is_proof_asm: keywords -> string -> bool
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59123
diff changeset
    81
  val is_improper: keywords -> string -> bool
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
    82
  val is_printed: keywords -> string -> bool
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    83
end;
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    84
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
    85
structure Keyword: KEYWORD =
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    86
struct
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    87
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
    88
(** keyword classification **)
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
    89
58918
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58906
diff changeset
    90
(* kinds *)
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58906
diff changeset
    91
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    92
val diag = "diag";
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    93
val document_heading = "document_heading";
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    94
val document_body = "document_body";
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
    95
val document_raw = "document_raw";
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    96
val thy_begin = "thy_begin";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    97
val thy_end = "thy_end";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    98
val thy_decl = "thy_decl";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    99
val thy_decl_block = "thy_decl_block";
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   100
val thy_defn = "thy_defn";
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   101
val thy_stmt = "thy_stmt";
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   102
val thy_load = "thy_load";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   103
val thy_goal = "thy_goal";
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   104
val thy_goal_defn = "thy_goal_defn";
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   105
val thy_goal_stmt = "thy_goal_stmt";
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   106
val qed = "qed";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   107
val qed_script = "qed_script";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   108
val qed_block = "qed_block";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   109
val qed_global = "qed_global";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   110
val prf_goal = "prf_goal";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   111
val prf_block = "prf_block";
60694
b3fa4a8cdb5f clarified text folds: proof ... qed counts as extra block;
wenzelm
parents: 60693
diff changeset
   112
val next_block = "next_block";
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   113
val prf_open = "prf_open";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   114
val prf_close = "prf_close";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   115
val prf_chain = "prf_chain";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   116
val prf_decl = "prf_decl";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   117
val prf_asm = "prf_asm";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   118
val prf_asm_goal = "prf_asm_goal";
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   119
val prf_script = "prf_script";
60624
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
   120
val prf_script_goal = "prf_script_goal";
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
   121
val prf_script_asm_goal = "prf_script_asm_goal";
63441
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63430
diff changeset
   122
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63430
diff changeset
   123
val before_command = "before_command";
63430
9c5fcd355a2d support for quasi_command keywords;
wenzelm
parents: 63429
diff changeset
   124
val quasi_command = "quasi_command";
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   125
63430
9c5fcd355a2d support for quasi_command keywords;
wenzelm
parents: 63429
diff changeset
   126
val command_kinds =
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   127
  [diag, document_heading, document_body, document_raw, thy_begin, thy_end, thy_load, thy_decl,
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   128
    thy_decl_block, thy_defn, thy_stmt, thy_goal, thy_goal_defn, thy_goal_stmt, qed, qed_script,
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   129
    qed_block, qed_global, prf_goal, prf_block, next_block, prf_open, prf_close, prf_chain,
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   130
    prf_decl, prf_asm, prf_asm_goal, prf_script, prf_script_goal, prf_script_asm_goal];
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   131
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   132
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   133
(* specifications *)
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   134
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   135
type spec = (string * string list) * string list;
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   136
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   137
val no_spec: spec = (("", []), []);
63441
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63430
diff changeset
   138
val before_command_spec: spec = ((before_command, []), []);
63430
9c5fcd355a2d support for quasi_command keywords;
wenzelm
parents: 63429
diff changeset
   139
val quasi_command_spec: spec = ((quasi_command, []), []);
67139
8fe0aba577af explicit tag for document commands: avoid implicit use of document_tags;
wenzelm
parents: 63441
diff changeset
   140
val document_heading_spec: spec = (("document_heading", []), ["document"]);
8fe0aba577af explicit tag for document commands: avoid implicit use of document_tags;
wenzelm
parents: 63441
diff changeset
   141
val document_body_spec: spec = (("document_body", []), ["document"]);
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   142
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   143
type entry =
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   144
 {pos: Position.T,
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   145
  id: serial,
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   146
  kind: string,
48864
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48709
diff changeset
   147
  files: string list,  (*extensions of embedded files*)
58918
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58906
diff changeset
   148
  tags: string list};
17059
a001a3ebfcfd Isar command keyword classification (from Isar/outer_syntax.ML);
wenzelm
parents:
diff changeset
   149
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   150
fun check_spec pos ((kind, files), tags) : entry =
63430
9c5fcd355a2d support for quasi_command keywords;
wenzelm
parents: 63429
diff changeset
   151
  if not (member (op =) command_kinds kind) then
58918
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58906
diff changeset
   152
    error ("Unknown outer syntax keyword kind " ^ quote kind)
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   153
  else if not (null files) andalso kind <> thy_load then
58918
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58906
diff changeset
   154
    error ("Illegal specification of files for " ^ quote kind)
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   155
  else {pos = pos, id = serial (), kind = kind, files = files, tags = tags};
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   156
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46924
diff changeset
   157
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   158
(** keyword tables **)
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   159
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   160
(* type keywords *)
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   161
48874
ff9cd47be39b refined Thy_Load.check_thy: find more uses in body text, based on keywords;
wenzelm
parents: 48872
diff changeset
   162
datatype keywords = Keywords of
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   163
 {minor: Scan.lexicon,
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   164
  major: Scan.lexicon,
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   165
  commands: entry Symtab.table};
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   166
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   167
fun minor_keywords (Keywords {minor, ...}) = minor;
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   168
fun major_keywords (Keywords {major, ...}) = major;
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   169
58906
wenzelm
parents: 58903
diff changeset
   170
fun make_keywords (minor, major, commands) =
wenzelm
parents: 58903
diff changeset
   171
  Keywords {minor = minor, major = major, commands = commands};
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   172
58906
wenzelm
parents: 58903
diff changeset
   173
fun map_keywords f (Keywords {minor, major, commands}) =
wenzelm
parents: 58903
diff changeset
   174
  make_keywords (f (minor, major, commands));
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   175
58920
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
   176
val no_command_keywords =
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
   177
  map_keywords (fn (minor, _, _) => (minor, Scan.empty_lexicon, Symtab.empty));
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
   178
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
   179
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
   180
(* build keywords *)
2f8168dc0eac tuned signature;
wenzelm
parents: 58919
diff changeset
   181
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   182
val empty_keywords =
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   183
  make_keywords (Scan.empty_lexicon, Scan.empty_lexicon, Symtab.empty);
48874
ff9cd47be39b refined Thy_Load.check_thy: find more uses in body text, based on keywords;
wenzelm
parents: 48872
diff changeset
   184
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   185
fun merge_keywords
58906
wenzelm
parents: 58903
diff changeset
   186
  (Keywords {minor = minor1, major = major1, commands = commands1},
wenzelm
parents: 58903
diff changeset
   187
    Keywords {minor = minor2, major = major2, commands = commands2}) =
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   188
  make_keywords
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   189
   (Scan.merge_lexicons (minor1, minor2),
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   190
    Scan.merge_lexicons (major1, major2),
58906
wenzelm
parents: 58903
diff changeset
   191
    Symtab.merge (K true) (commands1, commands2));
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   192
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   193
val add_keywords =
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   194
  fold (fn ((name, pos), spec as ((kind, _), _)) => map_keywords (fn (minor, major, commands) =>
63441
4c3fa4dba79f explicit kind "before_command";
wenzelm
parents: 63430
diff changeset
   195
    if kind = "" orelse kind = before_command orelse kind = quasi_command then
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   196
      let
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   197
        val minor' = Scan.extend_lexicon (Symbol.explode name) minor;
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   198
      in (minor', major, commands) end
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   199
    else
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   200
      let
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   201
        val entry = check_spec pos spec;
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   202
        val major' = Scan.extend_lexicon (Symbol.explode name) major;
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   203
        val commands' = Symtab.update (name, entry) commands;
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 61618
diff changeset
   204
      in (minor, major', commands') end));
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   205
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58900
diff changeset
   206
58931
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
   207
(* keyword status *)
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   208
58931
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
   209
fun is_keyword keywords s = Scan.is_literal (minor_keywords keywords) (Symbol.explode s);
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
   210
fun is_command (Keywords {commands, ...}) = Symtab.defined commands;
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
   211
fun is_literal keywords = is_keyword keywords orf is_command keywords;
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   212
61618
27af754f50ca more thorough check_command, including completion;
wenzelm
parents: 60694
diff changeset
   213
fun dest_commands (Keywords {commands, ...}) = Symtab.keys commands;
27af754f50ca more thorough check_command, including completion;
wenzelm
parents: 60694
diff changeset
   214
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   215
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   216
(* command keywords *)
58931
3097ec653547 clarified keyword categories;
wenzelm
parents: 58928
diff changeset
   217
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
   218
fun lookup_command (Keywords {commands, ...}) = Symtab.lookup commands;
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
   219
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   220
fun command_markup keywords name =
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   221
  lookup_command keywords name
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   222
  |> Option.map (fn {pos, id, ...} =>
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   223
      Markup.properties (Position.entity_properties_of false id pos)
59935
343905de27b1 clarified command keyword markup;
wenzelm
parents: 59934
diff changeset
   224
        (Markup.entity Markup.command_keywordN name));
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   225
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
   226
fun command_kind keywords = Option.map #kind o lookup_command keywords;
54523
11087efad95e more uniform handling of inlined files;
wenzelm
parents: 53571
diff changeset
   227
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   228
fun command_files keywords name path =
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
   229
  (case lookup_command keywords name of
54523
11087efad95e more uniform handling of inlined files;
wenzelm
parents: 53571
diff changeset
   230
    NONE => []
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   231
  | SOME {kind, files, ...} =>
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   232
      if kind <> thy_load then []
54523
11087efad95e more uniform handling of inlined files;
wenzelm
parents: 53571
diff changeset
   233
      else if null files then [path]
11087efad95e more uniform handling of inlined files;
wenzelm
parents: 53571
diff changeset
   234
      else map (fn ext => Path.ext ext path) files);
11087efad95e more uniform handling of inlined files;
wenzelm
parents: 53571
diff changeset
   235
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   236
fun command_tags keywords name =
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
   237
  (case lookup_command keywords name of
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   238
    SOME {tags, ...} => tags
58918
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58906
diff changeset
   239
  | NONE => []);
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   240
27433
b82c12e57e79 added datatype category;
wenzelm
parents: 27357
diff changeset
   241
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   242
(* command categories *)
27433
b82c12e57e79 added datatype category;
wenzelm
parents: 27357
diff changeset
   243
51225
3fe0d8d55975 support nested Thy_Syntax.element;
wenzelm
parents: 50714
diff changeset
   244
fun command_category ks =
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   245
  let
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   246
    val tab = Symtab.make_set ks;
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   247
    fun pred keywords name =
59123
e68e44836d04 imitate command markup and rendering of Isabelle/jEdit in HTML output;
wenzelm
parents: 59033
diff changeset
   248
      (case lookup_command keywords name of
51225
3fe0d8d55975 support nested Thy_Syntax.element;
wenzelm
parents: 50714
diff changeset
   249
        NONE => false
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   250
      | SOME {kind, ...} => Symtab.defined tab kind);
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   251
  in pred end;
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   252
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   253
val is_vacuous = command_category [diag, document_heading, document_body, document_raw];
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   254
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   255
val is_diag = command_category [diag];
40397
4ad71312a192 added Keyword.is_heading (cf. Scala version);
wenzelm
parents: 38413
diff changeset
   256
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   257
val is_document_heading = command_category [document_heading];
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   258
val is_document_body = command_category [document_body];
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   259
val is_document_raw = command_category [document_raw];
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58931
diff changeset
   260
val is_document = command_category [document_heading, document_body, document_raw];
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   261
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59123
diff changeset
   262
val is_theory_end = command_category [thy_end];
29347
b723fa577aa2 added is_control, is_regular, is_theory_begin;
wenzelm
parents: 28542
diff changeset
   263
48867
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48864
diff changeset
   264
val is_theory_load = command_category [thy_load];
e9beabf045ab some support for inlining file content into outer syntax token language;
wenzelm
parents: 48864
diff changeset
   265
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   266
val is_theory = command_category
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   267
  [thy_begin, thy_end, thy_load, thy_decl, thy_decl_block, thy_defn, thy_stmt, thy_goal,
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   268
    thy_goal_defn, thy_goal_stmt];
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   269
56944
578dc6b4be89 no reset for 'end' -- e.g. relevant for 'notepad';
wenzelm
parents: 56895
diff changeset
   270
val is_theory_body = command_category
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   271
  [thy_load, thy_decl, thy_decl_block, thy_defn, thy_stmt, thy_goal, thy_goal_defn, thy_goal_stmt];
56944
578dc6b4be89 no reset for 'end' -- e.g. relevant for 'notepad';
wenzelm
parents: 56895
diff changeset
   272
27440
a1eda23752bd replaced datatype category constructivism by is_theory/is_proof;
wenzelm
parents: 27433
diff changeset
   273
val is_proof = command_category
60694
b3fa4a8cdb5f clarified text folds: proof ... qed counts as extra block;
wenzelm
parents: 60693
diff changeset
   274
  [qed, qed_script, qed_block, qed_global, prf_goal, prf_block, next_block, prf_open,
b3fa4a8cdb5f clarified text folds: proof ... qed counts as extra block;
wenzelm
parents: 60693
diff changeset
   275
    prf_close, prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script, prf_script_goal,
60624
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
   276
    prf_script_asm_goal];
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   277
51225
3fe0d8d55975 support nested Thy_Syntax.element;
wenzelm
parents: 50714
diff changeset
   278
val is_proof_body = command_category
60694
b3fa4a8cdb5f clarified text folds: proof ... qed counts as extra block;
wenzelm
parents: 60693
diff changeset
   279
  [diag, document_heading, document_body, document_raw, prf_block, next_block, prf_open,
b3fa4a8cdb5f clarified text folds: proof ... qed counts as extra block;
wenzelm
parents: 60693
diff changeset
   280
    prf_close, prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script, prf_script_goal,
60624
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
   281
    prf_script_asm_goal];
51225
3fe0d8d55975 support nested Thy_Syntax.element;
wenzelm
parents: 50714
diff changeset
   282
69913
ca515cf61651 more specific keyword kinds;
wenzelm
parents: 67139
diff changeset
   283
val is_theory_goal = command_category [thy_goal, thy_goal_defn, thy_goal_stmt];
60624
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
   284
val is_proof_goal = command_category [prf_goal, prf_asm_goal, prf_script_goal, prf_script_asm_goal];
53571
e58ca0311c0f more explicit indication of 'done' as proof script element;
wenzelm
parents: 53371
diff changeset
   285
val is_qed = command_category [qed, qed_script, qed_block];
28431
f12c1c68ec8e more command categories;
wenzelm
parents: 28345
diff changeset
   286
val is_qed_global = command_category [qed_global];
27520
fb07f3b32863 added is_diag;
wenzelm
parents: 27440
diff changeset
   287
60693
044f8bb3dd30 more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents: 60624
diff changeset
   288
val is_proof_open =
044f8bb3dd30 more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents: 60624
diff changeset
   289
  command_category [prf_goal, prf_asm_goal, prf_script_goal, prf_script_asm_goal, prf_open];
044f8bb3dd30 more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents: 60624
diff changeset
   290
val is_proof_close = command_category [qed, qed_script, qed_block, prf_close];
044f8bb3dd30 more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents: 60624
diff changeset
   291
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59123
diff changeset
   292
val is_proof_asm = command_category [prf_asm, prf_asm_goal];
60624
5b6552e12421 clarified keyword categories;
wenzelm
parents: 59935
diff changeset
   293
val is_improper = command_category [qed_script, prf_script, prf_script_goal, prf_script_asm_goal];
59125
ee19c92ae8b4 more explicit markup for improper commands;
wenzelm
parents: 59123
diff changeset
   294
58923
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   295
fun is_printed keywords = is_theory_goal keywords orf is_proof keywords;
cb9b69cca999 more explicit Keyword.keywords;
wenzelm
parents: 58920
diff changeset
   296
27357
5b3a087ff292 moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 17270
diff changeset
   297
end;