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