src/Pure/Isar/outer_syntax.ML
author wenzelm
Tue, 12 Aug 2014 00:08:32 +0200
changeset 57905 c0c5652e796e
parent 57623 249c0297cf10
child 57918 f5d73caba4e5
permissions -rw-r--r--
separate module Command_Span: mostly syntactic representation; potentially prover-specific Output_Syntax.parse_spans;
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
    Author:     Markus Wenzel, TU Muenchen
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     3
27353
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26990
diff changeset
     4
The global Isabelle/Isar outer syntax.
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26990
diff changeset
     5
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26990
diff changeset
     6
Note: the syntax for files is statically determined at the very
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26990
diff changeset
     7
beginning; for interactive processing it may change dynamically.
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     8
*)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     9
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    10
signature OUTER_SYNTAX =
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    11
sig
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
    12
  type outer_syntax
55448
e42a3fc18458 explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents: 54734
diff changeset
    13
  val batch_mode: bool Unsynchronized.ref
43712
3c2c912af2ef moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents: 43711
diff changeset
    14
  val is_markup: outer_syntax -> Thy_Output.markup -> string -> bool
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
    15
  val get_syntax: unit -> (Scan.lexicon * Scan.lexicon) * outer_syntax
46970
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
    16
  val check_syntax: unit -> unit
48646
91281e9472d8 more official command specifications, including source position;
wenzelm
parents: 48638
diff changeset
    17
  type command_spec = (string * Keyword.T) * Position.T
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    18
  val command: command_spec -> string ->
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    19
    (Toplevel.transition -> Toplevel.transition) parser -> unit
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    20
  val markup_command: Thy_Output.markup -> command_spec -> string ->
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    21
    (Toplevel.transition -> Toplevel.transition) parser -> unit
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    22
  val improper_command: command_spec -> string ->
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
    23
    (Toplevel.transition -> Toplevel.transition) parser -> unit
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    24
  val local_theory': command_spec -> string ->
29380
a9ee3475abf4 added local_theory';
wenzelm
parents: 29315
diff changeset
    25
    (bool -> local_theory -> local_theory) parser -> unit
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    26
  val local_theory: command_spec -> string ->
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    27
    (local_theory -> local_theory) parser -> unit
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    28
  val local_theory_to_proof': command_spec -> string ->
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    29
    (bool -> local_theory -> Proof.state) parser -> unit
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
    30
  val local_theory_to_proof: command_spec -> string ->
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    31
    (local_theory -> Proof.state) parser -> unit
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
    32
  val help_outer_syntax: string list -> unit
5883
975c984526b0 tuned names;
wenzelm
parents: 5829
diff changeset
    33
  val print_outer_syntax: unit -> unit
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
    34
  val scan: Position.T -> string -> Token.T list
25580
6623674df897 added off-line parse;
wenzelm
parents: 25526
diff changeset
    35
  val parse: Position.T -> string -> Toplevel.transition list
57905
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
    36
  val parse_tokens: Scan.lexicon * Scan.lexicon -> Position.T -> string -> Token.T list
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
    37
  val parse_spans: Token.T list -> Command_Span.span list
26600
f11515535c83 moved structure Isar to isar.ML;
wenzelm
parents: 26431
diff changeset
    38
  type isar
38253
3d4e521014f7 Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents: 38236
diff changeset
    39
  val isar: TextIO.instream -> bool -> isar
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
    40
  val side_comments: Token.T list -> Token.T list
57105
bf5ddf4ec64b tuned signature;
wenzelm
parents: 57026
diff changeset
    41
  val command_reports: outer_syntax -> Token.T -> Position.report_text list
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
    42
  val read_spans: outer_syntax -> Token.T list -> Toplevel.transition list
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    43
end;
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    44
36953
2af1ad9aa1a3 renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
wenzelm
parents: 36950
diff changeset
    45
structure Outer_Syntax: OUTER_SYNTAX =
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    46
struct
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    47
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    48
(** outer syntax **)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    49
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    50
(* command parsers *)
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    51
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    52
datatype command = Command of
24868
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
    53
 {comment: string,
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36959
diff changeset
    54
  markup: Thy_Output.markup option,
24868
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
    55
  int_only: bool,
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    56
  parse: (Toplevel.transition -> Toplevel.transition) parser,
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    57
  pos: Position.T,
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    58
  id: serial};
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    59
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    60
fun new_command comment markup int_only parse pos =
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    61
  Command {comment = comment, markup = markup, int_only = int_only, parse = parse,
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    62
    pos = pos, id = serial ()};
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    63
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    64
fun command_markup def (name, Command {pos, id, ...}) =
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
    65
  Markup.properties (Position.entity_properties_of def id pos)
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 49564
diff changeset
    66
    (Markup.entity Markup.commandN name);
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    67
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
    68
