| author | wenzelm |
| Sat, 16 Nov 2013 22:17:45 +0100 | |
| changeset 54458 | 96ccc8972fc7 |
| parent 54451 | 459cf6ee254e |
| child 54520 | cee77d2e9582 |
| permissions | -rw-r--r-- |
|
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 | 2 |
Author: Makarius |
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 | 5 |
*) |
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 | 8 |
sig |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
9 |
val parse_tokens: Scan.lexicon * Scan.lexicon -> Position.T -> string -> Token.T list |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
10 |
val reports_of_tokens: Token.T list -> bool * (Position.report * string) list |
|
40131
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
wenzelm
parents:
39507
diff
changeset
|
11 |
val present_token: Token.T -> Output.output |
| 48878 | 12 |
datatype span_kind = Command of string * Position.T | Ignored | Malformed |
|
48867
e9beabf045ab
some support for inlining file content into outer syntax token language;
wenzelm
parents:
48865
diff
changeset
|
13 |
datatype span = Span of span_kind * Token.T list |
| 27842 | 14 |
val span_kind: span -> span_kind |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
15 |
val span_content: span -> Token.T list |
| 48865 | 16 |
val present_span: span -> Output.output |
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
17 |
val parse_spans: Token.T list -> span list |
| 54451 | 18 |
val resolve_files: (string -> Path.T * Position.T -> Token.file list) -> span -> span |
| 51225 | 19 |
datatype 'a element = Element of 'a * ('a element list * 'a) option
|
| 51321 | 20 |
val atom: 'a -> 'a element |
| 51225 | 21 |
val map_element: ('a -> 'b) -> 'a element -> 'b element
|
22 |
val flat_element: 'a element -> 'a list |
|
|
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51267
diff
changeset
|
23 |
val last_element: 'a element -> 'a |
| 51225 | 24 |
val parse_elements: span list -> span element list |
| 23726 | 25 |
end; |
26 |
||
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37197
diff
changeset
|
27 |
structure Thy_Syntax: THY_SYNTAX = |
| 23726 | 28 |
struct |
29 |
||
| 23803 | 30 |
(** tokens **) |
31 |
||
32 |
(* parse *) |
|
| 23726 | 33 |
|
|
40523
1050315f6ee2
simplified/robustified treatment of malformed symbols, which are now fully internalized (total Symbol.explode etc.);
wenzelm
parents:
40290
diff
changeset
|
34 |
fun parse_tokens lexs pos = |
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
35 |
Source.of_string #> |
|
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
36 |
Symbol.source #> |
|
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
37 |
Token.source {do_recover = SOME false} (K lexs) pos #>
|
|
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
38 |
Source.exhaust; |
| 23726 | 39 |
|
40 |
||
| 23803 | 41 |
(* present *) |
| 23726 | 42 |
|
43 |
local |
|
44 |
||
45 |
val token_kind_markup = |
|
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
46 |
fn Token.Command => (Markup.command, "") |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
47 |
| Token.Keyword => (Markup.keyword, "") |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
48 |
| Token.Ident => (Markup.empty, "") |
|
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
49 |
| Token.LongIdent => (Markup.empty, "") |
|
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
50 |
| Token.SymIdent => (Markup.empty, "") |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
51 |
| Token.Var => (Markup.var, "") |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
52 |
| Token.TypeIdent => (Markup.tfree, "") |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
53 |
| Token.TypeVar => (Markup.tvar, "") |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
54 |
| Token.Nat => (Markup.empty, "") |
|
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
55 |
| Token.Float => (Markup.empty, "") |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
56 |
| Token.String => (Markup.string, "") |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
57 |
| Token.AltString => (Markup.altstring, "") |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
58 |
| Token.Verbatim => (Markup.verbatim, "") |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
59 |
| Token.Space => (Markup.empty, "") |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
60 |
| Token.Comment => (Markup.comment, "") |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
61 |
| Token.InternalValue => (Markup.empty, "") |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
62 |
| Token.Error msg => (Markup.bad, msg) |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
63 |
| Token.Sync => (Markup.control, "") |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
64 |
| Token.EOF => (Markup.control, ""); |
| 23726 | 65 |
|
| 37192 | 66 |
fun token_markup tok = |
|
50238
98d35a7368bd
more uniform Symbol.is_ascii_identifier in ML/Scala;
wenzelm
parents:
50201
diff
changeset
|
67 |
if Token.keyword_with (not o Symbol.is_ascii_identifier) tok |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
68 |
then (Markup.operator, "") |
|
37197
953fc4983439
more detailed token markup, including command kind as sub_kind;
wenzelm
parents:
37193
diff
changeset
|
69 |
else |
|
953fc4983439
more detailed token markup, including command kind as sub_kind;
wenzelm
parents:
37193
diff
changeset
|
70 |
let |
|
953fc4983439
more detailed token markup, including command kind as sub_kind;
wenzelm
parents:
37193
diff
changeset
|
71 |
val kind = Token.kind_of tok; |
|
953fc4983439
more detailed token markup, including command kind as sub_kind;
wenzelm
parents:
37193
diff
changeset
|
72 |
val props = |
|
38471
0924654b8163
report command token name instead of kind, which can be retrieved later via Outer_Syntax.keyword_kind;
wenzelm
parents:
38422
diff
changeset
|
73 |
if kind = Token.Command |
|
0924654b8163
report command token name instead of kind, which can be retrieved later via Outer_Syntax.keyword_kind;
wenzelm
parents:
38422
diff
changeset
|
74 |
then Markup.properties [(Markup.nameN, Token.content_of tok)] |
|
37197
953fc4983439
more detailed token markup, including command kind as sub_kind;
wenzelm
parents:
37193
diff
changeset
|
75 |
else I; |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
76 |
val (markup, txt) = token_kind_markup kind; |
|
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
77 |
in (props markup, txt) end; |
| 37192 | 78 |
|
|
48749
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
79 |
fun reports_of_token tok = |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
80 |
let |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
81 |
val malformed_symbols = |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
82 |
Symbol_Pos.explode (Token.source_position_of tok) |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
83 |
|> map_filter (fn (sym, pos) => |
|
48756
1c843142758e
sneak message into "bad" markup as property -- to be displayed after YXML parsing;
wenzelm
parents:
48752
diff
changeset
|
84 |
if Symbol.is_malformed sym |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
48878
diff
changeset
|
85 |
then SOME ((pos, Markup.bad), "Malformed symbolic character") else NONE); |
|
48749
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
86 |
val is_malformed = Token.is_error tok orelse not (null malformed_symbols); |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
87 |
val (markup, txt) = token_markup tok; |
|
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
88 |
val reports = ((Token.position_of tok, markup), txt) :: malformed_symbols; |
|
48749
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
89 |
in (is_malformed, reports) end; |
| 40528 | 90 |
|
| 23803 | 91 |
in |
92 |
||
|
48749
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
93 |
fun reports_of_tokens toks = |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
94 |
let val results = map reports_of_token toks |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
95 |
in (exists fst results, maps snd results) end; |
|
c197b3c3e7fa
some attempts to keep malformed syntax errors focussed, without too much red spilled onto the document view;
wenzelm
parents:
46811
diff
changeset
|
96 |
|
| 23726 | 97 |
fun present_token tok = |
|
48768
abc45de5bb22
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
wenzelm
parents:
48756
diff
changeset
|
98 |
Markup.enclose (fst (token_markup tok)) (Output.output (Token.unparse tok)); |
| 23726 | 99 |
|
| 23803 | 100 |
end; |
101 |
||
102 |
||
103 |
||
| 27665 | 104 |
(** spans **) |
105 |
||
| 27842 | 106 |
(* type span *) |
107 |
||
| 48878 | 108 |
datatype span_kind = Command of string * Position.T | Ignored | Malformed; |
|
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
109 |
datatype span = Span of span_kind * Token.T list; |
| 23803 | 110 |
|
| 27842 | 111 |
fun span_kind (Span (k, _)) = k; |
112 |
fun span_content (Span (_, toks)) = toks; |
|
113 |
||
| 48865 | 114 |
val present_span = implode o map present_token o span_content; |
115 |
||
| 23803 | 116 |
|
117 |
(* parse *) |
|
| 23726 | 118 |
|
| 23803 | 119 |
local |
120 |
||
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
121 |
fun make_span toks = |
|
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
122 |
if not (null toks) andalso Token.is_command (hd toks) then |
| 48878 | 123 |
Span (Command (Token.content_of (hd toks), Token.position_of (hd toks)), toks) |
| 51267 | 124 |
else if forall Token.is_improper toks then Span (Ignored, toks) |
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
125 |
else Span (Malformed, toks); |
| 23726 | 126 |
|
|
53843
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
127 |
fun flush (result, span, improper) = |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
128 |
result |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
129 |
|> not (null span) ? cons (rev span) |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
130 |
|> not (null improper) ? cons (rev improper); |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
131 |
|
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
132 |
fun parse tok (result, span, improper) = |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
133 |
if Token.is_command tok then (flush (result, span, improper), [tok], []) |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
134 |
else if Token.is_improper tok then (result, span, tok :: improper) |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
135 |
else (result, tok :: (improper @ span), []); |
| 23726 | 136 |
|
137 |
in |
|
138 |
||
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
139 |
fun parse_spans toks = |
|
53843
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
140 |
fold parse toks ([], [], []) |
|
88c6e630c15f
clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents:
51423
diff
changeset
|
141 |
|> flush |> rev |> map make_span; |
| 23803 | 142 |
|
143 |
end; |
|
144 |
||
145 |
||
| 54451 | 146 |
(* inlined files *) |
147 |
||
148 |
local |
|
149 |
||
150 |
fun clean ((i1, t1) :: (i2, t2) :: toks) = |
|
151 |
if Token.keyword_with (fn s => s = "%" orelse s = "--") t1 then clean toks |
|
152 |
else (i1, t1) :: clean ((i2, t2) :: toks) |
|
153 |
| clean toks = toks; |
|
154 |
||
155 |
fun clean_tokens toks = |
|
156 |
((0 upto length toks - 1) ~~ toks) |
|
157 |
|> filter (fn (_, tok) => Token.is_proper tok) |
|
158 |
|> clean; |
|
159 |
||
160 |
fun find_file toks = |
|
161 |
rev (clean_tokens toks) |> get_first (fn (i, tok) => |
|
162 |
if Token.is_name tok then |
|
163 |
SOME (i, (Path.explode (Token.content_of tok), Token.position_of tok)) |
|
164 |
handle ERROR msg => error (msg ^ Token.pos_of tok) |
|
165 |
else NONE); |
|
166 |
||
167 |
in |
|
168 |
||
169 |
fun resolve_files read_files span = |
|
170 |
(case span of |
|
171 |
Span (Command (cmd, pos), toks) => |
|
172 |
if Keyword.is_theory_load cmd then |
|
173 |
(case find_file toks of |
|
174 |
NONE => error ("Bad file argument of command " ^ quote cmd ^ Position.here pos)
|
|
175 |
| SOME (i, path) => |
|
176 |
let |
|
177 |
val toks' = toks |> map_index (fn (j, tok) => |
|
178 |
if i = j then Token.put_files (read_files cmd path) tok |
|
179 |
else tok); |
|
180 |
in Span (Command (cmd, pos), toks') end) |
|
181 |
else span |
|
182 |
| _ => span); |
|
183 |
||
184 |
end; |
|
185 |
||
186 |
||
| 28434 | 187 |
|
| 43621 | 188 |
(** specification elements: commands with optional proof **) |
189 |
||
| 51225 | 190 |
datatype 'a element = Element of 'a * ('a element list * 'a) option;
|
191 |
||
192 |
fun element (a, b) = Element (a, SOME b); |
|
193 |
fun atom a = Element (a, NONE); |
|
| 43621 | 194 |
|
| 51225 | 195 |
fun map_element f (Element (a, NONE)) = Element (f a, NONE) |
196 |
| map_element f (Element (a, SOME (elems, b))) = |
|
197 |
Element (f a, SOME ((map o map_element) f elems, f b)); |
|
198 |
||
199 |
fun flat_element (Element (a, NONE)) = [a] |
|
200 |
| flat_element (Element (a, SOME (elems, b))) = a :: maps flat_element elems @ [b]; |
|
| 43621 | 201 |
|
|
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51267
diff
changeset
|
202 |
fun last_element (Element (a, NONE)) = a |
|
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51267
diff
changeset
|
203 |
| last_element (Element (_, SOME (_, b))) = b; |
|
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51267
diff
changeset
|
204 |
|
| 28434 | 205 |
|
206 |
(* scanning spans *) |
|
207 |
||
| 48878 | 208 |
val eof = Span (Command ("", Position.none), []);
|
| 28434 | 209 |
|
| 48878 | 210 |
fun is_eof (Span (Command ("", _), _)) = true
|
| 28434 | 211 |
| is_eof _ = false; |
212 |
||
213 |
val not_eof = not o is_eof; |
|
214 |
||
215 |
val stopper = Scan.stopper (K eof) is_eof; |
|
216 |
||
217 |
||
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
218 |
(* parse *) |
| 28434 | 219 |
|
220 |
local |
|
221 |
||
| 48878 | 222 |
fun command_with pred = |
223 |
Scan.one (fn (Span (Command (name, _), _)) => pred name | _ => false); |
|
| 28434 | 224 |
|
| 51225 | 225 |
val proof_atom = |
226 |
Scan.one (fn (Span (Command (name, _), _)) => Keyword.is_proof_body name | _ => true) >> atom; |
|
| 28434 | 227 |
|
| 51225 | 228 |
fun proof_element x = (command_with Keyword.is_proof_goal -- proof_rest >> element || proof_atom) x |
229 |
and proof_rest x = (Scan.repeat proof_element -- command_with Keyword.is_qed) x; |
|
230 |
||
231 |
val other_element = |
|
232 |
command_with Keyword.is_theory_goal -- proof_rest >> element || |
|
233 |
Scan.one not_eof >> atom; |
|
| 28434 | 234 |
|
235 |
in |
|
236 |
||
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
237 |
val parse_elements = |
|
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
238 |
Source.of_list #> |
| 51225 | 239 |
Source.source stopper (Scan.bulk other_element) NONE #> |
|
46811
03a2dc9e0624
clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents:
45666
diff
changeset
|
240 |
Source.exhaust; |
| 28434 | 241 |
|
| 23726 | 242 |
end; |
| 28434 | 243 |
|
244 |
end; |