src/Pure/Thy/thy_edit.ML
author wenzelm
Wed, 01 Oct 2008 22:33:29 +0200
changeset 28454 c63168db774c
parent 28438 32bb6b4eb390
permissions -rw-r--r--
unit_source: more rigid parsing, stop after final qed;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thy_edit.ML
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     4
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
     5
Basic editor operations on theory sources.
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     6
*)
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     7
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     8
signature THY_EDIT =
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
     9
sig
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    10
  val token_source: Scan.lexicon * Scan.lexicon -> Position.T -> (string, 'a) Source.source ->
27770
10d84e124a2f updated type of nested sources;
wenzelm
parents: 27756
diff changeset
    11
    (OuterLex.token, (SymbolPos.T, Position.T * (Symbol.symbol, (string, 'a)
10d84e124a2f updated type of nested sources;
wenzelm
parents: 27756
diff changeset
    12
      Source.source) Source.source) Source.source) Source.source
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    13
  val parse_tokens: Scan.lexicon * Scan.lexicon -> Position.T -> string -> OuterLex.token list
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    14
  val present_token: OuterLex.token -> output
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    15
  val report_token: OuterLex.token -> unit
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    16
  datatype span_kind = Command of string | Ignored | Malformed
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    17
  type span
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    18
  val span_kind: span -> span_kind
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    19
  val span_content: span -> OuterLex.token list
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
    20
  val span_range: span -> Position.range
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    21
  val span_source: (OuterLex.token, 'a) Source.source ->
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    22
    (span, (OuterLex.token, 'a) Source.source) Source.source
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    23
  val parse_spans: Scan.lexicon * Scan.lexicon -> Position.T -> string -> span list
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
    24
  val present_span: span -> output
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    25
  val report_span: span -> unit
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
    26
  val unit_source: (span, 'a) Source.source ->
28438
32bb6b4eb390 unit_source: explicit treatment of 'oops' proofs;
wenzelm
parents: 28434
diff changeset
    27
    (span * span list * bool, (span, 'a) Source.source) Source.source
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    28
end;
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    29
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    30
structure ThyEdit: THY_EDIT =
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    31
struct
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    32
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
    33
structure K = OuterKeyword;
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    34
structure T = OuterLex;
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    35
structure P = OuterParse;
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    36
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    37
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    38
(** tokens **)
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    39
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    40
(* parse *)
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    41
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    42
fun token_source lexs pos src =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    43
  Symbol.source {do_recover = true} src
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    44
  |> T.source {do_recover = SOME false} (K lexs) pos;
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    45
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    46
fun parse_tokens lexs pos str =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    47
  Source.of_string str
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    48
  |> token_source lexs pos
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    49
  |> Source.exhaust;
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    50
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    51
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    52
(* present *)
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    53
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    54
local
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    55
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    56
val token_kind_markup =
27846
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    57
 fn T.Command       => (Markup.commandN, [])
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    58
  | T.Keyword       => (Markup.keywordN, [])
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    59
  | T.Ident         => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    60
  | T.LongIdent     => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    61
  | T.SymIdent      => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    62
  | T.Var           => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    63
  | T.TypeIdent     => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    64
  | T.TypeVar       => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    65
  | T.Nat           => Markup.ident
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    66
  | T.String        => Markup.string
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    67
  | T.AltString     => Markup.altstring
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    68
  | T.Verbatim      => Markup.verbatim
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    69
  | T.Space         => Markup.none
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    70
  | T.Comment       => Markup.comment
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    71
  | T.InternalValue => Markup.none
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    72
  | T.Malformed     => Markup.malformed
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    73
  | T.Error _       => Markup.malformed
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    74
  | T.Sync          => Markup.control
2828a276dc93 token_kind_markup: complete coverage;
wenzelm
parents: 27842
diff changeset
    75
  | T.EOF           => Markup.control;
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    76
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    77
in
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    78
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    79
fun present_token tok =
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    80
  Markup.enclose (token_kind_markup (T.kind_of tok)) (Output.output (T.unparse tok));
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
    81
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    82
fun report_token tok =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    83
  Position.report (token_kind_markup (T.kind_of tok)) (T.position_of tok);
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    84
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    85
end;
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    86
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    87
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    88
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
    89
(** spans **)
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
    90
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    91
(* type span *)
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    92
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    93
datatype span_kind = Command of string | Ignored | Malformed;
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    94
datatype span = Span of span_kind * OuterLex.token list;
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
    95
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    96
fun span_kind (Span (k, _)) = k;
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    97
fun span_content (Span (_, toks)) = toks;
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    98
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
    99
fun span_range span =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   100
  (case span_content span of
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   101
    [] => (Position.none, Position.none)
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   102
  | toks =>
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   103
      let
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   104
        val start_pos = T.position_of (hd toks);
27756
24d0e890b432 T.end_position_of;
wenzelm
parents: 27665
diff changeset
   105
        val end_pos = T.end_position_of (List.last toks);
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   106
      in (start_pos, end_pos) end);
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   107
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   108
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   109
(* parse *)
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
   110
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   111
local
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   112
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   113
val is_whitespace = T.is_kind T.Space orf T.is_kind T.Comment;
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   114
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   115
val body = Scan.unless (Scan.many is_whitespace -- Scan.ahead (P.command || P.eof)) P.not_eof;
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
   116
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   117
val span =
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   118
  Scan.ahead P.command -- P.not_eof -- Scan.repeat body
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   119
    >> (fn ((name, c), bs) => Span (Command name, c :: bs)) ||
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   120
  Scan.many1 is_whitespace >> (fn toks => Span (Ignored, toks)) ||
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   121
  Scan.repeat1 body >> (fn toks => Span (Malformed, toks));
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
   122
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
   123
in
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
   124
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   125
fun span_source src = Source.source T.stopper (Scan.bulk span) NONE src;
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   126
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   127
end;
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   128
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   129
fun parse_spans lexs pos str =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   130
  Source.of_string str
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   131
  |> token_source lexs pos
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   132
  |> span_source
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   133
  |> Source.exhaust;
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   134
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   135
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   136
(* present *)
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   137
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   138
local
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   139
27665
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   140
fun kind_markup (Command name) = Markup.command_span name
b9e54ba563b3 renamed item to span, renamed contructors;
wenzelm
parents: 27353
diff changeset
   141
  | kind_markup Ignored = Markup.ignored_span
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   142
  | kind_markup Malformed = Markup.malformed_span;
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   143
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   144
in
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   145
27842
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   146
fun present_span span =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   147
  Markup.enclose (kind_markup (span_kind span)) (implode (map present_token (span_content span)));
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   148
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   149
fun report_span span =
6c35d50d309f abstract type span, tuned interfaces;
wenzelm
parents: 27770
diff changeset
   150
  Position.report (kind_markup (span_kind span)) (Position.encode_range (span_range span));
23803
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   151
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   152
end;
11bf7af10ec8 tuned signature;
wenzelm
parents: 23790
diff changeset
   153
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   154
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   155
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   156
(** units: commands with proof **)
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   157
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   158
(* scanning spans *)
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   159
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   160
val eof = Span (Command "", []);
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   161
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   162
fun is_eof (Span (Command "", _)) = true
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   163
  | is_eof _ = false;
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   164
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   165
val not_eof = not o is_eof;
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   166
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   167
val stopper = Scan.stopper (K eof) is_eof;
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   168
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   169
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   170
(* unit_source *)
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   171
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   172
local
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   173
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   174
fun command_with pred = Scan.one (fn (Span (Command name, _)) => pred name | _ => false);
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   175
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   176
val proof = Scan.pass 1 (Scan.repeat (Scan.depend (fn d =>
28454
c63168db774c unit_source: more rigid parsing, stop after final qed;
wenzelm
parents: 28438
diff changeset
   177
  if d <= 0 then Scan.fail
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   178
  else
28454
c63168db774c unit_source: more rigid parsing, stop after final qed;
wenzelm
parents: 28438
diff changeset
   179
    command_with K.is_qed_global >> pair ~1 ||
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   180
    command_with K.is_proof_goal >> pair (d + 1) ||
28454
c63168db774c unit_source: more rigid parsing, stop after final qed;
wenzelm
parents: 28438
diff changeset
   181
    (if d = 0 then Scan.fail else command_with K.is_qed >> pair (d - 1)) ||
28438
32bb6b4eb390 unit_source: explicit treatment of 'oops' proofs;
wenzelm
parents: 28434
diff changeset
   182
    Scan.unless (command_with K.is_theory) (Scan.one not_eof) >> pair d)) -- Scan.state);
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   183
28438
32bb6b4eb390 unit_source: explicit treatment of 'oops' proofs;
wenzelm
parents: 28434
diff changeset
   184
val unit =
28454
c63168db774c unit_source: more rigid parsing, stop after final qed;
wenzelm
parents: 28438
diff changeset
   185
  command_with K.is_theory_goal -- proof >> (fn (a, (bs, d)) => (a, bs, d >= 0)) ||
28438
32bb6b4eb390 unit_source: explicit treatment of 'oops' proofs;
wenzelm
parents: 28434
diff changeset
   186
  Scan.one not_eof >> (fn a => (a, [], true));
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   187
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   188
in
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   189
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   190
fun unit_source src = Source.source stopper (Scan.bulk unit) NONE src;
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   191
23726
2ebecff57b17 Basic editing of theory sources.
wenzelm
parents:
diff changeset
   192
end;
28434
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   193
56f0951f4d26 added unit_source: commands with proof;
wenzelm
parents: 27863
diff changeset
   194
end;