src/Pure/Thy/thy_header.ML
author wenzelm
Thu, 22 Sep 2016 11:25:27 +0200
changeset 63936 b87784e19a77
parent 63579 73939a9b70a3
child 64556 851ae0e7b09c
permissions -rw-r--r--
discontinued raw symbols; discontinued Symbol.source; use initial Symbol.explode;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thy_header.ML
46939
5b67ac48b384 allow multiple 'keywords' as in 'fixes';
wenzelm
parents: 46938
diff changeset
     2
    Author:     Makarius
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
     3
46939
5b67ac48b384 allow multiple 'keywords' as in 'fixes';
wenzelm
parents: 46938
diff changeset
     4
Static theory header information.
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
     5
*)
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
     6
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
     7
signature THY_HEADER =
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
     8
sig
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
     9
  type keywords = ((string * Position.T) * Keyword.spec) list
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    10
  type header =
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
    11
   {name: string * Position.T,
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
    12
    imports: (string * Position.T) list,
51294
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
    13
    keywords: keywords}
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
    14
  val make: string * Position.T -> (string * Position.T) list -> keywords -> header
59735
24bee1b11fce misc tuning and simplification;
wenzelm
parents: 59694
diff changeset
    15
  val theoryN: string
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    16
  val bootstrap_keywords: Keyword.keywords
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    17
  val add_keywords: keywords -> theory -> theory
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    18
  val get_keywords: theory -> Keyword.keywords
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    19
  val get_keywords': Proof.context -> Keyword.keywords
62895
54c2abe7e9a4 treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents: 62849
diff changeset
    20
  val ml_bootstrapN: string
62932
db12de2367ca support ROOT0.ML as well -- independently of ROOT.ML;
wenzelm
parents: 62895
diff changeset
    21
  val ml_roots: string list
63022
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62969
diff changeset
    22
  val bootstrap_thys: string list
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    23
  val args: header parser
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    24
  val read: Position.T -> string -> header
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
    25
  val read_tokens: Token.T list -> header
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    26
end;
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    27
32466
a393b7e2a2f8 modernized Thy_Header;
wenzelm
parents: 29606
diff changeset
    28
structure Thy_Header: THY_HEADER =
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    29
struct
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    30
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    31
(** keyword declarations **)
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    32
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    33
(* header *)
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    34
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    35
type keywords = ((string * Position.T) * Keyword.spec) list;
48874
ff9cd47be39b refined Thy_Load.check_thy: find more uses in body text, based on keywords;
wenzelm
parents: 48864
diff changeset
    36
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    37
type header =
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
    38
 {name: string * Position.T,
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
    39
  imports: (string * Position.T) list,
51294
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
    40
  keywords: keywords};
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    41
51294
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
    42
fun make name imports keywords : header =
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
    43
  {name = name, imports = imports, keywords = keywords};
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    44
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    45
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    46
(* bootstrap keywords *)
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    47
58868
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
    48
val chapterN = "chapter";
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
    49
val sectionN = "section";
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
    50
val subsectionN = "subsection";
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
    51
val subsubsectionN = "subsubsection";
61463
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 60957
diff changeset
    52
val paragraphN = "paragraph";
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 60957
diff changeset
    53
val subparagraphN = "subparagraph";
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
    54
val textN = "text";
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
    55
val txtN = "txt";
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
    56
val text_rawN = "text_raw";
58868
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
    57
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    58
val theoryN = "theory";
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    59
val importsN = "imports";
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
    60
val keywordsN = "keywords";
63579
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
    61
