author | wenzelm |
Thu, 28 Jan 2021 14:20:37 +0100 | |
changeset 73199 | d300574cee4e |
parent 73178 | 7e70d7dd1baa |
child 73246 | b9c480878663 |
permissions | -rw-r--r-- |
69222 | 1 |
(* Title: Tools/Haskell/Haskell.thy |
2 |
Author: Makarius |
|
69225 | 3 |
|
4 |
Support for Isabelle tools in Haskell. |
|
69222 | 5 |
*) |
6 |
||
7 |
theory Haskell |
|
8 |
imports Pure |
|
9 |
begin |
|
10 |
||
69490 | 11 |
generate_file "Isabelle/Symbol.hs" = \<open> |
12 |
{- Title: Isabelle/Symbols.hs |
|
13 |
Author: Makarius |
|
14 |
LICENSE: BSD 3-clause (Isabelle) |
|
15 |
||
16 |
Isabelle text symbols. |
|
17 |
-} |
|
18 |
||
19 |
module Isabelle.Symbol where |
|
20 |
||
21 |
{- ASCII characters -} |
|
22 |
||
23 |
is_ascii_letter :: Char -> Bool |
|
24 |
is_ascii_letter c = 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' |
|
25 |
||
26 |
is_ascii_digit :: Char -> Bool |
|
27 |
is_ascii_digit c = '0' <= c && c <= '9' |
|
28 |
||
29 |
is_ascii_hex :: Char -> Bool |
|
30 |
is_ascii_hex c = '0' <= c && c <= '9' || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f' |
|
31 |
||
32 |
is_ascii_quasi :: Char -> Bool |
|
33 |
is_ascii_quasi c = c == '_' || c == '\'' |
|
34 |
||
35 |
is_ascii_blank :: Char -> Bool |
|
36 |
is_ascii_blank c = c `elem` " \t\n\11\f\r" |
|
37 |
||
38 |
is_ascii_line_terminator :: Char -> Bool |
|
39 |
is_ascii_line_terminator c = c == '\r' || c == '\n' |
|
40 |
||
41 |
is_ascii_letdig :: Char -> Bool |
|
42 |
is_ascii_letdig c = is_ascii_letter c || is_ascii_digit c || is_ascii_quasi c |
|
43 |
||
44 |
is_ascii_identifier :: String -> Bool |
|
45 |
is_ascii_identifier s = |
|
46 |
not (null s) && is_ascii_letter (head s) && all is_ascii_letdig s |
|
47 |
\<close> |
|
48 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
49 |
generate_file "Isabelle/Library.hs" = \<open> |
69445 | 50 |
{- Title: Isabelle/Library.hs |
69225 | 51 |
Author: Makarius |
52 |
LICENSE: BSD 3-clause (Isabelle) |
|
53 |
||
54 |
Basic library of Isabelle idioms. |
|
69280 | 55 |
|
56 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/basics.ML\<close>, \<^file>\<open>$ISABELLE_HOME/src/Pure/library.ML\<close>. |
|
69225 | 57 |
-} |
58 |
||
69240 | 59 |
module Isabelle.Library ( |
60 |
(|>), (|->), (#>), (#->), |
|
61 |
||
62 |
the, the_default, |
|
63 |
||
64 |
fold, fold_rev, single, map_index, get_index, |
|
65 |
||
69477 | 66 |
proper_string, quote, space_implode, commas, commas_quote, cat_lines, |
69453 | 67 |
space_explode, split_lines, trim_line, clean_name) |
69225 | 68 |
where |
69 |
||
69453 | 70 |
import qualified Data.List as List |
71 |
import qualified Data.List.Split as Split |
|
69491 | 72 |
import qualified Isabelle.Symbol as Symbol |
69234 | 73 |
|
74 |
||
69225 | 75 |
{- functions -} |
76 |
||
77 |
(|>) :: a -> (a -> b) -> b |
|
78 |
x |> f = f x |
|
79 |
||
80 |
(|->) :: (a, b) -> (a -> b -> c) -> c |
|
81 |
(x, y) |-> f = f x y |
|
82 |
||
83 |
(#>) :: (a -> b) -> (b -> c) -> a -> c |
|
84 |
(f #> g) x = x |> f |> g |
|
85 |
||
86 |
(#->) :: (a -> (c, b)) -> (c -> b -> d) -> a -> d |
|
87 |
(f #-> g) x = x |> f |-> g |
|
88 |
||
89 |
||
69234 | 90 |
{- options -} |
91 |
||
69240 | 92 |
the :: Maybe a -> a |
93 |
the (Just x) = x |
|
94 |
the Nothing = error "the Nothing" |
|
95 |
||
69234 | 96 |
the_default :: a -> Maybe a -> a |
97 |
the_default x Nothing = x |
|
98 |
the_default _ (Just y) = y |
|
99 |
||
100 |
||
69225 | 101 |
{- lists -} |
102 |
||
103 |
fold :: (a -> b -> b) -> [a] -> b -> b |
|
104 |
fold _ [] y = y |
|
105 |
fold f (x : xs) y = fold f xs (f x y) |
|
106 |
||
107 |
fold_rev :: (a -> b -> b) -> [a] -> b -> b |
|
108 |
fold_rev _ [] y = y |
|
109 |
fold_rev f (x : xs) y = f x (fold_rev f xs y) |
|
110 |
||
111 |
single :: a -> [a] |
|
112 |
single x = [x] |
|
113 |
||
69240 | 114 |
map_index :: ((Int, a) -> b) -> [a] -> [b] |
115 |
map_index f = map_aux 0 |
|
116 |
where |
|
117 |
map_aux _ [] = [] |
|
118 |
map_aux i (x : xs) = f (i, x) : map_aux (i + 1) xs |
|
119 |
||
120 |
get_index :: (a -> Maybe b) -> [a] -> Maybe (Int, b) |
|
121 |
get_index f = get_aux 0 |
|
122 |
where |
|
123 |
get_aux _ [] = Nothing |
|
124 |
get_aux i (x : xs) = |
|
125 |
case f x of |
|
126 |
Nothing -> get_aux (i + 1) xs |
|
127 |
Just y -> Just (i, y) |
|
128 |
||
69225 | 129 |
|
130 |
{- strings -} |
|
131 |
||
69477 | 132 |
proper_string :: String -> Maybe String |
133 |
proper_string s = if null s then Nothing else Just s |
|
134 |
||
69225 | 135 |
quote :: String -> String |
136 |
quote s = "\"" ++ s ++ "\"" |
|
137 |
||
69453 | 138 |
space_implode :: String -> [String] -> String |
139 |
space_implode = List.intercalate |
|
140 |
||
141 |
commas, commas_quote :: [String] -> String |
|
142 |
commas = space_implode ", " |
|
143 |
commas_quote = commas . map quote |
|
144 |
||
145 |
cat_lines :: [String] -> String |
|
146 |
cat_lines = space_implode "\n" |
|
147 |
||
148 |
||
149 |
space_explode :: Char -> String -> [String] |
|
150 |
space_explode c = Split.split (Split.dropDelims (Split.whenElt (== c))) |
|
151 |
||
152 |
split_lines :: String -> [String] |
|
153 |
split_lines = space_explode '\n' |
|
154 |
||
69225 | 155 |
trim_line :: String -> String |
156 |
trim_line line = |
|
69491 | 157 |
if not (null line) && Symbol.is_ascii_line_terminator (last line) then |
69486 | 158 |
case reverse line of |
159 |
'\n' : '\r' : rest -> reverse rest |
|
160 |
'\r' : rest -> reverse rest |
|
161 |
'\n' : rest -> reverse rest |
|
162 |
_ -> line |
|
163 |
else line |
|
69288 | 164 |
|
165 |
clean_name :: String -> String |
|
166 |
clean_name = reverse #> dropWhile (== '_') #> reverse |
|
69225 | 167 |
\<close> |
168 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
169 |
generate_file "Isabelle/Value.hs" = \<open> |
69233 | 170 |
{- Title: Haskell/Tools/Value.hs |
171 |
Author: Makarius |
|
172 |
LICENSE: BSD 3-clause (Isabelle) |
|
173 |
||
174 |
Plain values, represented as string. |
|
69280 | 175 |
|
176 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/value.ML\<close>. |
|
69233 | 177 |
-} |
178 |
||
179 |
module Isabelle.Value |
|
69452 | 180 |
(print_bool, parse_bool, parse_nat, print_int, parse_int, print_real, parse_real) |
69233 | 181 |
where |
182 |
||
183 |
import qualified Data.List as List |
|
184 |
import qualified Text.Read as Read |
|
185 |
||
186 |
||
187 |
{- bool -} |
|
188 |
||
189 |
print_bool :: Bool -> String |
|
190 |
print_bool True = "true" |
|
191 |
print_bool False = "false" |
|
192 |
||
193 |
parse_bool :: String -> Maybe Bool |
|
194 |
parse_bool "true" = Just True |
|
195 |
parse_bool "false" = Just False |
|
196 |
parse_bool _ = Nothing |
|
197 |
||
198 |
||
69452 | 199 |
{- nat -} |
200 |
||
201 |
parse_nat :: String -> Maybe Int |
|
202 |
parse_nat s = |
|
203 |
case Read.readMaybe s of |
|
204 |
Just n | n >= 0 -> Just n |
|
205 |
_ -> Nothing |
|
206 |
||
207 |
||
69233 | 208 |
{- int -} |
209 |
||
210 |
print_int :: Int -> String |
|
211 |
print_int = show |
|
212 |
||
213 |
parse_int :: String -> Maybe Int |
|
214 |
parse_int = Read.readMaybe |
|
215 |
||
216 |
||
217 |
{- real -} |
|
218 |
||
219 |
print_real :: Double -> String |
|
220 |
print_real x = |
|
221 |
let s = show x in |
|
222 |
case span (/= '.') s of |
|
223 |
(a, '.' : b) | List.all (== '0') b -> a |
|
224 |
_ -> s |
|
225 |
||
226 |
parse_real :: String -> Maybe Double |
|
227 |
parse_real = Read.readMaybe |
|
228 |
\<close> |
|
229 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
230 |
generate_file "Isabelle/Buffer.hs" = \<open> |
69445 | 231 |
{- Title: Isabelle/Buffer.hs |
69225 | 232 |
Author: Makarius |
233 |
LICENSE: BSD 3-clause (Isabelle) |
|
234 |
||
235 |
Efficient text buffers. |
|
69280 | 236 |
|
237 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/buffer.ML\<close>. |
|
69225 | 238 |
-} |
69222 | 239 |
|
69225 | 240 |
module Isabelle.Buffer (T, empty, add, content) |
241 |
where |
|
242 |
||
69474 | 243 |
import Isabelle.Library |
244 |
||
245 |
||
246 |
newtype T = Buffer [Char] |
|
69225 | 247 |
|
248 |
empty :: T |
|
249 |
empty = Buffer [] |
|
250 |
||
251 |
add :: String -> T -> T |
|
69474 | 252 |
add s (Buffer cs) = Buffer (fold (:) s cs) |
69225 | 253 |
|
254 |
content :: T -> String |
|
69474 | 255 |
content (Buffer cs) = reverse cs |
69225 | 256 |
\<close> |
257 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
258 |
generate_file "Isabelle/Properties.hs" = \<open> |
69445 | 259 |
{- Title: Isabelle/Properties.hs |
69225 | 260 |
Author: Makarius |
261 |
LICENSE: BSD 3-clause (Isabelle) |
|
262 |
||
263 |
Property lists. |
|
69280 | 264 |
|
265 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/properties.ML\<close>. |
|
69225 | 266 |
-} |
267 |
||
69477 | 268 |
module Isabelle.Properties (Entry, T, defined, get, get_value, put, remove) |
69225 | 269 |
where |
270 |
||
271 |
import qualified Data.List as List |
|
272 |
||
273 |
||
274 |
type Entry = (String, String) |
|
275 |
type T = [Entry] |
|
276 |
||
277 |
defined :: T -> String -> Bool |
|
278 |
defined props name = any (\(a, _) -> a == name) props |
|
279 |
||
280 |
get :: T -> String -> Maybe String |
|
281 |
get props name = List.lookup name props |
|
282 |
||
69477 | 283 |
get_value :: (String -> Maybe a) -> T -> String -> Maybe a |
284 |
get_value parse props name = |
|
285 |
case get props name of |
|
286 |
Nothing -> Nothing |
|
287 |
Just s -> parse s |
|
288 |
||
69225 | 289 |
put :: Entry -> T -> T |
290 |
put entry props = entry : remove (fst entry) props |
|
291 |
||
292 |
remove :: String -> T -> T |
|
293 |
remove name props = |
|
294 |
if defined props name then filter (\(a, _) -> a /= name) props |
|
295 |
else props |
|
296 |
\<close> |
|
297 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
298 |
generate_file "Isabelle/Markup.hs" = \<open> |
69226 | 299 |
{- Title: Haskell/Tools/Markup.hs |
69225 | 300 |
Author: Makarius |
301 |
LICENSE: BSD 3-clause (Isabelle) |
|
302 |
||
303 |
Quasi-abstract markup elements. |
|
69280 | 304 |
|
305 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/markup.ML\<close>. |
|
69225 | 306 |
-} |
307 |
||
73177 | 308 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
309 |
||
69234 | 310 |
module Isabelle.Markup ( |
311 |
T, empty, is_empty, properties, |
|
312 |
||
313 |
nameN, name, xnameN, xname, kindN, |
|
314 |
||
69315 | 315 |
bindingN, binding, entityN, entity, defN, refN, |
316 |
||
69288 | 317 |
completionN, completion, no_completionN, no_completion, |
318 |
||
69234 | 319 |
lineN, end_lineN, offsetN, end_offsetN, fileN, idN, positionN, position, |
320 |
||
69291 | 321 |
expressionN, expression, |
322 |
||
323 |
citationN, citation, |
|
324 |
||
71489 | 325 |
pathN, path, urlN, url, docN, doc, |
69291 | 326 |
|
69248 | 327 |
markupN, consistentN, unbreakableN, indentN, widthN, |
328 |
blockN, block, breakN, break, fbreakN, fbreak, itemN, item, |
|
329 |
||
69968
1a400b14fd3a
clarified spell-checking (see also 30233285270a);
wenzelm
parents:
69794
diff
changeset
|
330 |
wordsN, words, |
69234 | 331 |
|
332 |
tfreeN, tfree, tvarN, tvar, freeN, free, skolemN, skolem, boundN, bound, varN, var, |
|
333 |
numeralN, numeral, literalN, literal, delimiterN, delimiter, inner_stringN, inner_string, |
|
69320 | 334 |
inner_cartoucheN, inner_cartouche, |
69234 | 335 |
token_rangeN, token_range, |
336 |
sortingN, sorting, typingN, typing, class_parameterN, class_parameter, |
|
337 |
||
338 |
antiquotedN, antiquoted, antiquoteN, antiquote, |
|
339 |
||
340 |
paragraphN, paragraph, text_foldN, text_fold, |
|
341 |
||
342 |
keyword1N, keyword1, keyword2N, keyword2, keyword3N, keyword3, quasi_keywordN, quasi_keyword, |
|
343 |
improperN, improper, operatorN, operator, stringN, string, alt_stringN, alt_string, |
|
69320 | 344 |
verbatimN, verbatim, cartoucheN, cartouche, commentN, comment, comment1N, comment1, |
345 |
comment2N, comment2, comment3N, comment3, |
|
69234 | 346 |
|
70667 | 347 |
forkedN, forked, joinedN, joined, runningN, running, finishedN, finished, |
69794 | 348 |
failedN, failed, canceledN, canceled, initializedN, initialized, finalizedN, finalized, |
349 |
consolidatedN, consolidated, |
|
350 |
||
69234 | 351 |
writelnN, writeln, stateN, state, informationN, information, tracingN, tracing, |
352 |
warningN, warning, legacyN, legacy, errorN, error, reportN, report, no_reportN, no_report, |
|
353 |
||
354 |
intensifyN, intensify, |
|
355 |
Output, no_output) |
|
69225 | 356 |
where |
357 |
||
69248 | 358 |
import Prelude hiding (words, error, break) |
69234 | 359 |
|
360 |
import Isabelle.Library |
|
69225 | 361 |
import qualified Isabelle.Properties as Properties |
69248 | 362 |
import qualified Isabelle.Value as Value |
69225 | 363 |
|
364 |
||
69234 | 365 |
{- basic markup -} |
366 |
||
69225 | 367 |
type T = (String, Properties.T) |
368 |
||
369 |
empty :: T |
|
370 |
empty = ("", []) |
|
371 |
||
372 |
is_empty :: T -> Bool |
|
373 |
is_empty ("", _) = True |
|
374 |
is_empty _ = False |
|
375 |
||
69234 | 376 |
properties :: Properties.T -> T -> T |
377 |
properties more_props (elem, props) = |
|
378 |
(elem, fold_rev Properties.put more_props props) |
|
379 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
380 |
markup_elem :: String -> T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
381 |
markup_elem name = (name, []) |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
382 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
383 |
markup_string :: String -> String -> String -> T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
384 |
markup_string name prop = \s -> (name, [(prop, s)]) |
69234 | 385 |
|
386 |
||
387 |
{- misc properties -} |
|
388 |
||
389 |
nameN :: String |
|
390 |
nameN = \<open>Markup.nameN\<close> |
|
391 |
||
392 |
name :: String -> T -> T |
|
393 |
name a = properties [(nameN, a)] |
|
394 |
||
395 |
xnameN :: String |
|
396 |
xnameN = \<open>Markup.xnameN\<close> |
|
397 |
||
398 |
xname :: String -> T -> T |
|
399 |
xname a = properties [(xnameN, a)] |
|
400 |
||
401 |
kindN :: String |
|
402 |
kindN = \<open>Markup.kindN\<close> |
|
403 |
||
404 |
||
69315 | 405 |
{- formal entities -} |
406 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
407 |
bindingN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
408 |
bindingN = \<open>Markup.bindingN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
409 |
binding :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
410 |
binding = markup_elem bindingN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
411 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
412 |
entityN :: String |
69315 | 413 |
entityN = \<open>Markup.entityN\<close> |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
414 |
entity :: String -> String -> T |
69315 | 415 |
entity kind name = |
416 |
(entityN, |
|
417 |
(if null name then [] else [(nameN, name)]) ++ (if null kind then [] else [(kindN, kind)])) |
|
418 |
||
419 |
defN :: String |
|
420 |
defN = \<open>Markup.defN\<close> |
|
421 |
||
422 |
refN :: String |
|
423 |
refN = \<open>Markup.refN\<close> |
|
424 |
||
425 |
||
69288 | 426 |
{- completion -} |
427 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
428 |
completionN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
429 |
completionN = \<open>Markup.completionN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
430 |
completion :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
431 |
completion = markup_elem completionN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
432 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
433 |
no_completionN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
434 |
no_completionN = \<open>Markup.no_completionN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
435 |
no_completion :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
436 |
no_completion = markup_elem no_completionN |
69288 | 437 |
|
438 |
||
69234 | 439 |
{- position -} |
440 |
||
441 |
lineN, end_lineN :: String |
|
442 |
lineN = \<open>Markup.lineN\<close> |
|
443 |
end_lineN = \<open>Markup.end_lineN\<close> |
|
444 |
||
445 |
offsetN, end_offsetN :: String |
|
446 |
offsetN = \<open>Markup.offsetN\<close> |
|
447 |
end_offsetN = \<open>Markup.end_offsetN\<close> |
|
448 |
||
449 |
fileN, idN :: String |
|
450 |
fileN = \<open>Markup.fileN\<close> |
|
451 |
idN = \<open>Markup.idN\<close> |
|
452 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
453 |
positionN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
454 |
positionN = \<open>Markup.positionN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
455 |
position :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
456 |
position = markup_elem positionN |
69234 | 457 |
|
458 |
||
69291 | 459 |
{- expression -} |
460 |
||
461 |
expressionN :: String |
|
462 |
expressionN = \<open>Markup.expressionN\<close> |
|
463 |
||
464 |
expression :: String -> T |
|
465 |
expression kind = (expressionN, if kind == "" then [] else [(kindN, kind)]) |
|
466 |
||
467 |
||
468 |
{- citation -} |
|
469 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
470 |
citationN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
471 |
citationN = \<open>Markup.citationN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
472 |
citation :: String -> T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
473 |
citation = markup_string nameN citationN |
69291 | 474 |
|
475 |
||
476 |
{- external resources -} |
|
477 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
478 |
pathN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
479 |
pathN = \<open>Markup.pathN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
480 |
path :: String -> T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
481 |
path = markup_string pathN nameN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
482 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
483 |
urlN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
484 |
urlN = \<open>Markup.urlN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
485 |
url :: String -> T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
486 |
url = markup_string urlN nameN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
487 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
488 |
docN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
489 |
docN = \<open>Markup.docN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
490 |
doc :: String -> T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
491 |
doc = markup_string docN nameN |
69291 | 492 |
|
493 |
||
69248 | 494 |
{- pretty printing -} |
495 |
||
496 |
markupN, consistentN, unbreakableN, indentN :: String |
|
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
497 |
markupN = \<open>Markup.markupN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
498 |
consistentN = \<open>Markup.consistentN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
499 |
unbreakableN = \<open>Markup.unbreakableN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
500 |
indentN = \<open>Markup.indentN\<close> |
69248 | 501 |
|
502 |
widthN :: String |
|
503 |
widthN = \<open>Markup.widthN\<close> |
|
504 |
||
505 |
blockN :: String |
|
506 |
blockN = \<open>Markup.blockN\<close> |
|
507 |
block :: Bool -> Int -> T |
|
508 |
block c i = |
|
509 |
(blockN, |
|
510 |
(if c then [(consistentN, Value.print_bool c)] else []) ++ |
|
511 |
(if i /= 0 then [(indentN, Value.print_int i)] else [])) |
|
512 |
||
513 |
breakN :: String |
|
514 |
breakN = \<open>Markup.breakN\<close> |
|
515 |
break :: Int -> Int -> T |
|
516 |
break w i = |
|
517 |
(breakN, |
|
518 |
(if w /= 0 then [(widthN, Value.print_int w)] else []) ++ |
|
519 |
(if i /= 0 then [(indentN, Value.print_int i)] else [])) |
|
520 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
521 |
fbreakN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
522 |
fbreakN = \<open>Markup.fbreakN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
523 |
fbreak :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
524 |
fbreak = markup_elem fbreakN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
525 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
526 |
itemN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
527 |
itemN = \<open>Markup.itemN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
528 |
item :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
529 |
item = markup_elem itemN |
69248 | 530 |
|
531 |
||
69234 | 532 |
{- text properties -} |
533 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
534 |
wordsN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
535 |
wordsN = \<open>Markup.wordsN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
536 |
words :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
537 |
words = markup_elem wordsN |
69234 | 538 |
|
539 |
||
540 |
{- inner syntax -} |
|
541 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
542 |
tfreeN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
543 |
tfreeN = \<open>Markup.tfreeN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
544 |
tfree :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
545 |
tfree = markup_elem tfreeN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
546 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
547 |
tvarN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
548 |
tvarN = \<open>Markup.tvarN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
549 |
tvar :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
550 |
tvar = markup_elem tvarN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
551 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
552 |
freeN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
553 |
freeN = \<open>Markup.freeN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
554 |
free :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
555 |
free = markup_elem freeN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
556 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
557 |
skolemN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
558 |
skolemN = \<open>Markup.skolemN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
559 |
skolem :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
560 |
skolem = markup_elem skolemN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
561 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
562 |
boundN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
563 |
boundN = \<open>Markup.boundN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
564 |
bound :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
565 |
bound = markup_elem boundN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
566 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
567 |
varN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
568 |
varN = \<open>Markup.varN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
569 |
var :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
570 |
var = markup_elem varN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
571 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
572 |
numeralN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
573 |
numeralN = \<open>Markup.numeralN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
574 |
numeral :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
575 |
numeral = markup_elem numeralN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
576 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
577 |
literalN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
578 |
literalN = \<open>Markup.literalN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
579 |
literal :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
580 |
literal = markup_elem literalN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
581 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
582 |
delimiterN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
583 |
delimiterN = \<open>Markup.delimiterN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
584 |
delimiter :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
585 |
delimiter = markup_elem delimiterN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
586 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
587 |
inner_stringN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
588 |
inner_stringN = \<open>Markup.inner_stringN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
589 |
inner_string :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
590 |
inner_string = markup_elem inner_stringN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
591 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
592 |
inner_cartoucheN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
593 |
inner_cartoucheN = \<open>Markup.inner_cartoucheN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
594 |
inner_cartouche :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
595 |
inner_cartouche = markup_elem inner_cartoucheN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
596 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
597 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
598 |
token_rangeN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
599 |
token_rangeN = \<open>Markup.token_rangeN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
600 |
token_range :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
601 |
token_range = markup_elem token_rangeN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
602 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
603 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
604 |
sortingN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
605 |
sortingN = \<open>Markup.sortingN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
606 |
sorting :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
607 |
sorting = markup_elem sortingN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
608 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
609 |
typingN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
610 |
typingN = \<open>Markup.typingN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
611 |
typing :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
612 |
typing = markup_elem typingN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
613 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
614 |
class_parameterN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
615 |
class_parameterN = \<open>Markup.class_parameterN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
616 |
class_parameter :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
617 |
class_parameter = markup_elem class_parameterN |
69234 | 618 |
|
619 |
||
620 |
{- antiquotations -} |
|
621 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
622 |
antiquotedN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
623 |
antiquotedN = \<open>Markup.antiquotedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
624 |
antiquoted :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
625 |
antiquoted = markup_elem antiquotedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
626 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
627 |
antiquoteN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
628 |
antiquoteN = \<open>Markup.antiquoteN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
629 |
antiquote :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
630 |
antiquote = markup_elem antiquoteN |
69234 | 631 |
|
632 |
||
633 |
{- text structure -} |
|
634 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
635 |
paragraphN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
636 |
paragraphN = \<open>Markup.paragraphN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
637 |
paragraph :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
638 |
paragraph = markup_elem paragraphN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
639 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
640 |
text_foldN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
641 |
text_foldN = \<open>Markup.text_foldN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
642 |
text_fold :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
643 |
text_fold = markup_elem text_foldN |
69234 | 644 |
|
645 |
||
646 |
{- outer syntax -} |
|
647 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
648 |
keyword1N :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
649 |
keyword1N = \<open>Markup.keyword1N\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
650 |
keyword1 :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
651 |
keyword1 = markup_elem keyword1N |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
652 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
653 |
keyword2N :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
654 |
keyword2N = \<open>Markup.keyword2N\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
655 |
keyword2 :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
656 |
keyword2 = markup_elem keyword2N |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
657 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
658 |
keyword3N :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
659 |
keyword3N = \<open>Markup.keyword3N\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
660 |
keyword3 :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
661 |
keyword3 = markup_elem keyword3N |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
662 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
663 |
quasi_keywordN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
664 |
quasi_keywordN = \<open>Markup.quasi_keywordN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
665 |
quasi_keyword :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
666 |
quasi_keyword = markup_elem quasi_keywordN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
667 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
668 |
improperN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
669 |
improperN = \<open>Markup.improperN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
670 |
improper :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
671 |
improper = markup_elem improperN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
672 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
673 |
operatorN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
674 |
operatorN = \<open>Markup.operatorN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
675 |
operator :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
676 |
operator = markup_elem operatorN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
677 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
678 |
stringN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
679 |
stringN = \<open>Markup.stringN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
680 |
string :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
681 |
string = markup_elem stringN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
682 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
683 |
alt_stringN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
684 |
alt_stringN = \<open>Markup.alt_stringN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
685 |
alt_string :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
686 |
alt_string = markup_elem alt_stringN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
687 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
688 |
verbatimN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
689 |
verbatimN = \<open>Markup.verbatimN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
690 |
verbatim :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
691 |
verbatim = markup_elem verbatimN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
692 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
693 |
cartoucheN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
694 |
cartoucheN = \<open>Markup.cartoucheN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
695 |
cartouche :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
696 |
cartouche = markup_elem cartoucheN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
697 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
698 |
commentN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
699 |
commentN = \<open>Markup.commentN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
700 |
comment :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
701 |
comment = markup_elem commentN |
69234 | 702 |
|
703 |
||
69320 | 704 |
{- comments -} |
705 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
706 |
comment1N :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
707 |
comment1N = \<open>Markup.comment1N\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
708 |
comment1 :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
709 |
comment1 = markup_elem comment1N |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
710 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
711 |
comment2N :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
712 |
comment2N = \<open>Markup.comment2N\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
713 |
comment2 :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
714 |
comment2 = markup_elem comment2N |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
715 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
716 |
comment3N :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
717 |
comment3N = \<open>Markup.comment3N\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
718 |
comment3 :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
719 |
comment3 = markup_elem comment3N |
69320 | 720 |
|
721 |
||
69793 | 722 |
{- command status -} |
723 |
||
70667 | 724 |
forkedN, joinedN, runningN, finishedN, failedN, canceledN, |
69793 | 725 |
initializedN, finalizedN, consolidatedN :: String |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
726 |
forkedN = \<open>Markup.forkedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
727 |
joinedN = \<open>Markup.joinedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
728 |
runningN = \<open>Markup.runningN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
729 |
finishedN = \<open>Markup.finishedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
730 |
failedN = \<open>Markup.failedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
731 |
canceledN = \<open>Markup.canceledN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
732 |
initializedN = \<open>Markup.initializedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
733 |
finalizedN = \<open>Markup.finalizedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
734 |
consolidatedN = \<open>Markup.consolidatedN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
735 |
|
70667 | 736 |
forked, joined, running, finished, failed, canceled, |
69793 | 737 |
initialized, finalized, consolidated :: T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
738 |
forked = markup_elem forkedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
739 |
joined = markup_elem joinedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
740 |
running = markup_elem runningN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
741 |
finished = markup_elem finishedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
742 |
failed = markup_elem failedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
743 |
canceled = markup_elem canceledN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
744 |
initialized = markup_elem initializedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
745 |
finalized = markup_elem finalizedN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
746 |
consolidated = markup_elem consolidatedN |
69793 | 747 |
|
748 |
||
69234 | 749 |
{- messages -} |
750 |
||
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
751 |
writelnN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
752 |
writelnN = \<open>Markup.writelnN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
753 |
writeln :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
754 |
writeln = markup_elem writelnN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
755 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
756 |
stateN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
757 |
stateN = \<open>Markup.stateN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
758 |
state :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
759 |
state = markup_elem stateN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
760 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
761 |
informationN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
762 |
informationN = \<open>Markup.informationN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
763 |
information :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
764 |
information = markup_elem informationN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
765 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
766 |
tracingN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
767 |
tracingN = \<open>Markup.tracingN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
768 |
tracing :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
769 |
tracing = markup_elem tracingN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
770 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
771 |
warningN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
772 |
warningN = \<open>Markup.warningN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
773 |
warning :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
774 |
warning = markup_elem warningN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
775 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
776 |
legacyN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
777 |
legacyN = \<open>Markup.legacyN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
778 |
legacy :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
779 |
legacy = markup_elem legacyN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
780 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
781 |
errorN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
782 |
errorN = \<open>Markup.errorN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
783 |
error :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
784 |
error = markup_elem errorN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
785 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
786 |
reportN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
787 |
reportN = \<open>Markup.reportN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
788 |
report :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
789 |
report = markup_elem reportN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
790 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
791 |
no_reportN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
792 |
no_reportN = \<open>Markup.no_reportN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
793 |
no_report :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
794 |
no_report = markup_elem no_reportN |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
795 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
796 |
intensifyN :: String |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
797 |
intensifyN = \<open>Markup.intensifyN\<close> |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
798 |
intensify :: T |
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
799 |
intensify = markup_elem intensifyN |
69234 | 800 |
|
801 |
||
802 |
{- output -} |
|
69225 | 803 |
|
804 |
type Output = (String, String) |
|
805 |
||
806 |
no_output :: Output |
|
807 |
no_output = ("", "") |
|
69222 | 808 |
\<close> |
809 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
810 |
generate_file "Isabelle/Completion.hs" = \<open> |
69445 | 811 |
{- Title: Isabelle/Completion.hs |
69288 | 812 |
Author: Makarius |
813 |
LICENSE: BSD 3-clause (Isabelle) |
|
814 |
||
815 |
Completion of names. |
|
816 |
||
817 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/completion.ML\<close>. |
|
818 |
-} |
|
819 |
||
69289 | 820 |
module Isabelle.Completion ( |
821 |
Name, T, names, none, make, markup_element, markup_report, make_report |
|
822 |
) where |
|
69288 | 823 |
|
824 |
import qualified Data.List as List |
|
825 |
||
826 |
import Isabelle.Library |
|
827 |
import qualified Isabelle.Properties as Properties |
|
828 |
import qualified Isabelle.Markup as Markup |
|
829 |
import qualified Isabelle.XML.Encode as Encode |
|
830 |
import qualified Isabelle.XML as XML |
|
831 |
import qualified Isabelle.YXML as YXML |
|
832 |
||
833 |
||
834 |
type Name = (String, (String, String)) -- external name, kind, internal name |
|
835 |
data T = Completion Properties.T Int [Name] -- position, total length, names |
|
836 |
||
837 |
names :: Int -> Properties.T -> [Name] -> T |
|
838 |
names limit props names = Completion props (length names) (take limit names) |
|
839 |
||
840 |
none :: T |
|
841 |
none = names 0 [] [] |
|
842 |
||
843 |
make :: Int -> (String, Properties.T) -> ((String -> Bool) -> [Name]) -> T |
|
844 |
make limit (name, props) make_names = |
|
845 |
if name /= "" && name /= "_" |
|
846 |
then names limit props (make_names $ List.isPrefixOf $ clean_name name) |
|
847 |
else none |
|
848 |
||
69289 | 849 |
markup_element :: T -> (Markup.T, XML.Body) |
850 |
markup_element (Completion props total names) = |
|
851 |
if not (null names) then |
|
852 |
let |
|
853 |
markup = Markup.properties props Markup.completion |
|
854 |
body = |
|
855 |
Encode.pair Encode.int |
|
856 |
(Encode.list (Encode.pair Encode.string (Encode.pair Encode.string Encode.string))) |
|
857 |
(total, names) |
|
858 |
in (markup, body) |
|
859 |
else (Markup.empty, []) |
|
69288 | 860 |
|
69289 | 861 |
markup_report :: [T] -> String |
862 |
markup_report [] = "" |
|
863 |
markup_report elems = |
|
69290 | 864 |
YXML.string_of $ XML.Elem (Markup.report, map (XML.Elem . markup_element) elems) |
69289 | 865 |
|
866 |
make_report :: Int -> (String, Properties.T) -> ((String -> Bool) -> [Name]) -> String |
|
867 |
make_report limit name_props make_names = |
|
868 |
markup_report [make limit name_props make_names] |
|
69288 | 869 |
\<close> |
870 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
871 |
generate_file "Isabelle/File.hs" = \<open> |
69445 | 872 |
{- Title: Isabelle/File.hs |
69278 | 873 |
Author: Makarius |
874 |
LICENSE: BSD 3-clause (Isabelle) |
|
875 |
||
69280 | 876 |
File-system operations. |
877 |
||
878 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/file.ML\<close>. |
|
69278 | 879 |
-} |
880 |
||
881 |
module Isabelle.File (setup, read, write, append) where |
|
882 |
||
883 |
import Prelude hiding (read) |
|
884 |
import qualified System.IO as IO |
|
885 |
||
886 |
setup :: IO.Handle -> IO () |
|
887 |
setup h = do |
|
888 |
IO.hSetEncoding h IO.utf8 |
|
889 |
IO.hSetNewlineMode h IO.noNewlineTranslation |
|
890 |
||
891 |
read :: IO.FilePath -> IO String |
|
892 |
read path = |
|
893 |
IO.withFile path IO.ReadMode (\h -> |
|
894 |
do setup h; IO.hGetContents h >>= \s -> length s `seq` return s) |
|
895 |
||
896 |
write :: IO.FilePath -> String -> IO () |
|
897 |
write path s = |
|
898 |
IO.withFile path IO.WriteMode (\h -> do setup h; IO.hPutStr h s) |
|
899 |
||
900 |
append :: IO.FilePath -> String -> IO () |
|
901 |
append path s = |
|
902 |
IO.withFile path IO.AppendMode (\h -> do setup h; IO.hPutStr h s) |
|
903 |
\<close> |
|
904 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
905 |
generate_file "Isabelle/XML.hs" = \<open> |
69445 | 906 |
{- Title: Isabelle/XML.hs |
69225 | 907 |
Author: Makarius |
908 |
LICENSE: BSD 3-clause (Isabelle) |
|
909 |
||
910 |
Untyped XML trees and representation of ML values. |
|
69280 | 911 |
|
912 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/xml.ML\<close>. |
|
69225 | 913 |
-} |
914 |
||
73177 | 915 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
916 |
||
69225 | 917 |
module Isabelle.XML (Attributes, Body, Tree(..), wrap_elem, unwrap_elem, content_of) |
918 |
where |
|
919 |
||
920 |
import Isabelle.Library |
|
921 |
import qualified Isabelle.Properties as Properties |
|
922 |
import qualified Isabelle.Markup as Markup |
|
923 |
import qualified Isabelle.Buffer as Buffer |
|
924 |
||
925 |
||
926 |
{- types -} |
|
927 |
||
928 |
type Attributes = Properties.T |
|
929 |
type Body = [Tree] |
|
69290 | 930 |
data Tree = Elem (Markup.T, Body) | Text String |
69225 | 931 |
|
932 |
||
933 |
{- wrapped elements -} |
|
934 |
||
69482 | 935 |
wrap_elem :: ((Markup.T, Body), [Tree]) -> Tree |
69236 | 936 |
wrap_elem (((a, atts), body1), body2) = |
69290 | 937 |
Elem ((\<open>XML.xml_elemN\<close>, (\<open>XML.xml_nameN\<close>, a) : atts), Elem ((\<open>XML.xml_bodyN\<close>, []), body1) : body2) |
69225 | 938 |
|
69482 | 939 |
unwrap_elem :: Tree -> Maybe ((Markup.T, Body), [Tree]) |
69236 | 940 |
unwrap_elem |
69290 | 941 |
(Elem ((\<open>XML.xml_elemN\<close>, (\<open>XML.xml_nameN\<close>, a) : atts), Elem ((\<open>XML.xml_bodyN\<close>, []), body1) : body2)) = |
69236 | 942 |
Just (((a, atts), body1), body2) |
69225 | 943 |
unwrap_elem _ = Nothing |
944 |
||
945 |
||
946 |
{- text content -} |
|
947 |
||
69482 | 948 |
add_content :: Tree -> Buffer.T -> Buffer.T |
69225 | 949 |
add_content tree = |
950 |
case unwrap_elem tree of |
|
951 |
Just (_, ts) -> fold add_content ts |
|
952 |
Nothing -> |
|
953 |
case tree of |
|
69290 | 954 |
Elem (_, ts) -> fold add_content ts |
69225 | 955 |
Text s -> Buffer.add s |
956 |
||
69482 | 957 |
content_of :: Body -> String |
69225 | 958 |
content_of body = Buffer.empty |> fold add_content body |> Buffer.content |
959 |
||
960 |
||
961 |
{- string representation -} |
|
962 |
||
963 |
encode '<' = "<" |
|
964 |
encode '>' = ">" |
|
965 |
encode '&' = "&" |
|
966 |
encode '\'' = "'" |
|
967 |
encode '\"' = """ |
|
968 |
encode c = [c] |
|
969 |
||
970 |
instance Show Tree where |
|
971 |
show tree = |
|
972 |
Buffer.empty |> show_tree tree |> Buffer.content |
|
973 |
where |
|
69290 | 974 |
show_tree (Elem ((name, atts), [])) = |
69225 | 975 |
Buffer.add "<" #> Buffer.add (show_elem name atts) #> Buffer.add "/>" |
69290 | 976 |
show_tree (Elem ((name, atts), ts)) = |
69225 | 977 |
Buffer.add "<" #> Buffer.add (show_elem name atts) #> Buffer.add ">" #> |
978 |
fold show_tree ts #> |
|
979 |
Buffer.add "</" #> Buffer.add name #> Buffer.add ">" |
|
980 |
show_tree (Text s) = Buffer.add (show_text s) |
|
981 |
||
982 |
show_elem name atts = |
|
983 |
unwords (name : map (\(a, x) -> a ++ "=\"" ++ show_text x ++ "\"") atts) |
|
984 |
||
985 |
show_text = concatMap encode |
|
986 |
\<close> |
|
987 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
988 |
generate_file "Isabelle/XML/Encode.hs" = \<open> |
69445 | 989 |
{- Title: Isabelle/XML/Encode.hs |
69240 | 990 |
Author: Makarius |
991 |
LICENSE: BSD 3-clause (Isabelle) |
|
992 |
||
993 |
XML as data representation language. |
|
69280 | 994 |
|
995 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/xml.ML\<close>. |
|
69240 | 996 |
-} |
997 |
||
73177 | 998 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
999 |
||
69240 | 1000 |
module Isabelle.XML.Encode ( |
70845 | 1001 |
A, T, V, P, |
69240 | 1002 |
|
1003 |
int_atom, bool_atom, unit_atom, |
|
1004 |
||
71490 | 1005 |
tree, properties, string, int, bool, unit, pair, triple, list, option, variant |
69240 | 1006 |
) |
1007 |
where |
|
1008 |
||
1009 |
import Isabelle.Library |
|
1010 |
import qualified Isabelle.Value as Value |
|
1011 |
import qualified Isabelle.Properties as Properties |
|
1012 |
import qualified Isabelle.XML as XML |
|
1013 |
||
1014 |
||
1015 |
type A a = a -> String |
|
1016 |
type T a = a -> XML.Body |
|
1017 |
type V a = a -> Maybe ([String], XML.Body) |
|
70845 | 1018 |
type P a = a -> [String] |
69240 | 1019 |
|
1020 |
||
1021 |
-- atomic values |
|
1022 |
||
1023 |
int_atom :: A Int |
|
1024 |
int_atom = Value.print_int |
|
1025 |
||
1026 |
bool_atom :: A Bool |
|
1027 |
bool_atom False = "0" |
|
1028 |
bool_atom True = "1" |
|
1029 |
||
1030 |
unit_atom :: A () |
|
1031 |
unit_atom () = "" |
|
1032 |
||
1033 |
||
1034 |
-- structural nodes |
|
1035 |
||
69290 | 1036 |
node ts = XML.Elem ((":", []), ts) |
69240 | 1037 |
|
1038 |
vector = map_index (\(i, x) -> (int_atom i, x)) |
|
1039 |
||
69290 | 1040 |
tagged (tag, (xs, ts)) = XML.Elem ((int_atom tag, vector xs), ts) |
69240 | 1041 |
|
1042 |
||
1043 |
-- representation of standard types |
|
1044 |
||
1045 |
tree :: T XML.Tree |
|
1046 |
tree t = [t] |
|
1047 |
||
1048 |
properties :: T Properties.T |
|
69290 | 1049 |
properties props = [XML.Elem ((":", props), [])] |
69240 | 1050 |
|
1051 |
string :: T String |
|
1052 |
string "" = [] |
|
1053 |
string s = [XML.Text s] |
|
1054 |
||
1055 |
int :: T Int |
|
1056 |
int = string . int_atom |
|
1057 |
||
1058 |
bool :: T Bool |
|
1059 |
bool = string . bool_atom |
|
1060 |
||
1061 |
unit :: T () |
|
1062 |
unit = string . unit_atom |
|
1063 |
||
1064 |
pair :: T a -> T b -> T (a, b) |
|
1065 |
pair f g (x, y) = [node (f x), node (g y)] |
|
1066 |
||
1067 |
triple :: T a -> T b -> T c -> T (a, b, c) |
|
1068 |
triple f g h (x, y, z) = [node (f x), node (g y), node (h z)] |
|
1069 |
||
1070 |
list :: T a -> T [a] |
|
1071 |
list f xs = map (node . f) xs |
|
1072 |
||
71490 | 1073 |
option :: T a -> T (Maybe a) |
1074 |
option _ Nothing = [] |
|
1075 |
option f (Just x) = [node (f x)] |
|
1076 |
||
69240 | 1077 |
variant :: [V a] -> T a |
1078 |
variant fs x = [tagged (the (get_index (\f -> f x) fs))] |
|
1079 |
\<close> |
|
1080 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1081 |
generate_file "Isabelle/XML/Decode.hs" = \<open> |
69445 | 1082 |
{- Title: Isabelle/XML/Decode.hs |
69240 | 1083 |
Author: Makarius |
1084 |
LICENSE: BSD 3-clause (Isabelle) |
|
1085 |
||
1086 |
XML as data representation language. |
|
69280 | 1087 |
|
1088 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/xml.ML\<close>. |
|
69240 | 1089 |
-} |
1090 |
||
73177 | 1091 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
1092 |
||
69240 | 1093 |
module Isabelle.XML.Decode ( |
70845 | 1094 |
A, T, V, P, |
69240 | 1095 |
|
1096 |
int_atom, bool_atom, unit_atom, |
|
1097 |
||
71490 | 1098 |
tree, properties, string, int, bool, unit, pair, triple, list, option, variant |
69240 | 1099 |
) |
1100 |
where |
|
1101 |
||
1102 |
import Isabelle.Library |
|
1103 |
import qualified Isabelle.Value as Value |
|
1104 |
import qualified Isabelle.Properties as Properties |
|
1105 |
import qualified Isabelle.XML as XML |
|
1106 |
||
1107 |
||
1108 |
type A a = String -> a |
|
1109 |
type T a = XML.Body -> a |
|
1110 |
type V a = ([String], XML.Body) -> a |
|
70845 | 1111 |
type P a = [String] -> a |
69240 | 1112 |
|
1113 |
err_atom = error "Malformed XML atom" |
|
1114 |
err_body = error "Malformed XML body" |
|
1115 |
||
1116 |
||
1117 |
{- atomic values -} |
|
1118 |
||
1119 |
int_atom :: A Int |
|
1120 |
int_atom s = |
|
1121 |
case Value.parse_int s of |
|
1122 |
Just i -> i |
|
1123 |
Nothing -> err_atom |
|
1124 |
||
1125 |
bool_atom :: A Bool |
|
1126 |
bool_atom "0" = False |
|
1127 |
bool_atom "1" = True |
|
1128 |
bool_atom _ = err_atom |
|
1129 |
||
1130 |
unit_atom :: A () |
|
1131 |
unit_atom "" = () |
|
1132 |
unit_atom _ = err_atom |
|
1133 |
||
1134 |
||
1135 |
{- structural nodes -} |
|
1136 |
||
69290 | 1137 |
node (XML.Elem ((":", []), ts)) = ts |
69240 | 1138 |
node _ = err_body |
1139 |
||
1140 |
vector atts = |
|
1141 |
map_index (\(i, (a, x)) -> if int_atom a == i then x else err_atom) atts |
|
1142 |
||
69290 | 1143 |
tagged (XML.Elem ((name, atts), ts)) = (int_atom name, (vector atts, ts)) |
69240 | 1144 |
tagged _ = err_body |
1145 |
||
1146 |
||
1147 |
{- representation of standard types -} |
|
1148 |
||
1149 |
tree :: T XML.Tree |
|
1150 |
tree [t] = t |
|
1151 |
tree _ = err_body |
|
1152 |
||
1153 |
properties :: T Properties.T |
|
69290 | 1154 |
properties [XML.Elem ((":", props), [])] = props |
69240 | 1155 |
properties _ = err_body |
1156 |
||
1157 |
string :: T String |
|
1158 |
string [] = "" |
|
1159 |
string [XML.Text s] = s |
|
1160 |
string _ = err_body |
|
1161 |
||
1162 |
int :: T Int |
|
1163 |
int = int_atom . string |
|
1164 |
||
1165 |
bool :: T Bool |
|
1166 |
bool = bool_atom . string |
|
1167 |
||
1168 |
unit :: T () |
|
1169 |
unit = unit_atom . string |
|
1170 |
||
1171 |
pair :: T a -> T b -> T (a, b) |
|
1172 |
pair f g [t1, t2] = (f (node t1), g (node t2)) |
|
1173 |
pair _ _ _ = err_body |
|
1174 |
||
1175 |
triple :: T a -> T b -> T c -> T (a, b, c) |
|
1176 |
triple f g h [t1, t2, t3] = (f (node t1), g (node t2), h (node t3)) |
|
1177 |
triple _ _ _ _ = err_body |
|
1178 |
||
1179 |
list :: T a -> T [a] |
|
1180 |
list f ts = map (f . node) ts |
|
1181 |
||
1182 |
option :: T a -> T (Maybe a) |
|
1183 |
option _ [] = Nothing |
|
1184 |
option f [t] = Just (f (node t)) |
|
1185 |
option _ _ = err_body |
|
1186 |
||
1187 |
variant :: [V a] -> T a |
|
1188 |
variant fs [t] = (fs !! tag) (xs, ts) |
|
1189 |
where (tag, (xs, ts)) = tagged t |
|
1190 |
variant _ _ = err_body |
|
1191 |
\<close> |
|
1192 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1193 |
generate_file "Isabelle/YXML.hs" = \<open> |
69445 | 1194 |
{- Title: Isabelle/YXML.hs |
69288 | 1195 |
Author: Makarius |
1196 |
LICENSE: BSD 3-clause (Isabelle) |
|
1197 |
||
1198 |
Efficient text representation of XML trees. Suitable for direct |
|
1199 |
inlining into plain text. |
|
1200 |
||
1201 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/yxml.ML\<close>. |
|
1202 |
-} |
|
1203 |
||
73177 | 1204 |
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-incomplete-patterns #-} |
1205 |
||
69288 | 1206 |
module Isabelle.YXML (charX, charY, strX, strY, detect, output_markup, |
1207 |
buffer_body, buffer, string_of_body, string_of, parse_body, parse) |
|
1208 |
where |
|
1209 |
||
1210 |
import qualified Data.Char as Char |
|
1211 |
import qualified Data.List as List |
|
1212 |
||
1213 |
import Isabelle.Library |
|
1214 |
import qualified Isabelle.Markup as Markup |
|
1215 |
import qualified Isabelle.XML as XML |
|
1216 |
import qualified Isabelle.Buffer as Buffer |
|
1217 |
||
1218 |
||
1219 |
{- markers -} |
|
1220 |
||
1221 |
charX, charY :: Char |
|
1222 |
charX = Char.chr 5 |
|
1223 |
charY = Char.chr 6 |
|
1224 |
||
1225 |
strX, strY, strXY, strXYX :: String |
|
1226 |
strX = [charX] |
|
1227 |
strY = [charY] |
|
1228 |
strXY = strX ++ strY |
|
1229 |
strXYX = strXY ++ strX |
|
1230 |
||
1231 |
detect :: String -> Bool |
|
1232 |
detect = any (\c -> c == charX || c == charY) |
|
1233 |
||
1234 |
||
1235 |
{- output -} |
|
1236 |
||
1237 |
output_markup :: Markup.T -> Markup.Output |
|
1238 |
output_markup markup@(name, atts) = |
|
1239 |
if Markup.is_empty markup then Markup.no_output |
|
1240 |
else (strXY ++ name ++ concatMap (\(a, x) -> strY ++ a ++ "=" ++ x) atts ++ strX, strXYX) |
|
1241 |
||
1242 |
buffer_attrib (a, x) = |
|
1243 |
Buffer.add strY #> Buffer.add a #> Buffer.add "=" #> Buffer.add x |
|
1244 |
||
1245 |
buffer_body :: XML.Body -> Buffer.T -> Buffer.T |
|
1246 |
buffer_body = fold buffer |
|
1247 |
||
1248 |
buffer :: XML.Tree -> Buffer.T -> Buffer.T |
|
69290 | 1249 |
buffer (XML.Elem ((name, atts), ts)) = |
69288 | 1250 |
Buffer.add strXY #> Buffer.add name #> fold buffer_attrib atts #> Buffer.add strX #> |
1251 |
buffer_body ts #> |
|
1252 |
Buffer.add strXYX |
|
1253 |
buffer (XML.Text s) = Buffer.add s |
|
1254 |
||
1255 |
string_of_body :: XML.Body -> String |
|
1256 |
string_of_body body = Buffer.empty |> buffer_body body |> Buffer.content |
|
1257 |
||
1258 |
string_of :: XML.Tree -> String |
|
1259 |
string_of = string_of_body . single |
|
1260 |
||
1261 |
||
1262 |
{- parse -} |
|
1263 |
||
1264 |
-- split: fields or non-empty tokens |
|
1265 |
||
1266 |
split :: Bool -> Char -> String -> [String] |
|
1267 |
split _ _ [] = [] |
|
1268 |
split fields sep str = splitting str |
|
1269 |
where |
|
1270 |
splitting rest = |
|
1271 |
case span (/= sep) rest of |
|
1272 |
(_, []) -> cons rest [] |
|
1273 |
(prfx, _ : rest') -> cons prfx (splitting rest') |
|
1274 |
cons item = if fields || not (null item) then (:) item else id |
|
1275 |
||
1276 |
||
1277 |
-- structural errors |
|
1278 |
||
1279 |
err msg = error ("Malformed YXML: " ++ msg) |
|
1280 |
err_attribute = err "bad attribute" |
|
1281 |
err_element = err "bad element" |
|
1282 |
err_unbalanced "" = err "unbalanced element" |
|
1283 |
err_unbalanced name = err ("unbalanced element " ++ quote name) |
|
1284 |
||
1285 |
||
1286 |
-- stack operations |
|
1287 |
||
1288 |
add x ((elem, body) : pending) = (elem, x : body) : pending |
|
1289 |
||
1290 |
push "" _ _ = err_element |
|
1291 |
push name atts pending = ((name, atts), []) : pending |
|
1292 |
||
1293 |
pop ((("", _), _) : _) = err_unbalanced "" |
|
69290 | 1294 |
pop ((markup, body) : pending) = add (XML.Elem (markup, reverse body)) pending |
69288 | 1295 |
|
1296 |
||
1297 |
-- parsing |
|
1298 |
||
1299 |
parse_attrib s = |
|
1300 |
case List.elemIndex '=' s of |
|
1301 |
Just i | i > 0 -> (take i s, drop (i + 1) s) |
|
1302 |
_ -> err_attribute |
|
1303 |
||
1304 |
parse_chunk ["", ""] = pop |
|
1305 |
parse_chunk ("" : name : atts) = push name (map parse_attrib atts) |
|
1306 |
parse_chunk txts = fold (add . XML.Text) txts |
|
1307 |
||
1308 |
parse_body :: String -> XML.Body |
|
1309 |
parse_body source = |
|
1310 |
case fold parse_chunk chunks [(("", []), [])] of |
|
1311 |
[(("", _), result)] -> reverse result |
|
1312 |
((name, _), _) : _ -> err_unbalanced name |
|
1313 |
where chunks = split False charX source |> map (split True charY) |
|
1314 |
||
1315 |
parse :: String -> XML.Tree |
|
1316 |
parse source = |
|
1317 |
case parse_body source of |
|
1318 |
[result] -> result |
|
1319 |
[] -> XML.Text "" |
|
1320 |
_ -> err "multiple results" |
|
1321 |
\<close> |
|
1322 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1323 |
generate_file "Isabelle/Pretty.hs" = \<open> |
69445 | 1324 |
{- Title: Isabelle/Pretty.hs |
69248 | 1325 |
Author: Makarius |
1326 |
LICENSE: BSD 3-clause (Isabelle) |
|
1327 |
||
1328 |
Generic pretty printing module. |
|
69280 | 1329 |
|
1330 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/General/pretty.ML\<close>. |
|
69248 | 1331 |
-} |
1332 |
||
73177 | 1333 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
1334 |
||
69248 | 1335 |
module Isabelle.Pretty ( |
1336 |
T, symbolic, formatted, unformatted, |
|
1337 |
||
1338 |
str, brk_indent, brk, fbrk, breaks, fbreaks, blk, block, strs, markup, mark, mark_str, marks_str, |
|
1339 |
item, text_fold, keyword1, keyword2, text, paragraph, para, quote, cartouche, separate, |
|
1340 |
commas, enclose, enum, list, str_list, big_list) |
|
1341 |
where |
|
1342 |
||
69453 | 1343 |
import Isabelle.Library hiding (quote, commas) |
69248 | 1344 |
import qualified Data.List as List |
1345 |
import qualified Isabelle.Buffer as Buffer |
|
1346 |
import qualified Isabelle.Markup as Markup |
|
1347 |
import qualified Isabelle.XML as XML |
|
1348 |
import qualified Isabelle.YXML as YXML |
|
1349 |
||
1350 |
||
1351 |
data T = |
|
1352 |
Block Markup.T Bool Int [T] |
|
1353 |
| Break Int Int |
|
1354 |
| Str String |
|
1355 |
||
1356 |
||
1357 |
{- output -} |
|
1358 |
||
1359 |
output_spaces n = replicate n ' ' |
|
1360 |
||
1361 |
symbolic_text "" = [] |
|
1362 |
symbolic_text s = [XML.Text s] |
|
1363 |
||
1364 |
symbolic_markup markup body = |
|
1365 |
if Markup.is_empty markup then body |
|
69290 | 1366 |
else [XML.Elem (markup, body)] |
69248 | 1367 |
|
1368 |
symbolic :: T -> XML.Body |
|
1369 |
symbolic (Block markup consistent indent prts) = |
|
1370 |
concatMap symbolic prts |
|
1371 |
|> symbolic_markup block_markup |
|
1372 |
|> symbolic_markup markup |
|
1373 |
where block_markup = if null prts then Markup.empty else Markup.block consistent indent |
|
69290 | 1374 |
symbolic (Break wd ind) = [XML.Elem (Markup.break wd ind, symbolic_text (output_spaces wd))] |
69248 | 1375 |
symbolic (Str s) = symbolic_text s |
1376 |
||
1377 |
formatted :: T -> String |
|
1378 |
formatted = YXML.string_of_body . symbolic |
|
1379 |
||
1380 |
unformatted :: T -> String |
|
1381 |
unformatted prt = Buffer.empty |> out prt |> Buffer.content |
|
1382 |
where |
|
1383 |
out (Block markup _ _ prts) = |
|
1384 |
let (bg, en) = YXML.output_markup markup |
|
1385 |
in Buffer.add bg #> fold out prts #> Buffer.add en |
|
1386 |
out (Break _ wd) = Buffer.add (output_spaces wd) |
|
1387 |
out (Str s) = Buffer.add s |
|
1388 |
||
1389 |
||
1390 |
{- derived operations to create formatting expressions -} |
|
1391 |
||
1392 |
force_nat n | n < 0 = 0 |
|
1393 |
force_nat n = n |
|
1394 |
||
1395 |
str :: String -> T |
|
1396 |
str = Str |
|
1397 |
||
1398 |
brk_indent :: Int -> Int -> T |
|
1399 |
brk_indent wd ind = Break (force_nat wd) ind |
|
1400 |
||
1401 |
brk :: Int -> T |
|
1402 |
brk wd = brk_indent wd 0 |
|
1403 |
||
1404 |
fbrk :: T |
|
1405 |
fbrk = str "\n" |
|
1406 |
||
1407 |
breaks, fbreaks :: [T] -> [T] |
|
1408 |
breaks = List.intersperse (brk 1) |
|
1409 |
fbreaks = List.intersperse fbrk |
|
1410 |
||
1411 |
blk :: (Int, [T]) -> T |
|
1412 |
blk (indent, es) = Block Markup.empty False (force_nat indent) es |
|
1413 |
||
1414 |
block :: [T] -> T |
|
1415 |
block prts = blk (2, prts) |
|
1416 |
||
1417 |
strs :: [String] -> T |
|
1418 |
strs = block . breaks . map str |
|
1419 |
||
1420 |
markup :: Markup.T -> [T] -> T |
|
1421 |
markup m = Block m False 0 |
|
1422 |
||
1423 |
mark :: Markup.T -> T -> T |
|
1424 |
mark m prt = if m == Markup.empty then prt else markup m [prt] |
|
1425 |
||
1426 |
mark_str :: (Markup.T, String) -> T |
|
1427 |
mark_str (m, s) = mark m (str s) |
|
1428 |
||
1429 |
marks_str :: ([Markup.T], String) -> T |
|
1430 |
marks_str (ms, s) = fold_rev mark ms (str s) |
|
1431 |
||
1432 |
item :: [T] -> T |
|
1433 |
item = markup Markup.item |
|
1434 |
||
1435 |
text_fold :: [T] -> T |
|
1436 |
text_fold = markup Markup.text_fold |
|
1437 |
||
1438 |
keyword1, keyword2 :: String -> T |
|
1439 |
keyword1 name = mark_str (Markup.keyword1, name) |
|
1440 |
keyword2 name = mark_str (Markup.keyword2, name) |
|
1441 |
||
1442 |
text :: String -> [T] |
|
1443 |
text = breaks . map str . words |
|
1444 |
||
1445 |
paragraph :: [T] -> T |
|
1446 |
paragraph = markup Markup.paragraph |
|
1447 |
||
1448 |
para :: String -> T |
|
1449 |
para = paragraph . text |
|
1450 |
||
1451 |
quote :: T -> T |
|
1452 |
quote prt = blk (1, [str "\"", prt, str "\""]) |
|
1453 |
||
1454 |
cartouche :: T -> T |
|
1455 |
cartouche prt = blk (1, [str "\92<open>", prt, str "\92<close>"]) |
|
1456 |
||
1457 |
separate :: String -> [T] -> [T] |
|
1458 |
separate sep = List.intercalate [str sep, brk 1] . map single |
|
1459 |
||
1460 |
commas :: [T] -> [T] |
|
1461 |
commas = separate "," |
|
1462 |
||
1463 |
enclose :: String -> String -> [T] -> T |
|
1464 |
enclose lpar rpar prts = block (str lpar : prts ++ [str rpar]) |
|
1465 |
||
1466 |
enum :: String -> String -> String -> [T] -> T |
|
1467 |
enum sep lpar rpar = enclose lpar rpar . separate sep |
|
1468 |
||
1469 |
list :: String -> String -> [T] -> T |
|
1470 |
list = enum "," |
|
1471 |
||
1472 |
str_list :: String -> String -> [String] -> T |
|
1473 |
str_list lpar rpar = list lpar rpar . map str |
|
1474 |
||
1475 |
big_list :: String -> [T] -> T |
|
1476 |
big_list name prts = block (fbreaks (str name : prts)) |
|
1477 |
\<close> |
|
1478 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1479 |
generate_file "Isabelle/Term.hs" = \<open> |
69445 | 1480 |
{- Title: Isabelle/Term.hs |
69240 | 1481 |
Author: Makarius |
1482 |
LICENSE: BSD 3-clause (Isabelle) |
|
1483 |
||
1484 |
Lambda terms, types, sorts. |
|
69280 | 1485 |
|
1486 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/term.scala\<close>. |
|
69240 | 1487 |
-} |
1488 |
||
1489 |
module Isabelle.Term ( |
|
1490 |
Indexname, |
|
1491 |
||
1492 |
Sort, dummyS, |
|
1493 |
||
70845 | 1494 |
Typ(..), dummyT, is_dummyT, Term(..)) |
69240 | 1495 |
where |
1496 |
||
1497 |
type Indexname = (String, Int) |
|
1498 |
||
1499 |
||
1500 |
type Sort = [String] |
|
1501 |
||
1502 |
dummyS :: Sort |
|
1503 |
dummyS = [""] |
|
1504 |
||
1505 |
||
1506 |
data Typ = |
|
1507 |
Type (String, [Typ]) |
|
1508 |
| TFree (String, Sort) |
|
1509 |
| TVar (Indexname, Sort) |
|
1510 |
deriving Show |
|
1511 |
||
1512 |
dummyT :: Typ |
|
1513 |
dummyT = Type (\<open>\<^type_name>\<open>dummy\<close>\<close>, []) |
|
1514 |
||
70845 | 1515 |
is_dummyT :: Typ -> Bool |
1516 |
is_dummyT (Type (\<open>\<^type_name>\<open>dummy\<close>\<close>, [])) = True |
|
1517 |
is_dummyT _ = False |
|
1518 |
||
69240 | 1519 |
|
1520 |
data Term = |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70667
diff
changeset
|
1521 |
Const (String, [Typ]) |
69240 | 1522 |
| Free (String, Typ) |
1523 |
| Var (Indexname, Typ) |
|
1524 |
| Bound Int |
|
1525 |
| Abs (String, Typ, Term) |
|
1526 |
| App (Term, Term) |
|
1527 |
deriving Show |
|
1528 |
\<close> |
|
1529 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1530 |
generate_file "Isabelle/Term_XML/Encode.hs" = \<open> |
69445 | 1531 |
{- Title: Isabelle/Term_XML/Encode.hs |
69240 | 1532 |
Author: Makarius |
1533 |
LICENSE: BSD 3-clause (Isabelle) |
|
1534 |
||
1535 |
XML data representation of lambda terms. |
|
69280 | 1536 |
|
1537 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/term_xml.ML\<close>. |
|
69240 | 1538 |
-} |
1539 |
||
1540 |
{-# LANGUAGE LambdaCase #-} |
|
1541 |
||
70845 | 1542 |
module Isabelle.Term_XML.Encode (indexname, sort, typ, typ_body, term) |
69240 | 1543 |
where |
1544 |
||
1545 |
import Isabelle.Library |
|
1546 |
import Isabelle.XML.Encode |
|
1547 |
import Isabelle.Term |
|
1548 |
||
70845 | 1549 |
indexname :: P Indexname |
1550 |
indexname (a, b) = if b == 0 then [a] else [a, int_atom b] |
|
69240 | 1551 |
|
1552 |
sort :: T Sort |
|
1553 |
sort = list string |
|
1554 |
||
1555 |
typ :: T Typ |
|
1556 |
typ ty = |
|
1557 |
ty |> variant |
|
1558 |
[\case { Type (a, b) -> Just ([a], list typ b); _ -> Nothing }, |
|
1559 |
\case { TFree (a, b) -> Just ([a], sort b); _ -> Nothing }, |
|
70845 | 1560 |
\case { TVar (a, b) -> Just (indexname a, sort b); _ -> Nothing }] |
1561 |
||
1562 |
typ_body :: T Typ |
|
1563 |
typ_body ty = if is_dummyT ty then [] else typ ty |
|
69240 | 1564 |
|
1565 |
term :: T Term |
|
1566 |
term t = |
|
1567 |
t |> variant |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70667
diff
changeset
|
1568 |
[\case { Const (a, b) -> Just ([a], list typ b); _ -> Nothing }, |
70845 | 1569 |
\case { Free (a, b) -> Just ([a], typ_body b); _ -> Nothing }, |
1570 |
\case { Var (a, b) -> Just (indexname a, typ_body b); _ -> Nothing }, |
|
1571 |
\case { Bound a -> Just ([], int a); _ -> Nothing }, |
|
69240 | 1572 |
\case { Abs (a, b, c) -> Just ([a], pair typ term (b, c)); _ -> Nothing }, |
1573 |
\case { App a -> Just ([], pair term term a); _ -> Nothing }] |
|
1574 |
\<close> |
|
1575 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1576 |
generate_file "Isabelle/Term_XML/Decode.hs" = \<open> |
69445 | 1577 |
{- Title: Isabelle/Term_XML/Decode.hs |
69240 | 1578 |
Author: Makarius |
1579 |
LICENSE: BSD 3-clause (Isabelle) |
|
1580 |
||
1581 |
XML data representation of lambda terms. |
|
69280 | 1582 |
|
1583 |
See also \<^file>\<open>$ISABELLE_HOME/src/Pure/term_xml.ML\<close>. |
|
69240 | 1584 |
-} |
1585 |
||
73177 | 1586 |
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} |
1587 |
||
70845 | 1588 |
module Isabelle.Term_XML.Decode (indexname, sort, typ, typ_body, term) |
69240 | 1589 |
where |
1590 |
||
1591 |
import Isabelle.Library |
|
1592 |
import Isabelle.XML.Decode |
|
1593 |
import Isabelle.Term |
|
1594 |
||
1595 |
||
70845 | 1596 |
indexname :: P Indexname |
1597 |
indexname [a] = (a, 0) |
|
1598 |
indexname [a, b] = (a, int_atom b) |
|
1599 |
||
69240 | 1600 |
sort :: T Sort |
1601 |
sort = list string |
|
1602 |
||
1603 |
typ :: T Typ |
|
1604 |
typ ty = |
|
1605 |
ty |> variant |
|
1606 |
[\([a], b) -> Type (a, list typ b), |
|
1607 |
\([a], b) -> TFree (a, sort b), |
|
70845 | 1608 |
\(a, b) -> TVar (indexname a, sort b)] |
1609 |
||
1610 |
typ_body :: T Typ |
|
1611 |
typ_body [] = dummyT |
|
1612 |
typ_body body = typ body |
|
69240 | 1613 |
|
1614 |
term :: T Term |
|
1615 |
term t = |
|
1616 |
t |> variant |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70667
diff
changeset
|
1617 |
[\([a], b) -> Const (a, list typ b), |
70845 | 1618 |
\([a], b) -> Free (a, typ_body b), |
1619 |
\(a, b) -> Var (indexname a, typ_body b), |
|
1620 |
\([], a) -> Bound (int a), |
|
69240 | 1621 |
\([a], b) -> let (c, d) = pair typ term b in Abs (a, c, d), |
1622 |
\([], a) -> App (pair term term a)] |
|
1623 |
\<close> |
|
1624 |
||
69459 | 1625 |
generate_file "Isabelle/UUID.hs" = \<open> |
1626 |
{- Title: Isabelle/UUID.hs |
|
1627 |
Author: Makarius |
|
1628 |
LICENSE: BSD 3-clause (Isabelle) |
|
1629 |
||
1630 |
Universally unique identifiers. |
|
1631 |
||
1632 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/uuid.scala\<close>. |
|
1633 |
-} |
|
1634 |
||
69465 | 1635 |
module Isabelle.UUID ( |
1636 |
T, |
|
1637 |
parse_string, parse_bytes, |
|
1638 |
string, bytes, |
|
1639 |
random, random_string, random_bytes |
|
1640 |
) |
|
69459 | 1641 |
where |
1642 |
||
69465 | 1643 |
import Data.ByteString (ByteString) |
69459 | 1644 |
import Data.UUID (UUID) |
1645 |
import qualified Data.UUID as UUID |
|
1646 |
import Data.UUID.V4 (nextRandom) |
|
1647 |
||
1648 |
||
69462 | 1649 |
type T = UUID |
1650 |
||
69465 | 1651 |
|
1652 |
{- parse -} |
|
1653 |
||
1654 |
parse_string :: String -> Maybe T |
|
1655 |
parse_string = UUID.fromString |
|
1656 |
||
1657 |
parse_bytes :: ByteString -> Maybe T |
|
1658 |
parse_bytes = UUID.fromASCIIBytes |
|
1659 |
||
1660 |
||
1661 |
{- print -} |
|
1662 |
||
1663 |
string :: T -> String |
|
1664 |
string = UUID.toString |
|
1665 |
||
1666 |
bytes :: T -> ByteString |
|
1667 |
bytes = UUID.toASCIIBytes |
|
1668 |
||
1669 |
||
1670 |
{- random id -} |
|
1671 |
||
69462 | 1672 |
random :: IO T |
69459 | 1673 |
random = nextRandom |
1674 |
||
1675 |
random_string :: IO String |
|
69465 | 1676 |
random_string = string <$> random |
69459 | 1677 |
|
69465 | 1678 |
random_bytes :: IO ByteString |
1679 |
random_bytes = bytes <$> random |
|
69459 | 1680 |
\<close> |
1681 |
||
69448 | 1682 |
generate_file "Isabelle/Byte_Message.hs" = \<open> |
1683 |
{- Title: Isabelle/Byte_Message.hs |
|
69446 | 1684 |
Author: Makarius |
1685 |
LICENSE: BSD 3-clause (Isabelle) |
|
1686 |
||
69448 | 1687 |
Byte-oriented messages. |
1688 |
||
1689 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/byte_message.ML\<close> |
|
1690 |
and \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/byte_message.scala\<close>. |
|
69446 | 1691 |
-} |
1692 |
||
73177 | 1693 |
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} |
1694 |
||
69452 | 1695 |
module Isabelle.Byte_Message ( |
69467 | 1696 |
write, write_line, |
1697 |
read, read_block, trim_line, read_line, |
|
69476 | 1698 |
make_message, write_message, read_message, |
73178 | 1699 |
make_line_message, write_line_message, read_line_message, |
1700 |
read_yxml, write_yxml |
|
69452 | 1701 |
) |
69446 | 1702 |
where |
1703 |
||
69449 | 1704 |
import Prelude hiding (read) |
69454 | 1705 |
import Data.Maybe |
69446 | 1706 |
import Data.ByteString (ByteString) |
1707 |
import qualified Data.ByteString as ByteString |
|
1708 |
import qualified Data.ByteString.UTF8 as UTF8 |
|
73178 | 1709 |
import qualified Isabelle.XML as XML |
1710 |
import qualified Isabelle.YXML as YXML |
|
73177 | 1711 |
|
69446 | 1712 |
import Network.Socket (Socket) |
1713 |
import qualified Network.Socket.ByteString as ByteString |
|
1714 |
||
69454 | 1715 |
import Isabelle.Library hiding (trim_line) |
69446 | 1716 |
import qualified Isabelle.Value as Value |
1717 |
||
1718 |
||
69452 | 1719 |
{- output operations -} |
1720 |
||
1721 |
write :: Socket -> [ByteString] -> IO () |
|
1722 |
write = ByteString.sendMany |
|
1723 |
||
1724 |
newline :: ByteString |
|
1725 |
newline = ByteString.singleton 10 |
|
1726 |
||
69467 | 1727 |
write_line :: Socket -> ByteString -> IO () |
1728 |
write_line socket s = write socket [s, newline] |
|
1729 |
||
69452 | 1730 |
|
1731 |
{- input operations -} |
|
1732 |
||
69449 | 1733 |
read :: Socket -> Int -> IO ByteString |
69452 | 1734 |
read socket n = read_body 0 [] |
69449 | 1735 |
where |
1736 |
result = ByteString.concat . reverse |
|
69452 | 1737 |
read_body len ss = |
69449 | 1738 |
if len >= n then return (result ss) |
1739 |
else |
|
1740 |
(do |
|
1741 |
s <- ByteString.recv socket (min (n - len) 8192) |
|
1742 |
case ByteString.length s of |
|
1743 |
0 -> return (result ss) |
|
69452 | 1744 |
m -> read_body (len + m) (s : ss)) |
1745 |
||
1746 |
read_block :: Socket -> Int -> IO (Maybe ByteString, Int) |
|
1747 |
read_block socket n = do |
|
1748 |
msg <- read socket n |
|
1749 |
let len = ByteString.length msg |
|
1750 |
return (if len == n then Just msg else Nothing, len) |
|
69449 | 1751 |
|
69452 | 1752 |
trim_line :: ByteString -> ByteString |
1753 |
trim_line s = |
|
1754 |
if n >= 2 && at (n - 2) == 13 && at (n - 1) == 10 then ByteString.take (n - 2) s |
|
1755 |
else if n >= 1 && (at (n - 1) == 13 || at (n - 1) == 10) then ByteString.take (n - 1) s |
|
1756 |
else s |
|
1757 |
where |
|
1758 |
n = ByteString.length s |
|
1759 |
at = ByteString.index s |
|
69449 | 1760 |
|
69446 | 1761 |
read_line :: Socket -> IO (Maybe ByteString) |
69452 | 1762 |
read_line socket = read_body [] |
69446 | 1763 |
where |
69452 | 1764 |
result = trim_line . ByteString.pack . reverse |
1765 |
read_body bs = do |
|
69446 | 1766 |
s <- ByteString.recv socket 1 |
1767 |
case ByteString.length s of |
|
1768 |
0 -> return (if null bs then Nothing else Just (result bs)) |
|
1769 |
1 -> |
|
1770 |
case ByteString.head s of |
|
1771 |
10 -> return (Just (result bs)) |
|
69452 | 1772 |
b -> read_body (b : bs) |
69446 | 1773 |
|
69448 | 1774 |
|
69454 | 1775 |
{- messages with multiple chunks (arbitrary content) -} |
1776 |
||
1777 |
make_header :: [Int] -> [ByteString] |
|
1778 |
make_header ns = |
|
1779 |
[UTF8.fromString (space_implode "," (map Value.print_int ns)), newline] |
|
1780 |
||
69476 | 1781 |
make_message :: [ByteString] -> [ByteString] |
1782 |
make_message chunks = make_header (map ByteString.length chunks) ++ chunks |
|
1783 |
||
69454 | 1784 |
write_message :: Socket -> [ByteString] -> IO () |
69476 | 1785 |
write_message socket = write socket . make_message |
69454 | 1786 |
|
1787 |
parse_header :: ByteString -> [Int] |
|
1788 |
parse_header line = |
|
1789 |
let |
|
1790 |
res = map Value.parse_nat (space_explode ',' (UTF8.toString line)) |
|
1791 |
in |
|
1792 |
if all isJust res then map fromJust res |
|
1793 |
else error ("Malformed message header: " ++ quote (UTF8.toString line)) |
|
1794 |
||
1795 |
read_chunk :: Socket -> Int -> IO ByteString |
|
1796 |
read_chunk socket n = do |
|
1797 |
res <- read_block socket n |
|
1798 |
return $ |
|
1799 |
case res of |
|
1800 |
(Just chunk, _) -> chunk |
|
1801 |
(Nothing, len) -> |
|
1802 |
error ("Malformed message chunk: unexpected EOF after " ++ |
|
1803 |
show len ++ " of " ++ show n ++ " bytes") |
|
1804 |
||
1805 |
read_message :: Socket -> IO (Maybe [ByteString]) |
|
1806 |
read_message socket = do |
|
1807 |
res <- read_line socket |
|
1808 |
case res of |
|
1809 |
Just line -> Just <$> mapM (read_chunk socket) (parse_header line) |
|
1810 |
Nothing -> return Nothing |
|
1811 |
||
1812 |
||
69448 | 1813 |
-- hybrid messages: line or length+block (with content restriction) |
1814 |
||
1815 |
is_length :: ByteString -> Bool |
|
69452 | 1816 |
is_length msg = |
1817 |
not (ByteString.null msg) && ByteString.all (\b -> 48 <= b && b <= 57) msg |
|
69446 | 1818 |
|
69452 | 1819 |
is_terminated :: ByteString -> Bool |
1820 |
is_terminated msg = |
|
1821 |
not (ByteString.null msg) && (ByteString.last msg == 13 || ByteString.last msg == 10) |
|
69448 | 1822 |
|
69476 | 1823 |
make_line_message :: ByteString -> [ByteString] |
1824 |
make_line_message msg = |
|
1825 |
let n = ByteString.length msg in |
|
1826 |
if is_length msg || is_terminated msg then |
|
1827 |
error ("Bad content for line message:\n" ++ take 100 (UTF8.toString msg)) |
|
1828 |
else |
|
1829 |
(if n > 100 || ByteString.any (== 10) msg then make_header [n + 1] else []) ++ |
|
1830 |
[msg, newline] |
|
69448 | 1831 |
|
69476 | 1832 |
write_line_message :: Socket -> ByteString -> IO () |
1833 |
write_line_message socket = write socket . make_line_message |
|
69448 | 1834 |
|
1835 |
read_line_message :: Socket -> IO (Maybe ByteString) |
|
1836 |
read_line_message socket = do |
|
69446 | 1837 |
opt_line <- read_line socket |
1838 |
case opt_line of |
|
1839 |
Nothing -> return Nothing |
|
1840 |
Just line -> |
|
69452 | 1841 |
case Value.parse_nat (UTF8.toString line) of |
69446 | 1842 |
Nothing -> return $ Just line |
69452 | 1843 |
Just n -> fmap trim_line . fst <$> read_block socket n |
73178 | 1844 |
|
1845 |
||
1846 |
read_yxml :: Socket -> IO (Maybe XML.Body) |
|
1847 |
read_yxml socket = do |
|
1848 |
res <- read_line_message socket |
|
1849 |
return (YXML.parse_body . UTF8.toString <$> res) |
|
1850 |
||
1851 |
write_yxml :: Socket -> XML.Body -> IO () |
|
1852 |
write_yxml socket body = |
|
1853 |
write_line_message socket (UTF8.fromString (YXML.string_of_body body)) |
|
69446 | 1854 |
\<close> |
1855 |
||
71692 | 1856 |
generate_file "Isabelle/Isabelle_Thread.hs" = \<open> |
1857 |
{- Title: Isabelle/Isabelle_Thread.hs |
|
69473 | 1858 |
Author: Makarius |
1859 |
LICENSE: BSD 3-clause (Isabelle) |
|
1860 |
||
71692 | 1861 |
Isabelle-specific thread management. |
1862 |
||
1863 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/Concurrent/isabelle_thread.ML\<close> |
|
1864 |
and \<^file>\<open>$ISABELLE_HOME/src/Pure/Concurrent/isabelle_thread.scala\<close>. |
|
69473 | 1865 |
-} |
1866 |
||
1867 |
{-# LANGUAGE NamedFieldPuns #-} |
|
1868 |
||
71692 | 1869 |
module Isabelle.Isabelle_Thread ( |
69473 | 1870 |
ThreadId, Result, |
69494 | 1871 |
find_id, |
69473 | 1872 |
properties, change_properties, |
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1873 |
add_resource, del_resource, bracket_resource, |
69497 | 1874 |
is_stopped, expose_stopped, stop, |
69496 | 1875 |
my_uuid, stop_uuid, |
69494 | 1876 |
Fork, fork_finally, fork) |
69473 | 1877 |
where |
1878 |
||
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1879 |
import Data.Unique |
69473 | 1880 |
import Data.IORef |
1881 |
import System.IO.Unsafe |
|
1882 |
||
69494 | 1883 |
import qualified Data.List as List |
69497 | 1884 |
import Control.Monad (when, forM_) |
69473 | 1885 |
import Data.Map.Strict (Map) |
1886 |
import qualified Data.Map.Strict as Map |
|
1887 |
import Control.Exception as Exception |
|
1888 |
import Control.Concurrent (ThreadId) |
|
1889 |
import qualified Control.Concurrent as Concurrent |
|
1890 |
import Control.Concurrent.Thread (Result) |
|
1891 |
import qualified Control.Concurrent.Thread as Thread |
|
69494 | 1892 |
import qualified Isabelle.UUID as UUID |
69473 | 1893 |
import qualified Isabelle.Properties as Properties |
1894 |
||
1895 |
||
1896 |
{- thread info -} |
|
1897 |
||
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1898 |
type Resources = Map Unique (IO ()) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1899 |
data Info = Info {uuid :: UUID.T, props :: Properties.T, stopped :: Bool, resources :: Resources} |
69473 | 1900 |
type Infos = Map ThreadId Info |
1901 |
||
1902 |
lookup_info :: Infos -> ThreadId -> Maybe Info |
|
69494 | 1903 |
lookup_info infos id = Map.lookup id infos |
1904 |
||
1905 |
init_info :: ThreadId -> UUID.T -> Infos -> (Infos, ()) |
|
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1906 |
init_info id uuid infos = (Map.insert id (Info uuid [] False Map.empty) infos, ()) |
69473 | 1907 |
|
1908 |
||
1909 |
{- global state -} |
|
1910 |
||
1911 |
{-# NOINLINE global_state #-} |
|
1912 |
global_state :: IORef Infos |
|
1913 |
global_state = unsafePerformIO (newIORef Map.empty) |
|
1914 |
||
69494 | 1915 |
find_id :: UUID.T -> IO (Maybe ThreadId) |
1916 |
find_id uuid = do |
|
1917 |
state <- readIORef global_state |
|
1918 |
return $ fst <$> List.find (\(_, Info{uuid = uuid'}) -> uuid == uuid') (Map.assocs state) |
|
1919 |
||
69473 | 1920 |
get_info :: ThreadId -> IO (Maybe Info) |
1921 |
get_info id = do |
|
1922 |
state <- readIORef global_state |
|
1923 |
return $ lookup_info state id |
|
1924 |
||
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1925 |
map_info :: ThreadId -> (Info -> Info) -> IO (Maybe Info) |
69473 | 1926 |
map_info id f = |
1927 |
atomicModifyIORef' global_state |
|
1928 |
(\infos -> |
|
1929 |
case lookup_info infos id of |
|
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1930 |
Nothing -> (infos, Nothing) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1931 |
Just info -> |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1932 |
let info' = f info |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1933 |
in (Map.insert id info' infos, Just info')) |
69473 | 1934 |
|
69495 | 1935 |
delete_info :: ThreadId -> IO () |
1936 |
delete_info id = |
|
1937 |
atomicModifyIORef' global_state (\infos -> (Map.delete id infos, ())) |
|
1938 |
||
69473 | 1939 |
|
1940 |
{- thread properties -} |
|
1941 |
||
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
1942 |
my_info :: IO (Maybe Info) |
69473 | 1943 |
my_info = do |
1944 |
id <- Concurrent.myThreadId |
|
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
1945 |
get_info id |
69473 | 1946 |
|
1947 |
properties :: IO Properties.T |
|
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
1948 |
properties = maybe [] props <$> my_info |
69473 | 1949 |
|
1950 |
change_properties :: (Properties.T -> Properties.T) -> IO () |
|
1951 |
change_properties f = do |
|
1952 |
id <- Concurrent.myThreadId |
|
1953 |
map_info id (\info -> info {props = f (props info)}) |
|
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1954 |
return () |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1955 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1956 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1957 |
{- managed resources -} |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1958 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1959 |
add_resource :: IO () -> IO Unique |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1960 |
add_resource resource = do |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1961 |
id <- Concurrent.myThreadId |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1962 |
u <- newUnique |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1963 |
map_info id (\info -> info {resources = Map.insert u resource (resources info)}) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1964 |
return u |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1965 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1966 |
del_resource :: Unique -> IO () |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1967 |
del_resource u = do |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1968 |
id <- Concurrent.myThreadId |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1969 |
map_info id (\info -> info {resources = Map.delete u (resources info)}) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1970 |
return () |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1971 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1972 |
bracket_resource :: IO () -> IO a -> IO a |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1973 |
bracket_resource resource body = |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1974 |
Exception.bracket (add_resource resource) del_resource (const body) |
69473 | 1975 |
|
1976 |
||
1977 |
{- stop -} |
|
1978 |
||
1979 |
is_stopped :: IO Bool |
|
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
1980 |
is_stopped = maybe False stopped <$> my_info |
69473 | 1981 |
|
69497 | 1982 |
expose_stopped :: IO () |
1983 |
expose_stopped = do |
|
1984 |
stopped <- is_stopped |
|
1985 |
when stopped $ throw ThreadKilled |
|
1986 |
||
69473 | 1987 |
stop :: ThreadId -> IO () |
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1988 |
stop id = do |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1989 |
info <- map_info id (\info -> info {stopped = True}) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1990 |
let ops = case info of Nothing -> []; Just Info{resources} -> map snd (Map.toDescList resources) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
1991 |
sequence_ ops |
69473 | 1992 |
|
1993 |
||
69496 | 1994 |
{- UUID -} |
1995 |
||
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
1996 |
my_uuid :: IO (Maybe UUID.T) |
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
1997 |
my_uuid = fmap uuid <$> my_info |
69496 | 1998 |
|
1999 |
stop_uuid :: UUID.T -> IO () |
|
2000 |
stop_uuid uuid = do |
|
2001 |
id <- find_id uuid |
|
2002 |
forM_ id stop |
|
2003 |
||
2004 |
||
69473 | 2005 |
{- fork -} |
2006 |
||
69494 | 2007 |
type Fork a = (ThreadId, UUID.T, IO (Result a)) |
2008 |
||
2009 |
fork_finally :: IO a -> (Either SomeException a -> IO b) -> IO (Fork b) |
|
69473 | 2010 |
fork_finally body finally = do |
69494 | 2011 |
uuid <- UUID.random |
69473 | 2012 |
(id, result) <- |
2013 |
Exception.mask (\restore -> |
|
2014 |
Thread.forkIO |
|
2015 |
(Exception.try |
|
2016 |
(do |
|
2017 |
id <- Concurrent.myThreadId |
|
69494 | 2018 |
atomicModifyIORef' global_state (init_info id uuid) |
69495 | 2019 |
restore body) |
2020 |
>>= (\res -> do id <- Concurrent.myThreadId; delete_info id; finally res))) |
|
69494 | 2021 |
return (id, uuid, result) |
2022 |
||
2023 |
fork :: IO a -> IO (Fork a) |
|
69473 | 2024 |
fork body = fork_finally body Thread.result |
2025 |
\<close> |
|
2026 |
||
69455 | 2027 |
generate_file "Isabelle/Server.hs" = \<open> |
2028 |
{- Title: Isabelle/Server.hs |
|
2029 |
Author: Makarius |
|
2030 |
LICENSE: BSD 3-clause (Isabelle) |
|
2031 |
||
2032 |
TCP server on localhost. |
|
2033 |
-} |
|
2034 |
||
69465 | 2035 |
module Isabelle.Server ( |
2036 |
localhost_name, localhost, publish_text, publish_stdout, |
|
73178 | 2037 |
server, connection |
69465 | 2038 |
) |
2039 |
where |
|
69455 | 2040 |
|
69465 | 2041 |
import Data.ByteString (ByteString) |
2042 |
import Control.Monad (forever, when) |
|
69455 | 2043 |
import qualified Control.Exception as Exception |
2044 |
import Network.Socket (Socket) |
|
2045 |
import qualified Network.Socket as Socket |
|
69472 | 2046 |
import qualified System.IO as IO |
69455 | 2047 |
|
69462 | 2048 |
import Isabelle.Library |
2049 |
import qualified Isabelle.UUID as UUID |
|
69465 | 2050 |
import qualified Isabelle.Byte_Message as Byte_Message |
71692 | 2051 |
import qualified Isabelle.Isabelle_Thread as Isabelle_Thread |
73178 | 2052 |
import qualified Data.ByteString.UTF8 as UTF8 |
69462 | 2053 |
|
2054 |
||
2055 |
{- server address -} |
|
69455 | 2056 |
|
69463 | 2057 |
localhost_name :: String |
2058 |
localhost_name = "127.0.0.1" |
|
2059 |
||
69455 | 2060 |
localhost :: Socket.HostAddress |
2061 |
localhost = Socket.tupleToHostAddress (127, 0, 0, 1) |
|
2062 |
||
69462 | 2063 |
publish_text :: String -> String -> UUID.T -> String |
2064 |
publish_text name address password = |
|
2065 |
"server " ++ quote name ++ " = " ++ address ++ " (password " ++ quote (show password) ++ ")" |
|
2066 |
||
2067 |
publish_stdout :: String -> String -> UUID.T -> IO () |
|
2068 |
publish_stdout name address password = putStrLn (publish_text name address password) |
|
2069 |
||
2070 |
||
2071 |
{- server -} |
|
2072 |
||
2073 |
server :: (String -> UUID.T -> IO ()) -> (Socket -> IO ()) -> IO () |
|
69455 | 2074 |
server publish handle = |
69462 | 2075 |
Socket.withSocketsDo $ Exception.bracket open (Socket.close . fst) (uncurry loop) |
69455 | 2076 |
where |
69465 | 2077 |
open :: IO (Socket, ByteString) |
69455 | 2078 |
open = do |
69466 | 2079 |
server_socket <- Socket.socket Socket.AF_INET Socket.Stream Socket.defaultProtocol |
2080 |
Socket.bind server_socket (Socket.SockAddrInet 0 localhost) |
|
2081 |
Socket.listen server_socket 50 |
|
69462 | 2082 |
|
69466 | 2083 |
port <- Socket.socketPort server_socket |
69462 | 2084 |
let address = localhost_name ++ ":" ++ show port |
2085 |
password <- UUID.random |
|
2086 |
publish address password |
|
69455 | 2087 |
|
69466 | 2088 |
return (server_socket, UUID.bytes password) |
69462 | 2089 |
|
69465 | 2090 |
loop :: Socket -> ByteString -> IO () |
69466 | 2091 |
loop server_socket password = forever $ do |
69480 | 2092 |
(connection, _) <- Socket.accept server_socket |
71692 | 2093 |
Isabelle_Thread.fork_finally |
69465 | 2094 |
(do |
2095 |
line <- Byte_Message.read_line connection |
|
2096 |
when (line == Just password) $ handle connection) |
|
69473 | 2097 |
(\finally -> do |
69472 | 2098 |
Socket.close connection |
69473 | 2099 |
case finally of |
69472 | 2100 |
Left exn -> IO.hPutStrLn IO.stderr $ Exception.displayException exn |
2101 |
Right () -> return ()) |
|
69455 | 2102 |
return () |
73178 | 2103 |
|
2104 |
||
2105 |
{- client connection -} |
|
2106 |
||
2107 |
connection :: String -> String -> (Socket -> IO a) -> IO a |
|
2108 |
connection port password client = |
|
2109 |
Socket.withSocketsDo $ do |
|
2110 |
addr <- resolve |
|
2111 |
Exception.bracket (open addr) Socket.close body |
|
2112 |
where |
|
2113 |
resolve = do |
|
2114 |
let hints = |
|
2115 |
Socket.defaultHints { |
|
2116 |
Socket.addrFlags = [Socket.AI_NUMERICHOST, Socket.AI_NUMERICSERV], |
|
2117 |
Socket.addrSocketType = Socket.Stream } |
|
2118 |
head <$> Socket.getAddrInfo (Just hints) (Just "127.0.0.1") (Just port) |
|
2119 |
||
2120 |
open addr = do |
|
2121 |
socket <- Socket.socket (Socket.addrFamily addr) (Socket.addrSocketType addr) |
|
2122 |
(Socket.addrProtocol addr) |
|
2123 |
Socket.connect socket $ Socket.addrAddress addr |
|
2124 |
return socket |
|
2125 |
||
2126 |
body socket = do |
|
2127 |
Byte_Message.write_line socket (UTF8.fromString password) |
|
2128 |
client socket |
|
69455 | 2129 |
\<close> |
2130 |
||
70047
96fe857a7a6f
clarified signature: more explicit operations for corresponding Isar commands;
wenzelm
parents:
69968
diff
changeset
|
2131 |
export_generated_files _ |
69628 | 2132 |
|
69222 | 2133 |
end |