fun pretty_command (cmd as (name, Command {comment, ...})) =
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
    69
  Pretty.block
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
    70
    (Pretty.marks_str
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50215
diff changeset
    71
      ([Active.make_markup Markup.sendbackN {implicit = true, properties = [Markup.padding_line]},
50215
97959912840a more general sendback properties;
wenzelm
parents: 50213
diff changeset
    72
        command_markup false cmd], name) :: Pretty.str ":" :: Pretty.brk 2 :: Pretty.text comment);
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
    73
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    74
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    75
(* parse command *)
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    76
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    77
local
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
    78
14925
0f86a8a694f8 added read (provides transition names and sources);
wenzelm
parents: 14687
diff changeset
    79
fun terminate false = Scan.succeed ()
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 44187
diff changeset
    80
  | terminate true =
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 44187
diff changeset
    81
      Parse.group (fn () => "end of input")
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 44187
diff changeset
    82
        (Scan.option Parse.sync -- Parse.semicolon >> K ());
14925
0f86a8a694f8 added read (provides transition names and sources);
wenzelm
parents: 14687
diff changeset
    83
26620
722cf4fdd4dd eliminated unused trace, read;
wenzelm
parents: 26611
diff changeset
    84
fun body cmd (name, _) =
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
    85
  (case cmd name of
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
    86
    SOME (Command {int_only, parse, ...}) =>
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 33223
diff changeset
    87
      Parse.!!! (Scan.prompt (name ^ "# ") (Parse.tags |-- parse >> pair int_only))
48191
c1def7433a72 internalize error into command transaction -- relevant for commands that are declared via 'keywords', but not defined yet;
wenzelm
parents: 47416
diff changeset
    88
  | NONE =>
c1def7433a72 internalize error into command transaction -- relevant for commands that are declared via 'keywords', but not defined yet;
wenzelm
parents: 47416
diff changeset
    89
      Scan.succeed (false, Toplevel.imperative (fn () =>
c1def7433a72 internalize error into command transaction -- relevant for commands that are declared via 'keywords', but not defined yet;
wenzelm
parents: 47416
diff changeset
    90
        error ("Bad parser for outer syntax command " ^ quote name))));
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    91
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    92
in
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    93
26620
722cf4fdd4dd eliminated unused trace, read;
wenzelm
parents: 26611
diff changeset
    94
fun parse_command do_terminate cmd =
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 33223
diff changeset
    95
  Parse.semicolon >> K NONE ||
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 33223
diff changeset
    96
  Parse.sync >> K NONE ||
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 33223
diff changeset
    97
  (Parse.position Parse.command :-- body cmd) --| terminate do_terminate
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
    98
    >> (fn ((name, pos), (int_only, f)) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15224
diff changeset
    99
      SOME (Toplevel.empty |> Toplevel.name name |> Toplevel.position pos |>
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   100
        Toplevel.interactive int_only |> f));
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   101
6199
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   102
end;
9b1be867e21a removed load;
wenzelm
parents: 6107
diff changeset
   103
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   104
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   105
(* type outer_syntax *)
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   106
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   107
datatype outer_syntax = Outer_Syntax of
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   108
 {commands: command Symtab.table,
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   109
  markups: (string * Thy_Output.markup) list};
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   110
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   111
fun make_outer_syntax commands markups =
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   112
  Outer_Syntax {commands = commands, markups = markups};
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   113
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   114
val empty_outer_syntax = make_outer_syntax Symtab.empty [];
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   115
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   116
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   117
fun map_commands f (Outer_Syntax {commands, ...}) =
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   118
  let
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   119
    val commands' = f commands;
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   120
    val markups' =
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   121
      Symtab.fold (fn (name, Command {markup = SOME m, ...}) => cons (name, m) | _ => I)
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   122
        commands' [];
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   123
  in make_outer_syntax commands' markups' end;
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   124
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   125
fun dest_commands (Outer_Syntax {commands, ...}) =
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   126
  commands |> Symtab.dest |> sort_wrt #1;
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   127
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   128
fun lookup_commands (Outer_Syntax {commands, ...}) = Symtab.lookup commands;
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   129
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   130
fun is_markup (Outer_Syntax {markups, ...}) kind name =
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   131
  AList.lookup (op =) markups name = SOME kind;
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   132
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   133
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   134
9132
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   135
(** global outer syntax **)
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   136
48646
91281e9472d8 more official command specifications, including source position;
wenzelm
parents: 48638
diff changeset
   137
