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