val abbrevsN = "abbrevs";
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    62
val beginN = "begin";
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    63
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    64
val bootstrap_keywords =
58903
38c72f5f6c2e explicit type Keyword.keywords;
wenzelm
parents: 58868
diff changeset
    65
  Keyword.empty_keywords
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    66
  |> Keyword.add_keywords
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    67
    [(("%", @{here}), Keyword.no_spec),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    68
     (("(", @{here}), Keyword.no_spec),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    69
     ((")", @{here}), Keyword.no_spec),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    70
     ((",", @{here}), Keyword.no_spec),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    71
     (("::", @{here}), Keyword.no_spec),
63579
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
    72
     (("=", @{here}), Keyword.no_spec),
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    73
     (("and", @{here}), Keyword.no_spec),
63449
b3f6e81cd13b clarified keywords;
wenzelm
parents: 63448
diff changeset
    74
     ((beginN, @{here}), Keyword.quasi_command_spec),
63448
998acd66fbd7 clarified keywords;
wenzelm
parents: 63429
diff changeset
    75
     ((importsN, @{here}), Keyword.quasi_command_spec),
998acd66fbd7 clarified keywords;
wenzelm
parents: 63429
diff changeset
    76
     ((keywordsN, @{here}), Keyword.quasi_command_spec),
63579
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
    77
     ((abbrevsN, @{here}), Keyword.quasi_command_spec),
63429
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    78
     ((chapterN, @{here}), ((Keyword.document_heading, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    79
     ((sectionN, @{here}), ((Keyword.document_heading, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    80
     ((subsectionN, @{here}), ((Keyword.document_heading, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    81
     ((subsubsectionN, @{here}), ((Keyword.document_heading, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    82
     ((paragraphN, @{here}), ((Keyword.document_heading, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    83
     ((subparagraphN, @{here}), ((Keyword.document_heading, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    84
     ((textN, @{here}), ((Keyword.document_body, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    85
     ((txtN, @{here}), ((Keyword.document_body, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    86
     ((text_rawN, @{here}), ((Keyword.document_raw, []), [])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    87
     ((theoryN, @{here}), ((Keyword.thy_begin, []), ["theory"])),
baedd4724f08 tuned signature: more uniform Keyword.spec;
wenzelm
parents: 63022
diff changeset
    88
     (("ML", @{here}), ((Keyword.thy_decl, []), ["ML"]))];
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    89
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    90
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    91
(* theory data *)
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
    92
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    93
structure Data = Theory_Data
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    94
(
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    95
  type T = Keyword.keywords;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    96
  val empty = bootstrap_keywords;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    97
  val extend = I;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    98
  val merge = Keyword.merge_keywords;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
    99
);
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   100
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   101
val add_keywords = Data.map o Keyword.add_keywords;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   102
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   103
val get_keywords = Data.get;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   104
val get_keywords' = get_keywords o Proof_Context.theory_of;
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   105
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   106
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   107
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58924
diff changeset
   108
(** concrete syntax **)
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   109
62895
54c2abe7e9a4 treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents: 62849
diff changeset
   110
(* names *)
54c2abe7e9a4 treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents: 62849
diff changeset
   111
54c2abe7e9a4 treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents: 62849
diff changeset
   112
val ml_bootstrapN = "ML_Bootstrap";
62932
db12de2367ca support ROOT0.ML as well -- independently of ROOT.ML;
wenzelm
parents: 62895
diff changeset
   113
val ml_roots = ["ML_Root0", "ML_Root"];
63022
785a59235a15 more IDE support for Isabelle/Pure bootstrap;
wenzelm
parents: 62969
diff changeset
   114
val bootstrap_thys = ["Bootstrap_Pure", "Bootstrap_ML_Bootstrap"];
62932
db12de2367ca support ROOT0.ML as well -- independently of ROOT.ML;
wenzelm
parents: 62895
diff changeset
   115
62895
54c2abe7e9a4 treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents: 62849
diff changeset
   116
54c2abe7e9a4 treat ROOT.ML as theory with header "theory ML_Root imports ML_Bootstrap begin";
wenzelm
parents: 62849
diff changeset
   117
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   118
(* header args *)
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   119
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   120
local
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   121
59694
d2bb4b5ed862 misc tuning -- more uniform ML vs. Scala;
wenzelm
parents: 59693
diff changeset
   122
fun imports name =
d2bb4b5ed862 misc tuning -- more uniform ML vs. Scala;
wenzelm
parents: 59693
diff changeset
   123
  if name = Context.PureN then Scan.succeed []
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62932
diff changeset
   124
  else Parse.$$$ importsN |-- Parse.!!! (Scan.repeat1 (Parse.position Parse.theory_name));
53962
65bca53daf70 more robust parser: 'imports' are mandatory except for bootstrapping Pure;
wenzelm
parents: 51627
diff changeset
   125
48864
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48707
diff changeset
   126
val opt_files =
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48707
diff changeset
   127
  Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Parse.list1 Parse.name) --| Parse.$$$ ")") [];
50128
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 48992
diff changeset
   128
48864
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48707
diff changeset
   129
val keyword_spec =
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48707
diff changeset
   130
  Parse.group (fn () => "outer syntax keyword specification")
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48707
diff changeset
   131
    (Parse.name -- opt_files -- Parse.tags);
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48707
diff changeset
   132
46939
5b67ac48b384 allow multiple 'keywords' as in 'fixes';
wenzelm
parents: 46938
diff changeset
   133
val keyword_decl =
59934
b65c4370f831 more position information and PIDE markup for command keywords;
wenzelm
parents: 59735
diff changeset
   134
  Scan.repeat1 (Parse.position Parse.string) --
63579
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
   135
  Scan.optional (Parse.$$$ "::" |-- Parse.!!! keyword_spec) Keyword.no_spec
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
   136
  >> (fn (names, spec) => map (rpair spec) names);
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
   137
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
   138
val abbrevs = Scan.repeat1 (Parse.text -- (Parse.$$$ "=" |-- Parse.!!! Parse.text));
50128
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 48992
diff changeset
   139
46939
5b67ac48b384 allow multiple 'keywords' as in 'fixes';
wenzelm
parents: 46938
diff changeset
   140
val keyword_decls = Parse.and_list1 keyword_decl >> flat;
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   141
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   142
in
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   143
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   144
val args =
59693
d96cb03caf9e tunes signature -- more uniform ML vs. Scala;
wenzelm
parents: 58999
diff changeset
   145
  Parse.position Parse.theory_name :|-- (fn (name, pos) =>
59694
d2bb4b5ed862 misc tuning -- more uniform ML vs. Scala;
wenzelm
parents: 59693
diff changeset
   146
    imports name --
53962
65bca53daf70 more robust parser: 'imports' are mandatory except for bootstrapping Pure;
wenzelm
parents: 51627
diff changeset
   147
    Scan.optional (Parse.$$$ keywordsN |-- Parse.!!! keyword_decls) [] --|
63579
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
   148
    (Scan.optional (Parse.$$$ abbrevsN |-- Parse.!!! abbrevs) [] -- Parse.$$$ beginN)
73939a9b70a3 support 'abbrevs' within theory header;
wenzelm
parents: 63449
diff changeset
   149
    >> (fn (imports, keywords) => make (name, pos) imports keywords));
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   150
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   151
end;
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   152
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   153
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   154
(* read header *)
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   155
58868
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
   156
val heading =
62453
b93cc7d73431 discontinued old 'header';
wenzelm
parents: 61463
diff changeset
   157
  (Parse.command chapterN ||
58908
58bedbc18915 tuned signature;
wenzelm
parents: 58907
diff changeset
   158
    Parse.command sectionN ||
58bedbc18915 tuned signature;
wenzelm
parents: 58907
diff changeset
   159
    Parse.command subsectionN ||
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
   160
    Parse.command subsubsectionN ||
61463
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 60957
diff changeset
   161
    Parse.command paragraphN ||
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 60957
diff changeset
   162
    Parse.command subparagraphN ||
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
   163
    Parse.command textN ||
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
   164
    Parse.command txtN ||
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58932
diff changeset
   165
    Parse.command text_rawN) --
58868
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
   166
  Parse.tags -- Parse.!!! Parse.document_source;
c5e1cce7ace3 uniform heading commands work in any context, even in theory header;
wenzelm
parents: 58864
diff changeset
   167
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   168
val header =
58908
58bedbc18915 tuned signature;
wenzelm
parents: 58907
diff changeset
   169
  (Scan.repeat heading -- Parse.command theoryN -- Parse.tags) |-- Parse.!!! args;
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   170
63936
b87784e19a77 discontinued raw symbols;
wenzelm
parents: 63579
diff changeset
   171
fun token_source pos =
b87784e19a77 discontinued raw symbols;
wenzelm
parents: 63579
diff changeset
   172
  Symbol.explode
b87784e19a77 discontinued raw symbols;
wenzelm
parents: 63579
diff changeset
   173
  #> Source.of_list
b87784e19a77 discontinued raw symbols;
wenzelm
parents: 63579
diff changeset
   174
  #> Token.source_strict bootstrap_keywords pos;
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
   175
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
   176
fun read_source pos source =
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   177
  let val res =
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
   178
    source
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   179
    |> Token.source_proper
58864
505a8150368a recover via scanner;
wenzelm
parents: 58863
diff changeset
   180
    |> Source.source Token.stopper (Scan.single (Scan.error (Parse.!!! header)))
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   181
    |> Source.get_single;
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   182
  in
42003
6e45dc518ebb replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents: 41944
diff changeset
   183
    (case res of
46938
cda018294515 some support for outer syntax keyword declarations within theory header;
wenzelm
parents: 46737
diff changeset
   184
      SOME (h, _) => h
48992
0518bf89c777 renamed Position.str_of to Position.here;
wenzelm
parents: 48927
diff changeset
   185
    | NONE => error ("Unexpected end of input" ^ Position.here pos))
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   186
  end;
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   187
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
   188
fun read pos str = read_source pos (token_source pos str);
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
   189
fun read_tokens toks = read_source Position.none (Source.of_list toks);
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48881
diff changeset
   190
22106
0886ec05f951 renamed Isar/thy_header.ML to Thy/thy_header.ML;
wenzelm
parents:
diff changeset
   191
end;