type command_spec = (string * Keyword.T) * Position.T;
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   138
55448
e42a3fc18458 explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents: 54734
diff changeset
   139
val batch_mode = Unsynchronized.ref false;
e42a3fc18458 explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents: 54734
diff changeset
   140
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   141
local
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   142
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   143
(*synchronized wrt. Keywords*)
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   144
val global_outer_syntax = Unsynchronized.ref empty_outer_syntax;
5952
7d4ec8992b23 added commands;
wenzelm
parents: 5923
diff changeset
   145
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   146
fun add_command (name, kind) cmd = CRITICAL (fn () =>
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   147
  let
56294
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56203
diff changeset
   148
    val context = ML_Context.the_generic_context ();
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56203
diff changeset
   149
    val thy = Context.theory_of context;
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   150
    val Command {pos, ...} = cmd;
57623
249c0297cf10 more markup;
wenzelm
parents: 57105
diff changeset
   151
    val command_name = quote (Markup.markup Markup.keyword1 name);
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   152
    val _ =
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   153
      (case try (Thy_Header.the_keyword thy) name of
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   154
        SOME spec =>
48864
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48771
diff changeset
   155
          if Option.map #1 spec = SOME (Keyword.kind_files_of kind) then ()
48646
91281e9472d8 more official command specifications, including source position;
wenzelm
parents: 48638
diff changeset
   156
          else error ("Inconsistent outer syntax keyword declaration " ^
57623
249c0297cf10 more markup;
wenzelm
parents: 57105
diff changeset
   157
            command_name ^ Position.here pos)
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   158
      | NONE =>
46961
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   159
          if Context.theory_name thy = Context.PureN
5c6955f487e5 outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents: 46958
diff changeset
   160
          then Keyword.define (name, SOME kind)
57623
249c0297cf10 more markup;
wenzelm
parents: 57105
diff changeset
   161
          else error ("Undeclared outer syntax command " ^ command_name ^ Position.here pos));
56294
85911b8a6868 prefer Context_Position where a context is available;
wenzelm
parents: 56203
diff changeset
   162
    val _ = Context_Position.report_generic context pos (command_markup true (name, cmd));
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   163
  in
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   164
    Unsynchronized.change global_outer_syntax (map_commands (fn commands =>
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   165
     (if not (Symtab.defined commands name) then ()
57026
90a3e39be0ca afford strict check (see also AFP/a8e08d947f0a);
wenzelm
parents: 56938
diff changeset
   166
      else if ! batch_mode then
57623
249c0297cf10 more markup;
wenzelm
parents: 57105
diff changeset
   167
        error ("Attempt to redefine outer syntax command " ^ command_name)
55448
e42a3fc18458 explicit indication that redefining outer syntax commands is not supposed to happen -- NB: interactive mode requires global change of syntax;
wenzelm
parents: 54734
diff changeset
   168
      else
57623
249c0297cf10 more markup;
wenzelm
parents: 57105
diff changeset
   169
        warning ("Redefining outer syntax command " ^ command_name ^
57026
90a3e39be0ca afford strict check (see also AFP/a8e08d947f0a);
wenzelm
parents: 56938
diff changeset
   170
          Position.here (Position.thread_data ()));
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   171
      Symtab.update (name, cmd) commands)))
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46876
diff changeset
   172
  end);
6722
5e82c7196789 added keyword classification;
wenzelm
parents: 6685
diff changeset
   173
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   174
in
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   175
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   176
fun get_syntax () = CRITICAL (fn () => (Keyword.get_lexicons (), ! global_outer_syntax));
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7774
diff changeset
   177
