src/Pure/Isar/outer_syntax.ML
author wenzelm
Sun, 03 Oct 1999 15:52:53 +0200
changeset 7683 e74f43f1d8a3
parent 7676 811022c3837e
child 7735 3e5ff3806831
permissions -rw-r--r--
export token_source; improved Present.theory_source;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/outer_syntax.ML
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     4
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     5
The global Isabelle/Isar outer syntax.
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     6
*)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     7
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     8
signature BASIC_OUTER_SYNTAX =
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     9
sig
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    10
  val main: unit -> unit
5883
975c984526b0 tuned names;
wenzelm
parents: 5829
diff changeset
    11
  val loop: unit -> unit
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    12
  val sync_main: unit -> unit
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    13
  val sync_loop: unit -> unit
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    14
  val help: unit -> unit
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    15
end;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    16
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    17
signature OUTER_SYNTAX =
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    18
sig
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    19
  include BASIC_OUTER_SYNTAX
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    20
  structure Keyword:
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    21
    sig
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    22
      val control: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    23
      val diag: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    24
      val thy_begin: string
7104
247e4247b64e added thy_switch kind;
wenzelm
parents: 7062
diff changeset
    25
      val thy_switch: string
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    26
      val thy_end: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    27
      val thy_heading: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    28
      val thy_decl: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    29
      val thy_goal: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    30
      val qed: string
6733
429bbd7ef26d qed_block keywords;
wenzelm
parents: 6722
diff changeset
    31
      val qed_block: string
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    32
      val prf_goal: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    33
      val prf_block: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    34
      val prf_chain: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    35
      val prf_decl: string
6868
27ba88d57399 added prf_asm;
wenzelm
parents: 6860
diff changeset
    36
      val prf_asm: string
7676
811022c3837e added prf_asm_goal;
wenzelm
parents: 7613
diff changeset
    37
      val prf_asm_goal: string
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    38
      val prf_script: string
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    39
      val kinds: string list
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    40
    end
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    41
  type token
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    42
  type parser
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    43
  val command: string -> string -> string ->
6373
47b357194f32 added (improper_)command;
wenzelm
parents: 6332
diff changeset
    44
    (token list -> (Toplevel.transition -> Toplevel.transition) * token list) -> parser
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    45
  val improper_command: string -> string -> string ->
6373
47b357194f32 added (improper_)command;
wenzelm
parents: 6332
diff changeset
    46
    (token list -> (Toplevel.transition -> Toplevel.transition) * token list) -> parser
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
    47
  val dest_keywords: unit -> string list
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
    48
  val dest_parsers: unit -> (string * string * string * bool) list
5883
975c984526b0 tuned names;
wenzelm
parents: 5829
diff changeset
    49
  val print_outer_syntax: unit -> unit
