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