46970
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   178
fun check_syntax () =
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   179
  let
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   180
    val ((_, major), syntax) = CRITICAL (fn () => (Keyword.dest (), ! global_outer_syntax));
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   181
  in
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   182
    (case subtract (op =) (map #1 (dest_commands syntax)) major of
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   183
      [] => ()
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   184
    | missing => error ("Missing outer syntax command(s) " ^ commas_quote missing))
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   185
  end;
9667e0dcb5e2 check declared vs. defined commands at end of session;
wenzelm
parents: 46961
diff changeset
   186
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   187
fun lookup_commands_dynamic () = lookup_commands (! global_outer_syntax);
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   188
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   189
fun command (spec, pos) comment parse =
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   190
  add_command spec (new_command comment NONE false parse pos);
24868
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
   191
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   192
fun markup_command markup (spec, pos) comment parse =
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   193
  add_command spec (new_command comment (SOME markup) false parse pos);
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   194
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   195
fun improper_command (spec, pos) comment parse =
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   196
  add_command spec (new_command comment NONE true parse pos);
29311
4c830711e6f1 added type 'a parser, simplified signature;
wenzelm
parents: 28436
diff changeset
   197
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   198
end;
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   199
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   200
26990
a91f7741967a added local_theory command wrappers;
wenzelm
parents: 26881
diff changeset
   201
(* local_theory commands *)
a91f7741967a added local_theory command wrappers;
wenzelm
parents: 26881
diff changeset
   202
56895
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56334
diff changeset
   203
fun local_theory_command trans command_spec comment parse =
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56334
diff changeset
   204
  command command_spec comment (Parse.opt_target -- parse >> (fn (loc, f) => trans loc f));
26990
a91f7741967a added local_theory command wrappers;
wenzelm
parents: 26881
diff changeset
   205
56895
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56334
diff changeset
   206
val local_theory' = local_theory_command Toplevel.local_theory';
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56334
diff changeset
   207
val local_theory = local_theory_command Toplevel.local_theory;
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56334
diff changeset
   208
val local_theory_to_proof' = local_theory_command Toplevel.local_theory_to_proof';
f058120aaad4 discontinued Toplevel.print flag -- print uniformly according to Keyword.is_printed;
wenzelm
parents: 56334
diff changeset
   209
val local_theory_to_proof = local_theory_command Toplevel.local_theory_to_proof;
26990
a91f7741967a added local_theory command wrappers;
wenzelm
parents: 26881
diff changeset
   210
a91f7741967a added local_theory command wrappers;
wenzelm
parents: 26881
diff changeset
   211
24872
7fd1aa6671a4 report on keyword/command declarations;
wenzelm
parents: 24868
diff changeset
   212
(* inspect syntax *)
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   213
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   214
fun help_outer_syntax pats =
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   215
  dest_commands (#2 (get_syntax ()))
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   216
  |> filter (fn (name, _) => forall (fn pat => match_string pat name) pats)
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   217
  |> map pretty_command
56334
6b3739fee456 some shortcuts for chunks, which sometimes avoid bulky string output;
wenzelm
parents: 56294
diff changeset
   218
  |> Pretty.writeln_chunks;
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   219
9223
eb752c2fac22 removed help;
wenzelm
parents: 9213
diff changeset
   220
fun print_outer_syntax () =
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   221
  let
46957
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   222
    val ((keywords, _), outer_syntax) =
0c15caf47040 clarified Keyword.is_keyword: union of minor and major;
wenzelm
parents: 46950
diff changeset
   223
      CRITICAL (fn () => (Keyword.dest (), #2 (get_syntax ())));
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   224
    val (int_cmds, cmds) =
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   225
      List.partition (fn (_, Command {int_only, ...}) => int_only) (dest_commands outer_syntax);
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   226
  in
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   227
    [Pretty.strs ("syntax keywords:" :: map quote keywords),
50213
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   228
      Pretty.big_list "commands:" (map pretty_command cmds),
7b73c0509835 refined outer syntax 'help' command;
wenzelm
parents: 50201
diff changeset
   229
      Pretty.big_list "interactive-only commands:" (map pretty_command int_cmds)]
56334
6b3739fee456 some shortcuts for chunks, which sometimes avoid bulky string output;
wenzelm
parents: 56294
diff changeset
   230
    |> Pretty.writeln_chunks
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6868
diff changeset
   231
  end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   232
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   233
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   234
9132
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   235
(** toplevel parsing **)
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   236
9132
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   237
(* basic sources *)
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6733
diff changeset
   238
26620
722cf4fdd4dd eliminated unused trace, read;
wenzelm
parents: 26611
diff changeset
   239
fun toplevel_source term do_recover cmd src =
9132
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   240
  let
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   241
    val no_terminator =
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   242
      Scan.unless Parse.semicolon (Scan.one (Token.not_sync andf Token.not_eof));
23682
cf4773532006 nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents: 23679
diff changeset
   243
    fun recover int =
cf4773532006 nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents: 23679
diff changeset
   244
      (int, fn _ => Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]);
9132
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   245
  in
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   246
    src
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   247
    |> Token.source_proper
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   248
    |> Source.source Token.stopper
51627
589daaf48dba tuned signature -- agree with markup terminology;
wenzelm
parents: 51271
diff changeset
   249
      (Scan.bulk (Parse.$$$ "--" -- Parse.!!! Parse.document_source >> K NONE || Parse.not_eof >> SOME))
23682
cf4773532006 nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents: 23679
diff changeset
   250
        (Option.map recover do_recover)
19482
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19060
diff changeset
   251
    |> Source.map_filter I
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   252
    |> Source.source Token.stopper
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 33223
diff changeset
   253
        (Scan.bulk (fn xs => Parse.!!! (parse_command term (cmd ())) xs))
23682
cf4773532006 nested source: explicit interactive flag for recover avoids duplicate errors;
wenzelm
parents: 23679
diff changeset
   254
        (Option.map recover do_recover)
19482
9f11af8f7ef9 tuned basic list operators (flat, maps, map_filter);
wenzelm
parents: 19060
diff changeset
   255
    |> Source.map_filter I
9132
52286129faa5 moved header stuff to thy_header.ML;
wenzelm
parents: 9056
diff changeset
   256
  end;
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   257
7746
b52c1a632e6a simplified;
wenzelm
parents: 7735
diff changeset
   258
25580
6623674df897 added off-line parse;
wenzelm
parents: 25526
diff changeset
   259
(* off-line scanning/parsing *)
14925
0f86a8a694f8 added read (provides transition names and sources);
wenzelm
parents: 14687
diff changeset
   260
27839
0be8644c45eb Symbol.source/OuterLex.source: more explicit do_recover argument;
wenzelm
parents: 27831
diff changeset
   261
fun scan pos str =
16195
wenzelm
parents: 15989
diff changeset
   262
  Source.of_string str
40523
1050315f6ee2 simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents: 38422
diff changeset
   263
  |> Symbol.source
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   264
  |> Token.source {do_recover = SOME false} Keyword.get_lexicons pos
16195
wenzelm
parents: 15989
diff changeset
   265
  |> Source.exhaust;
wenzelm
parents: 15989
diff changeset
   266
25580
6623674df897 added off-line parse;
wenzelm
parents: 25526
diff changeset
   267
fun parse pos str =
6623674df897 added off-line parse;
wenzelm
parents: 25526
diff changeset
   268
  Source.of_string str
40523
1050315f6ee2 simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents: 38422
diff changeset
   269
  |> Symbol.source
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   270
  |> Token.source {do_recover = SOME false} Keyword.get_lexicons pos
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   271
  |> toplevel_source false NONE lookup_commands_dynamic
25580
6623674df897 added off-line parse;
wenzelm
parents: 25526
diff changeset
   272
  |> Source.exhaust;
6623674df897 added off-line parse;
wenzelm
parents: 25526
diff changeset
   273
57905
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   274
fun parse_tokens lexs pos =
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   275
  Source.of_string #>
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   276
  Symbol.source #>
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   277
  Token.source {do_recover = SOME false} (K lexs) pos #>
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   278
  Source.exhaust;
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   279
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   280
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   281
(* parse spans *)
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   282
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   283
local
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   284
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   285
fun ship span =
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   286
  let
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   287
    val kind =
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   288
      if not (null span) andalso Token.is_command (hd span) andalso not (exists Token.is_error span)
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   289
      then Command_Span.Command_Span (Token.content_of (hd span), Token.pos_of (hd span))
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   290
      else if forall Token.is_improper span then Command_Span.Ignored_Span
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   291
      else Command_Span.Malformed_Span;
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   292
  in cons (Command_Span.Span (kind, span)) end;
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   293
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   294
fun flush (result, content, improper) =
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   295
  result
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   296
  |> not (null content) ? ship (rev content)
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   297
  |> not (null improper) ? ship (rev improper);
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   298
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   299
fun parse tok (result, content, improper) =
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   300
  if Token.is_command tok then (flush (result, content, improper), [tok], [])
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   301
  else if Token.is_improper tok then (result, content, tok :: improper)
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   302
  else (result, tok :: (improper @ content), []);
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   303
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   304
in
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   305
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   306
fun parse_spans toks =
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   307
  fold parse toks ([], [], []) |> flush |> rev;
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   308
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   309
end;
c0c5652e796e separate module Command_Span: mostly syntactic representation;
wenzelm
parents: 57623
diff changeset
   310
14091
ad6ba9c55190 A patch by david aspinall
nipkow
parents: 12943
diff changeset
   311
24868
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
   312
(* interactive source of toplevel transformers *)
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
   313
26600
f11515535c83 moved structure Isar to isar.ML;
wenzelm
parents: 26431
diff changeset
   314
type isar =
f11515535c83 moved structure Isar to isar.ML;
wenzelm
parents: 26431
diff changeset
   315
  (Toplevel.transition, (Toplevel.transition option,
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   316
    (Token.T, (Token.T option, (Token.T, (Token.T,
54734
b91afc3aa3e6 clarified Proof General legacy: special treatment of \<^newline> only in TTY mode;
wenzelm
parents: 52510
diff changeset
   317
      (Symbol_Pos.T,
b91afc3aa3e6 clarified Proof General legacy: special treatment of \<^newline> only in TTY mode;
wenzelm
parents: 52510
diff changeset
   318
        Position.T * (Symbol.symbol, (Symbol.symbol, (string, unit) Source.source) Source.source)
27770
10d84e124a2f updated type of nested sources;
wenzelm
parents: 27720
diff changeset
   319
  Source.source) Source.source) Source.source) Source.source)
10d84e124a2f updated type of nested sources;
wenzelm
parents: 27720
diff changeset
   320
  Source.source) Source.source) Source.source) Source.source;
26600
f11515535c83 moved structure Isar to isar.ML;
wenzelm
parents: 26431
diff changeset
   321
38253
3d4e521014f7 Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents: 38236
diff changeset
   322
fun isar in_stream term : isar =
3d4e521014f7 Isabelle_Process: separate input fifo for commands (still using the old tty protocol);
wenzelm
parents: 38236
diff changeset
   323
  Source.tty in_stream
40523
1050315f6ee2 simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents: 38422
diff changeset
   324
  |> Symbol.source
56203
76c72f4d0667 clarified bootstrap process: switch to ML with context and antiquotations earlier;
wenzelm
parents: 55708
diff changeset
   325
  |> Source.map_filter (fn "\<^newline>" => SOME "\n" | s => SOME s)  (*Proof General legacy*)
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   326
  |> Token.source {do_recover = SOME true} Keyword.get_lexicons Position.none
43711
608d1b451f67 less stateful outer_syntax;
wenzelm
parents: 43621
diff changeset
   327
  |> toplevel_source term (SOME true) lookup_commands_dynamic;
24868
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
   328
2990c327d8c6 simplified interfaces for outer syntax;
wenzelm
parents: 24188
diff changeset
   329
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   330
(* side-comments *)
48749
c197b3c3e7fa some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents: 48647
diff changeset
   331
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   332
fun cmts (t1 :: t2 :: toks) =
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   333
      if Token.keyword_with (fn s => s = "--") t1 then t2 :: cmts toks
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   334
      else cmts (t2 :: toks)
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   335
  | cmts _ = [];
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   336
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   337
val side_comments = filter Token.is_proper #> cmts;
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   338
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   339
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   340
(* read commands *)
48647
a5144c4c26a2 report commands as formal entities, with def/ref positions;
wenzelm
parents: 48646
diff changeset
   341
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   342
fun command_reports outer_syntax tok =
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   343
  if Token.is_command tok then
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   344
    let val name = Token.content_of tok in
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   345
      (case lookup_commands outer_syntax name of
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   346
        NONE => []
55708
f4b114070675 tuned signature;
wenzelm
parents: 55489
diff changeset
   347
      | SOME cmd => [((Token.pos_of tok, command_markup false (name, cmd)), "")])
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   348
    end
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   349
  else [];
48749
c197b3c3e7fa some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents: 48647
diff changeset
   350
52510
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   351
fun read_spans outer_syntax toks =
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   352
  Source.of_list toks
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   353
  |> toplevel_source false NONE (K (lookup_commands outer_syntax))
a4a102237ded tuned signature;
wenzelm
parents: 52509
diff changeset
   354
  |> Source.exhaust;
28432
944cb67f809a load_thy: Toplevel.excursion based on units of command/proof pairs;
wenzelm
parents: 28424
diff changeset
   355
5829
0acb30dd92bc The global Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   356
end;
36953
2af1ad9aa1a3 renamed structure OuterSyntax to Outer_Syntax, keeping the old name as alias for some time;
wenzelm
parents: 36950
diff changeset
   357