7367
a79d4683fadf print_help;
wenzelm
parents: 7333
diff changeset
    50
  val print_help: Toplevel.transition -> Toplevel.transition
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    51
  val add_keywords: string list -> unit
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    52
  val add_parsers: parser list -> unit
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
    53
  val token_source: (string, 'a) Source.source * Position.T -> (OuterLex.token,
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
    54
    Position.T * (Symbol.symbol, (string, 'a) Source.source) Source.source) Source.source
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
    55
  val theory_header: token list -> (string * string list * (string * bool) list) * token list
7192
30a67acd0d7e simplified ML handling;
wenzelm
parents: 7104
diff changeset
    56
  val deps_thy: string -> Path.T -> string list * Path.T list
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
    57
  val load_thy: string -> bool -> bool -> Path.T -> unit
7333
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
    58
  val isar: bool -> bool -> Toplevel.isar
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    59
end;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    60
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    61
structure OuterSyntax: OUTER_SYNTAX =
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    62
struct
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    63
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    64
structure P = OuterParse;
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    65
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    66
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    67
(** outer syntax **)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    68
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    69
(* command keyword classification *)
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    70
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    71
structure Keyword =
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    72
struct
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    73
  val control = "control";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    74
  val diag = "diag";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    75
  val thy_begin = "theory-begin";
7104
247e4247b64e added thy_switch kind;
wenzelm
parents: 7062
diff changeset
    76
  val thy_switch = "theory-switch";
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    77
  val thy_end = "theory-end";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    78
  val thy_heading = "theory-heading";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    79
  val thy_decl = "theory-decl";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    80
  val thy_goal = "theory-goal";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    81
  val qed = "qed";
6733
429bbd7ef26d qed_block keywords;
wenzelm
parents: 6722
diff changeset
    82
  val qed_block = "qed-block";
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    83
  val prf_goal = "proof-goal";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    84
  val prf_block = "proof-block";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    85
  val prf_chain = "proof-chain";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    86
  val prf_decl = "proof-decl";
6868
27ba88d57399 added prf_asm;
wenzelm
parents: 6860
diff changeset
    87
  val prf_asm = "proof-asm";
7676
811022c3837e added prf_asm_goal;
wenzelm
parents: 7613
diff changeset
    88
  val prf_asm_goal = "proof-asm-goal";
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    89
  val prf_script = "proof-script";
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    90
7104
247e4247b64e added thy_switch kind;
wenzelm
parents: 7062
diff changeset
    91
  val kinds = [control, diag, thy_begin, thy_switch, thy_end, thy_heading, thy_decl, thy_goal,
7676
811022c3837e added prf_asm_goal;
wenzelm
parents: 7613
diff changeset
    92
    qed, qed_block, prf_goal, prf_block, prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script];
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    93
end;
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    94
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
    95
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    96
(* parsers *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    97
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    98
type token = OuterLex.token;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    99
type parser_fn = token list -> (Toplevel.transition -> Toplevel.transition) * token list;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   100
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   101
datatype parser =
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
   102
  Parser of string * (string * string) * bool * parser_fn;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   103
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
   104
fun parser int_only name comment kind parse = Parser (name, (comment, kind), int_only, parse);
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   105
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   106
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   107
(* parse command *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   108
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   109
local
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   110
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   111
fun command_body cmd (name, _) =
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   112
  (case cmd name of
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   113
    Some (int_only, parse) => P.!!! (Scan.prompt (name ^ "# ") (parse >> pair int_only))
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   114
  | None => sys_error ("no parser for outer syntax command " ^ quote name));
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   115
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   116
fun terminator false = Scan.succeed ()
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   117
  | terminator true = P.group "terminator" (Scan.option P.sync -- P.$$$ ";" >> K ());
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   118
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   119
in
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   120
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   121
fun command term cmd =
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   122
  P.$$$ ";" >> K None ||
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   123
  P.sync >> K None ||
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   124
  (P.position P.command :-- command_body cmd) --| terminator term
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   125
    >> (fn ((name, pos), (int_only, f)) =>
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   126
      Some (Toplevel.empty |> Toplevel.name name |> Toplevel.position pos |>
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   127
        Toplevel.interactive int_only |> f));
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   128
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   129
end;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   130
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   131
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   132
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   133
(** global syntax state **)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   134
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   135
local
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   136
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   137
val global_lexicons = ref (Scan.empty_lexicon, Scan.empty_lexicon);
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
   138
val global_parsers = ref (Symtab.empty: ((string * string) * (bool * parser_fn)) Symtab.table);
5952
7d4ec8992b23 added commands;
wenzelm
parents: 5923
diff changeset
   139
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   140
fun change_lexicons f =
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   141
  let val lexs = f (! global_lexicons) in
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   142
    (case (op inter_string) (pairself Scan.dest_lexicon lexs) of
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   143
      [] => global_lexicons := lexs
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   144
    | bads => error ("Clash of outer syntax commands and keywords: " ^ commas_quote bads))
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   145
  end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   146
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   147
fun change_parsers f = global_parsers := f (! global_parsers);
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
   148
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   149
in
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   150
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   151
(* get current lexers / parsers *)
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   152
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   153
(*Note: the syntax for files is statically determined at the very
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   154
  beginning; for interactive processing it may change dynamically.*)
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   155
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   156
fun get_lexicons () = ! global_lexicons;
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   157
fun get_parsers () = ! global_parsers;
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   158
fun get_parser () = apsome snd o curry Symtab.lookup (! global_parsers);
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   159
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   160
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   161
(* augment syntax *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   162
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   163
fun add_keywords keywords = change_lexicons (apfst (fn lex =>
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   164
  (Scan.extend_lexicon lex (map Symbol.explode keywords))));
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   165
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   166
fun add_parser (tab, Parser (name, comment, int_only, parse)) =
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   167
 (if is_none (Symtab.lookup (tab, name)) then ()
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   168
  else warning ("Redefined outer syntax command " ^ quote name);
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   169
  Symtab.update ((name, (comment, (int_only, parse))), tab));
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   170
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   171
fun add_parsers parsers =
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   172
  (change_parsers (fn tab => foldl add_parser (tab, parsers));
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   173
    change_lexicons (apsnd (fn lex => Scan.extend_lexicon lex
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   174
      (map (fn Parser (name, _, _, _) => Symbol.explode name) parsers))));
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   175
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   176
end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   177
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   178
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   179
(* print syntax *)
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   180
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   181
fun dest_keywords () = Scan.dest_lexicon (#1 (get_lexicons ()));
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   182
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   183
fun dest_parsers () =
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   184
  map (fn (name, ((cmt, kind), (int_only, _))) => (name, cmt, kind, int_only))
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   185
    (Symtab.dest (get_parsers ()));
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   186
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   187
fun print_outer_syntax () =
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   188
  let
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   189
    fun pretty_cmd (name, comment, _, _) =
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   190
      Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   191
    val (int_cmds, cmds) = partition #4 (dest_parsers ());
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   192
  in
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   193
    Pretty.writeln (Pretty.strs ("syntax keywords:" :: map quote (dest_keywords ())));
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   194
    Pretty.writeln (Pretty.big_list "proper commands:" (map pretty_cmd cmds));
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   195
    Pretty.writeln (Pretty.big_list "improper commands (interactive-only):"
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   196
      (map pretty_cmd int_cmds))
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   197
  end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   198
7367
a79d4683fadf print_help;
wenzelm
parents: 7333
diff changeset
   199
val print_help =
a79d4683fadf print_help;
wenzelm
parents: 7333
diff changeset
   200
  Toplevel.keep (fn state =>
7613
fe818734c387 help: unknown theory context;
wenzelm
parents: 7604
diff changeset
   201
    let val opt_thy = try Toplevel.theory_of state in
fe818734c387 help: unknown theory context;
wenzelm
parents: 7604
diff changeset
   202
      print_outer_syntax ();
fe818734c387 help: unknown theory context;
wenzelm
parents: 7604
diff changeset
   203
      Method.help_methods opt_thy;
fe818734c387 help: unknown theory context;
wenzelm
parents: 7604
diff changeset
   204
      Attrib.help_attributes opt_thy
fe818734c387 help: unknown theory context;
wenzelm
parents: 7604
diff changeset
   205
    end);
7367
a79d4683fadf print_help;
wenzelm
parents: 7333
diff changeset
   206
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   207
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   208
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   209
(** read theory **)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   210
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   211
(* theory keyword *)
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   212
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   213
val theoryN = "theory";
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   214
val theory_keyword = OuterParse.$$$ theoryN;
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   215
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   216
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   217
(* sources *)
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   218
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   219
local
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   220
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   221
val no_terminator =
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   222
  Scan.unless (P.$$$ ";") (Scan.one (OuterLex.not_sync andf OuterLex.not_eof));
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   223
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   224
val recover = Scan.prompt "recover# " (Scan.repeat no_terminator);
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   225
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   226
in
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   227
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   228
fun source term do_recover cmd src =
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   229
  src
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   230
  |> Source.source OuterLex.stopper
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   231
    (Scan.bulk (fn xs => OuterParse.!!! (command term (cmd ())) xs))
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   232
    (if do_recover then Some recover else None)
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   233
  |> Source.mapfilter I;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   234
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   235
end;
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   236
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   237
fun token_source (src, pos) =
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   238
  src
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   239
  |> Symbol.source false
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   240
  |> OuterLex.source false (K (get_lexicons ())) pos;
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   241
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   242
fun filter_proper src =
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   243
  src
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   244
  |> Source.filter OuterLex.is_proper;
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   245
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   246
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   247
(* detect header *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   248
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   249
fun scan_header get_lex scan (src, pos) =
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   250
  src
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   251
  |> Symbol.source false
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   252
  |> OuterLex.source false (fn () => (get_lex (), Scan.empty_lexicon)) pos
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   253
  |> filter_proper
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   254
  |> Source.source OuterLex.stopper (Scan.single scan) None
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   255
  |> (fst o the o Source.get_single);
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   256
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   257
val check_header_lexicon = Scan.make_lexicon [Symbol.explode theoryN];
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   258
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   259
fun is_old_theory src =
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   260
  is_none (scan_header (K check_header_lexicon) (Scan.option theory_keyword) src);
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   261
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   262
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   263
(* deps_thy --- inspect theory header *)
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   264
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   265
val header_lexicon =
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   266
  Scan.make_lexicon (map Symbol.explode ["(", ")", "+", ":", "=", "files", theoryN]);
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   267
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   268
local
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   269
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   270
val file_name =
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   271
  (P.$$$ "(" |-- P.!!! (P.name --| P.$$$ ")")) >> rpair false || P.name >> rpair true;
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   272
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   273
val theory_head =
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   274
  (P.name -- (P.$$$ "=" |-- P.enum1 "+" P.name) --
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   275
    Scan.optional (P.$$$ "files" |-- P.!!! (Scan.repeat1 file_name)) [])
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   276
  >> (fn ((A, Bs), files) => (A, Bs, files));
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   277
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   278
in
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   279
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   280
val theory_header = theory_head --| (Scan.ahead P.eof || P.$$$ ":");
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   281
val only_header = theory_keyword |-- theory_head --| Scan.ahead P.eof;
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   282
val new_header = theory_keyword |-- P.!!! theory_header;
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   283
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   284
val old_header =
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   285
  P.name -- (P.$$$ "=" |-- P.name -- Scan.repeat (P.$$$ "+" |-- P.name))
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   286
  >> (fn (A, (B, Bs)) => (A, B :: Bs, []: (string * bool) list));
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   287
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   288
end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   289
7192
30a67acd0d7e simplified ML handling;
wenzelm
parents: 7104
diff changeset
   290
fun deps_thy name path =
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   291
  let
6641
254ab03bd082 rearranged some modules;
wenzelm
parents: 6373
diff changeset
   292
    val src = File.source path;
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   293
    val (name', parents, files) =
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   294
      (*Note: old style headers dynamically depend on the current lexicon :-( *)
7212
1ad29e7d917b removed warn_theory_style;
wenzelm
parents: 7192
diff changeset
   295
      if is_old_theory src then scan_header ThySyn.get_lexicon (Scan.error old_header) src
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   296
      else scan_header (K header_lexicon) (Scan.error new_header) src;
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   297
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   298
    val ml_path = ThyLoad.ml_path name;
7192
30a67acd0d7e simplified ML handling;
wenzelm
parents: 7104
diff changeset
   299
    val ml_file = if is_none (ThyLoad.check_file ml_path) then [] else [ml_path];
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   300
  in
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   301
    if name <> name' then
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   302
      error ("Filename " ^ quote (Path.pack path) ^ " does not match theory name " ^ quote name)
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   303
    else (parents, map (Path.unpack o #1) files @ ml_file)
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   304
  end;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   305
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   306
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   307
(* load_thy --- read text (including header) *)
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   308
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   309
fun try_ml_file name ml time =
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   310
  let
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   311
    val path = ThyLoad.ml_path name;
7243
886ecd6a27ac ThyInfo.may_load_file;
wenzelm
parents: 7212
diff changeset
   312
    val tr = Toplevel.imperative (fn () => ThyInfo.may_load_file ml time path);
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   313
    val tr_name = if time then "time_use" else "use";
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   314
  in
7243
886ecd6a27ac ThyInfo.may_load_file;
wenzelm
parents: 7212
diff changeset
   315
    if is_none (ThyLoad.check_file path) then ()
7062
e992884b256d Toplevel.excursion_error;
wenzelm
parents: 7026
diff changeset
   316
    else Toplevel.excursion_error [Toplevel.empty |> Toplevel.name tr_name |> tr]
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   317
  end;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   318
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   319
fun parse_thy src_pos =
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   320
  let
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   321
    val lex_src = filter_proper (token_source src_pos);
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   322
    val only_head =
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   323
      lex_src
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   324
      |> Source.source OuterLex.stopper (Scan.single (Scan.option only_header)) None
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   325
      |> (fst o the o Source.get_single);
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   326
  in
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   327
    (case only_head of
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   328
      None =>
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   329
        lex_src
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   330
        |> source false false (K (get_parser ()))
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   331
        |> Source.exhaust
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   332
    | Some spec =>
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   333
        [Toplevel.empty |> Toplevel.name theoryN |> IsarThy.theory spec,
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   334
          Toplevel.empty |> Toplevel.name "end" |> Toplevel.exit])
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   335
  end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   336
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   337
fun run_thy name path =
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   338
  let
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   339
    val (src, pos) = File.source path;
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   340
    val is_old = is_old_theory (src, pos);
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   341
  in
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   342
    Present.theory_source is_old name (src, pos);
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   343
    if is_old then ThySyn.load_thy name (Source.exhaust src)
7062
e992884b256d Toplevel.excursion_error;
wenzelm
parents: 7026
diff changeset
   344
    else Toplevel.excursion_error (parse_thy (src, pos))
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   345
  end;
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   346
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   347
fun load_thy name ml time path =
6247
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   348
 (if time then
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   349
    timeit (fn () =>
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   350
     (writeln ("\n**** Starting theory " ^ quote name ^ " ****");
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   351
      setmp Goals.proof_timing true (run_thy name) path;
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   352
      writeln ("**** Finished theory " ^ quote name ^ " ****\n")))
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   353
  else run_thy name path;
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   354
  Context.context (ThyInfo.get_theory name);
e8bbe64861b8 more robust handling of theory context;
wenzelm
parents: 6229
diff changeset
   355
  try_ml_file name ml time);
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   356
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   357
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   358
(* interactive source of state transformers *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   359
7333
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   360
fun isar term no_pos =
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   361
  Source.tty
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   362
  |> Symbol.source true
7604
wenzelm
parents: 7367
diff changeset
   363
  |> OuterLex.source true get_lexicons
wenzelm
parents: 7367
diff changeset
   364
    (if no_pos then Position.none else Position.line_name 1 "stdin")
7683
e74f43f1d8a3 export token_source;
wenzelm
parents: 7676
diff changeset
   365
  |> filter_proper
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   366
  |> source term true get_parser;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   367
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   368
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   369
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   370
(** the read-eval-print loop **)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   371
5923
wenzelm
parents: 5883
diff changeset
   372
(* main loop *)
wenzelm
parents: 5883
diff changeset
   373
7333
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   374
fun gen_loop term no_pos =
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   375
 (Context.reset_context ();
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   376
  Toplevel.loop (isar term no_pos));
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   377
7333
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   378
fun gen_main term no_pos =
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   379
 (Toplevel.set_state Toplevel.toplevel;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   380
  ml_prompts "ML> " "ML# ";
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   381
  writeln (Session.welcome ());
7333
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   382
  gen_loop term no_pos);
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   383
7333
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   384
fun main () = gen_main false false;
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   385
fun loop () = gen_loop false false;
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   386
fun sync_main () = gen_main true true;
6cb15c6f1d9f isar: no_pos flag;
wenzelm
parents: 7243
diff changeset
   387
fun sync_loop () = gen_loop true true;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   388
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   389
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   390
(* help *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   391
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   392
fun help () =
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   393
  writeln ("This is Isabelle's underlying ML system (" ^ ml_system ^ ");\n\
5883
975c984526b0 tuned names;
wenzelm
parents: 5829
diff changeset
   394
    \invoke 'loop();' to enter the Isar loop.");
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   395
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   396
6373
47b357194f32 added (improper_)command;
wenzelm
parents: 6332
diff changeset
   397
(*final declarations of this structure!*)
6685
wenzelm
parents: 6641
diff changeset
   398
val command = parser false;
wenzelm
parents: 6641
diff changeset
   399
val improper_command = parser true;
wenzelm
parents: 6641
diff changeset
   400
6373
47b357194f32 added (improper_)command;
wenzelm
parents: 6332
diff changeset
   401
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   402
end;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   403
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   404
(*setup theory syntax dependent operations*)
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   405
ThyLoad.deps_thy_fn := OuterSyntax.deps_thy;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   406
ThyLoad.load_thy_fn := OuterSyntax.load_thy;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   407
structure ThyLoad: THY_LOAD = ThyLoad;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   408
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   409
structure BasicOuterSyntax: BASIC_OUTER_SYNTAX = OuterSyntax;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   410
open BasicOuterSyntax;