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