author | wenzelm |
Thu, 26 Aug 2021 22:15:55 +0200 | |
changeset 74203 | 92f08f3d77bd |
parent 74197 | 1f78a40e4399 |
child 74204 | c832f35ea571 |
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 |
|
74105 | 8 |
imports Main |
69222 | 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 |
||
74132 | 22 |
{-# LANGUAGE TypeApplications #-} |
23 |
||
74084 | 24 |
module Isabelle.Bytes ( |
25 |
Bytes, |
|
26 |
make, unmake, pack, unpack, |
|
27 |
empty, null, length, index, all, any, |
|
74099 | 28 |
head, last, take, drop, isPrefixOf, isSuffixOf, |
74137 | 29 |
concat, space, spaces, char, all_char, any_char, byte, singleton |
74084 | 30 |
) |
31 |
where |
|
32 |
||
33 |
import Prelude hiding (null, length, all, any, head, last, take, drop, concat) |
|
34 |
||
35 |
import qualified Data.ByteString.Short as ShortByteString |
|
36 |
import Data.ByteString.Short (ShortByteString) |
|
74090 | 37 |
import qualified Data.ByteString as ByteString |
74084 | 38 |
import Data.ByteString (ByteString) |
39 |
import qualified Data.List as List |
|
40 |
import Data.Word (Word8) |
|
74090 | 41 |
import Data.Array (Array, array, (!)) |
74084 | 42 |
|
43 |
||
44 |
type Bytes = ShortByteString |
|
45 |
||
46 |
make :: ByteString -> Bytes |
|
47 |
make = ShortByteString.toShort |
|
48 |
||
49 |
unmake :: Bytes -> ByteString |
|
50 |
unmake = ShortByteString.fromShort |
|
51 |
||
52 |
pack :: [Word8] -> Bytes |
|
53 |
pack = ShortByteString.pack |
|
54 |
||
55 |
unpack :: Bytes -> [Word8] |
|
56 |
unpack = ShortByteString.unpack |
|
57 |
||
58 |
empty :: Bytes |
|
59 |
empty = ShortByteString.empty |
|
60 |
||
61 |
null :: Bytes -> Bool |
|
62 |
null = ShortByteString.null |
|
63 |
||
64 |
length :: Bytes -> Int |
|
65 |
length = ShortByteString.length |
|
66 |
||
67 |
index :: Bytes -> Int -> Word8 |
|
68 |
index = ShortByteString.index |
|
69 |
||
70 |
all :: (Word8 -> Bool) -> Bytes -> Bool |
|
71 |
all p = List.all p . unpack |
|
72 |
||
73 |
any :: (Word8 -> Bool) -> Bytes -> Bool |
|
74 |
any p = List.any p . unpack |
|
75 |
||
76 |
head :: Bytes -> Word8 |
|
77 |
head bytes = index bytes 0 |
|
78 |
||
79 |
last :: Bytes -> Word8 |
|
80 |
last bytes = index bytes (length bytes - 1) |
|
81 |
||
82 |
take :: Int -> Bytes -> Bytes |
|
83 |
take n = pack . List.take n . unpack |
|
84 |
||
85 |
drop :: Int -> Bytes -> Bytes |
|
86 |
drop n = pack . List.drop n . unpack |
|
87 |
||
74099 | 88 |
isPrefixOf :: Bytes -> Bytes -> Bool |
89 |
isPrefixOf bs1 bs2 = |
|
90 |
n1 <= n2 && List.all (\i -> index bs1 i == index bs2 i) [0 .. n1 - 1] |
|
91 |
where n1 = length bs1; n2 = length bs2 |
|
92 |
||
93 |
isSuffixOf :: Bytes -> Bytes -> Bool |
|
94 |
isSuffixOf bs1 bs2 = |
|
95 |
n1 <= n2 && List.all (\i -> index bs1 i == index bs2 (i + k)) [0 .. n1 - 1] |
|
96 |
where n1 = length bs1; n2 = length bs2; k = n2 - n1 |
|
97 |
||
74084 | 98 |
concat :: [Bytes] -> Bytes |
99 |
concat = mconcat |
|
74088 | 100 |
|
74095 | 101 |
space :: Word8 |
102 |
space = 32 |
|
103 |
||
104 |
small_spaces :: Array Int Bytes |
|
105 |
small_spaces = array (0, 64) [(i, pack (replicate i space)) | i <- [0 .. 64]] |
|
106 |
||
107 |
spaces :: Int -> Bytes |
|
108 |
spaces n = |
|
109 |
if n < 64 then small_spaces ! n |
|
110 |
else concat ((small_spaces ! (n `mod` 64)) : replicate (n `div` 64) (small_spaces ! 64)) |
|
111 |
||
112 |
char :: Word8 -> Char |
|
113 |
char = toEnum . fromEnum |
|
114 |
||
74135 | 115 |
all_char :: (Char -> Bool) -> Bytes -> Bool |
116 |
all_char pred = all (pred . char) |
|
117 |
||
118 |
any_char :: (Char -> Bool) -> Bytes -> Bool |
|
119 |
any_char pred = any (pred . char) |
|
120 |
||
74095 | 121 |
byte :: Char -> Word8 |
122 |
byte = toEnum . fromEnum |
|
123 |
||
74132 | 124 |
singletons :: Array Word8 Bytes |
125 |
singletons = |
|
74137 | 126 |
array (minBound, maxBound) |
127 |
[(i, make (ByteString.singleton i)) | i <- [minBound .. maxBound]] |
|
74132 | 128 |
|
129 |
singleton :: Word8 -> Bytes |
|
130 |
singleton b = singletons ! b |
|
74084 | 131 |
\<close> |
132 |
||
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
133 |
generate_file "Isabelle/UTF8.hs" = \<open> |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
134 |
{- Title: Isabelle/UTF8.hs |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
135 |
Author: Makarius |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
136 |
LICENSE: BSD 3-clause (Isabelle) |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
137 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
138 |
Variations on UTF-8. |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
139 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
-} |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
143 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
144 |
{-# LANGUAGE MultiParamTypeClasses #-} |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
145 |
{-# LANGUAGE TypeSynonymInstances #-} |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
146 |
{-# LANGUAGE FlexibleInstances #-} |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
147 |
{-# LANGUAGE InstanceSigs #-} |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
148 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
149 |
module Isabelle.UTF8 ( |
74098 | 150 |
setup, setup3, |
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
151 |
Recode (..) |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
152 |
) |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
153 |
where |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
154 |
|
74098 | 155 |
import qualified System.IO as IO |
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
156 |
import Data.Text (Text) |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
157 |
import qualified Data.Text as Text |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
158 |
import qualified Data.Text.Encoding as Encoding |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
159 |
import qualified Data.Text.Encoding.Error as Error |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
160 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
161 |
import Data.ByteString (ByteString) |
74084 | 162 |
|
163 |
import qualified Isabelle.Bytes as Bytes |
|
164 |
import Isabelle.Bytes (Bytes) |
|
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
165 |
|
74098 | 166 |
setup :: IO.Handle -> IO () |
167 |
setup h = do |
|
168 |
IO.hSetEncoding h IO.utf8 |
|
169 |
IO.hSetNewlineMode h IO.noNewlineTranslation |
|
170 |
||
171 |
setup3 :: IO.Handle -> IO.Handle -> IO.Handle -> IO () |
|
172 |
setup3 h1 h2 h3 = do |
|
173 |
setup h1 |
|
174 |
setup h2 |
|
175 |
setup h3 |
|
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
176 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
177 |
class Recode a b where |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
178 |
encode :: a -> b |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
179 |
decode :: b -> a |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
180 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
181 |
instance Recode Text ByteString where |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
182 |
encode :: Text -> ByteString |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
183 |
encode = Encoding.encodeUtf8 |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
184 |
decode :: ByteString -> Text |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
185 |
decode = Encoding.decodeUtf8With Error.lenientDecode |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
186 |
|
74084 | 187 |
instance Recode Text Bytes where |
188 |
encode :: Text -> Bytes |
|
189 |
encode = Bytes.make . encode |
|
190 |
decode :: Bytes -> Text |
|
191 |
decode = decode . Bytes.unmake |
|
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
192 |
|
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
193 |
instance Recode String ByteString where |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
194 |
encode :: String -> ByteString |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
195 |
encode = encode . Text.pack |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
196 |
decode :: ByteString -> String |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
197 |
decode = Text.unpack . decode |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
198 |
|
74084 | 199 |
instance Recode String Bytes where |
200 |
encode :: String -> Bytes |
|
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
201 |
encode = encode . Text.pack |
74084 | 202 |
decode :: Bytes -> String |
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
203 |
decode = Text.unpack . decode |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
204 |
\<close> |
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
205 |
|
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
206 |
generate_file "Isabelle/Library.hs" = \<open> |
69445 | 207 |
{- Title: Isabelle/Library.hs |
69225 | 208 |
Author: Makarius |
209 |
LICENSE: BSD 3-clause (Isabelle) |
|
210 |
||
211 |
Basic library of Isabelle idioms. |
|
69280 | 212 |
|
74178 | 213 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/basics.ML\<close> |
214 |
and \<^file>\<open>$ISABELLE_HOME/src/Pure/library.ML\<close>. |
|
69225 | 215 |
-} |
216 |
||
74086 | 217 |
{-# LANGUAGE OverloadedStrings #-} |
74093 | 218 |
{-# LANGUAGE TypeSynonymInstances #-} |
219 |
{-# LANGUAGE FlexibleInstances #-} |
|
74134 | 220 |
{-# LANGUAGE InstanceSigs #-} |
74086 | 221 |
|
69240 | 222 |
module Isabelle.Library ( |
223 |
(|>), (|->), (#>), (#->), |
|
224 |
||
74203 | 225 |
fold, fold_rev, single, the_single, map_index, get_index, separate, |
69240 | 226 |
|
74093 | 227 |
StringLike, STRING (..), TEXT (..), BYTES (..), |
74128 | 228 |
show_bytes, show_text, |
74093 | 229 |
|
74185 | 230 |
proper_string, enclose, quote, space_implode, commas, commas_quote, cat_lines, |
74099 | 231 |
space_explode, split_lines, trim_line) |
69225 | 232 |
where |
233 |
||
74093 | 234 |
import qualified Data.Text as Text |
235 |
import Data.Text (Text) |
|
74096 | 236 |
import qualified Data.Text.Lazy as Lazy |
74086 | 237 |
import Data.String (IsString) |
69453 | 238 |
import qualified Data.List.Split as Split |
69491 | 239 |
import qualified Isabelle.Symbol as Symbol |
74130 | 240 |
import qualified Isabelle.Bytes as Bytes |
74093 | 241 |
import Isabelle.Bytes (Bytes) |
242 |
import qualified Isabelle.UTF8 as UTF8 |
|
69234 | 243 |
|
244 |
||
69225 | 245 |
{- functions -} |
246 |
||
247 |
(|>) :: a -> (a -> b) -> b |
|
248 |
x |> f = f x |
|
249 |
||
250 |
(|->) :: (a, b) -> (a -> b -> c) -> c |
|
251 |
(x, y) |-> f = f x y |
|
252 |
||
253 |
(#>) :: (a -> b) -> (b -> c) -> a -> c |
|
254 |
(f #> g) x = x |> f |> g |
|
255 |
||
256 |
(#->) :: (a -> (c, b)) -> (c -> b -> d) -> a -> d |
|
257 |
(f #-> g) x = x |> f |-> g |
|
258 |
||
259 |
||
260 |
{- lists -} |
|
261 |
||
262 |
fold :: (a -> b -> b) -> [a] -> b -> b |
|
263 |
fold _ [] y = y |
|
264 |
fold f (x : xs) y = fold f xs (f x y) |
|
265 |
||
266 |
fold_rev :: (a -> b -> b) -> [a] -> b -> b |
|
267 |
fold_rev _ [] y = y |
|
268 |
fold_rev f (x : xs) y = f x (fold_rev f xs y) |
|
269 |
||
270 |
single :: a -> [a] |
|
271 |
single x = [x] |
|
272 |
||
74203 | 273 |
the_single :: [a] -> a |
274 |
the_single [x] = x |
|
275 |
the_single _ = undefined |
|
276 |
||
69240 | 277 |
map_index :: ((Int, a) -> b) -> [a] -> [b] |
278 |
map_index f = map_aux 0 |
|
279 |
where |
|
280 |
map_aux _ [] = [] |
|
281 |
map_aux i (x : xs) = f (i, x) : map_aux (i + 1) xs |
|
282 |
||
283 |
get_index :: (a -> Maybe b) -> [a] -> Maybe (Int, b) |
|
284 |
get_index f = get_aux 0 |
|
285 |
where |
|
286 |
get_aux _ [] = Nothing |
|
287 |
get_aux i (x : xs) = |
|
288 |
case f x of |
|
289 |
Nothing -> get_aux (i + 1) xs |
|
290 |
Just y -> Just (i, y) |
|
291 |
||
74086 | 292 |
separate :: a -> [a] -> [a] |
74093 | 293 |
separate s (x : (xs @ (_ : _))) = x : s : separate s xs |
74086 | 294 |
separate _ xs = xs; |
295 |
||
69225 | 296 |
|
74093 | 297 |
{- string-like interfaces -} |
298 |
||
74132 | 299 |
class (IsString a, Monoid a, Eq a, Ord a) => StringLike a where |
300 |
space_explode :: Char -> a -> [a] |
|
74134 | 301 |
trim_line :: a -> a |
74130 | 302 |
|
74136 | 303 |
gen_trim_line :: Int -> (Int -> Char) -> (Int -> a -> a) -> a -> a |
304 |
gen_trim_line n at trim s = |
|
305 |
if n >= 2 && at (n - 2) == '\r' && at (n - 1) == '\n' then trim (n - 2) s |
|
306 |
else if n >= 1 && Symbol.is_ascii_line_terminator (at (n - 1)) then trim (n - 1) s |
|
307 |
else s |
|
308 |
||
74130 | 309 |
instance StringLike String where |
74134 | 310 |
space_explode :: Char -> String -> [String] |
74132 | 311 |
space_explode c = Split.split (Split.dropDelims (Split.whenElt (== c))) |
74134 | 312 |
trim_line :: String -> String |
74136 | 313 |
trim_line s = gen_trim_line (length s) ((!!) s) take s |
74130 | 314 |
|
315 |
instance StringLike Text where |
|
74134 | 316 |
space_explode :: Char -> Text -> [Text] |
74132 | 317 |
space_explode c str = |
74130 | 318 |
if Text.null str then [] |
74132 | 319 |
else if Text.all (/= c) str then [str] |
320 |
else map Text.pack $ space_explode c $ Text.unpack str |
|
74134 | 321 |
trim_line :: Text -> Text |
74136 | 322 |
trim_line s = gen_trim_line (Text.length s) (Text.index s) Text.take s |
74130 | 323 |
|
324 |
instance StringLike Lazy.Text where |
|
74134 | 325 |
space_explode :: Char -> Lazy.Text -> [Lazy.Text] |
74132 | 326 |
space_explode c str = |
74130 | 327 |
if Lazy.null str then [] |
74132 | 328 |
else if Lazy.all (/= c) str then [str] |
329 |
else map Lazy.pack $ space_explode c $ Lazy.unpack str |
|
74134 | 330 |
trim_line :: Lazy.Text -> Lazy.Text |
331 |
trim_line = Lazy.fromStrict . trim_line . Lazy.toStrict |
|
74130 | 332 |
|
333 |
instance StringLike Bytes where |
|
74134 | 334 |
space_explode :: Char -> Bytes -> [Bytes] |
74132 | 335 |
space_explode c str = |
74130 | 336 |
if Bytes.null str then [] |
74135 | 337 |
else if Bytes.all_char (/= c) str then [str] |
74132 | 338 |
else |
339 |
explode (Bytes.unpack str) |
|
340 |
where |
|
341 |
explode rest = |
|
342 |
case span (/= (Bytes.byte c)) rest of |
|
343 |
(_, []) -> [Bytes.pack rest] |
|
344 |
(prfx, _ : rest') -> Bytes.pack prfx : explode rest' |
|
74134 | 345 |
trim_line :: Bytes -> Bytes |
74136 | 346 |
trim_line s = gen_trim_line (Bytes.length s) (Bytes.char . Bytes.index s) Bytes.take s |
74093 | 347 |
|
348 |
class StringLike a => STRING a where make_string :: a -> String |
|
349 |
instance STRING String where make_string = id |
|
350 |
instance STRING Text where make_string = Text.unpack |
|
74096 | 351 |
instance STRING Lazy.Text where make_string = Lazy.unpack |
74093 | 352 |
instance STRING Bytes where make_string = UTF8.decode |
353 |
||
354 |
class StringLike a => TEXT a where make_text :: a -> Text |
|
355 |
instance TEXT String where make_text = Text.pack |
|
356 |
instance TEXT Text where make_text = id |
|
74096 | 357 |
instance TEXT Lazy.Text where make_text = Lazy.toStrict |
74093 | 358 |
instance TEXT Bytes where make_text = UTF8.decode |
359 |
||
360 |
class StringLike a => BYTES a where make_bytes :: a -> Bytes |
|
361 |
instance BYTES String where make_bytes = UTF8.encode |
|
362 |
instance BYTES Text where make_bytes = UTF8.encode |
|
74096 | 363 |
instance BYTES Lazy.Text where make_bytes = UTF8.encode . Lazy.toStrict |
74093 | 364 |
instance BYTES Bytes where make_bytes = id |
365 |
||
74128 | 366 |
show_bytes :: Show a => a -> Bytes |
367 |
show_bytes = make_bytes . show |
|
368 |
||
369 |
show_text :: Show a => a -> Text |
|
370 |
show_text = make_text . show |
|
371 |
||
74093 | 372 |
|
69225 | 373 |
{- strings -} |
374 |
||
74093 | 375 |
proper_string :: StringLike a => a -> Maybe a |
74086 | 376 |
proper_string s = if s == "" then Nothing else Just s |
377 |
||
74185 | 378 |
enclose :: StringLike a => a -> a -> a -> a |
379 |
enclose lpar rpar str = lpar <> str <> rpar |
|
380 |
||
74093 | 381 |
quote :: StringLike a => a -> a |
74185 | 382 |
quote = enclose "\"" "\"" |
69225 | 383 |
|
74093 | 384 |
space_implode :: StringLike a => a -> [a] -> a |
74086 | 385 |
space_implode s = mconcat . separate s |
386 |
||
74093 | 387 |
commas, commas_quote :: StringLike a => [a] -> a |
69453 | 388 |
commas = space_implode ", " |
389 |
commas_quote = commas . map quote |
|
390 |
||
74132 | 391 |
split_lines :: StringLike a => a -> [a] |
392 |
split_lines = space_explode '\n' |
|
393 |
||
74093 | 394 |
cat_lines :: StringLike a => [a] -> a |
69453 | 395 |
cat_lines = space_implode "\n" |
69225 | 396 |
\<close> |
397 |
||
74091 | 398 |
|
399 |
generate_file "Isabelle/Symbol.hs" = \<open> |
|
400 |
{- Title: Isabelle/Symbols.hs |
|
401 |
Author: Makarius |
|
402 |
LICENSE: BSD 3-clause (Isabelle) |
|
403 |
||
404 |
Isabelle text symbols. |
|
74172 | 405 |
|
406 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/symbol.ML\<close> |
|
407 |
and \<^file>\<open>$ISABELLE_HOME/src/Pure/General/symbol_explode.ML\<close>. |
|
74091 | 408 |
-} |
409 |
||
74172 | 410 |
{-# LANGUAGE OverloadedStrings #-} |
411 |
||
412 |
module Isabelle.Symbol ( |
|
74177
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
413 |
Symbol, eof, is_eof, not_eof, |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
414 |
|
74172 | 415 |
is_ascii_letter, is_ascii_digit, is_ascii_hex, is_ascii_quasi, |
416 |
is_ascii_blank, is_ascii_line_terminator, is_ascii_letdig, |
|
417 |
is_ascii_identifier, |
|
418 |
||
74177
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
419 |
explode |
74172 | 420 |
) |
421 |
where |
|
422 |
||
423 |
import Data.Word (Word8) |
|
424 |
import qualified Isabelle.Bytes as Bytes |
|
425 |
import Isabelle.Bytes (Bytes) |
|
426 |
||
74091 | 427 |
|
74177
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
428 |
{- type -} |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
429 |
|
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
430 |
type Symbol = Bytes |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
431 |
|
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
432 |
eof :: Symbol |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
433 |
eof = "" |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
434 |
|
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
435 |
is_eof, not_eof :: Symbol -> Bool |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
436 |
is_eof = Bytes.null |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
437 |
not_eof = not . is_eof |
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
438 |
|
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
439 |
|
74091 | 440 |
{- ASCII characters -} |
441 |
||
442 |
is_ascii_letter :: Char -> Bool |
|
443 |
is_ascii_letter c = 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' |
|
444 |
||
445 |
is_ascii_digit :: Char -> Bool |
|
446 |
is_ascii_digit c = '0' <= c && c <= '9' |
|
447 |
||
448 |
is_ascii_hex :: Char -> Bool |
|
449 |
is_ascii_hex c = '0' <= c && c <= '9' || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f' |
|
450 |
||
451 |
is_ascii_quasi :: Char -> Bool |
|
452 |
is_ascii_quasi c = c == '_' || c == '\'' |
|
453 |
||
454 |
is_ascii_blank :: Char -> Bool |
|
74172 | 455 |
is_ascii_blank c = c `elem` (" \t\n\11\f\r" :: String) |
74091 | 456 |
|
457 |
is_ascii_line_terminator :: Char -> Bool |
|
458 |
is_ascii_line_terminator c = c == '\r' || c == '\n' |
|
459 |
||
460 |
is_ascii_letdig :: Char -> Bool |
|
461 |
is_ascii_letdig c = is_ascii_letter c || is_ascii_digit c || is_ascii_quasi c |
|
462 |
||
463 |
is_ascii_identifier :: String -> Bool |
|
464 |
is_ascii_identifier s = |
|
465 |
not (null s) && is_ascii_letter (head s) && all is_ascii_letdig s |
|
74172 | 466 |
|
467 |
||
468 |
{- explode symbols: ASCII, UTF8, named -} |
|
469 |
||
470 |
is_utf8 :: Word8 -> Bool |
|
471 |
is_utf8 b = b >= 128 |
|
472 |
||
473 |
is_utf8_trailer :: Word8 -> Bool |
|
474 |
is_utf8_trailer b = 128 <= b && b < 192 |
|
475 |
||
476 |
is_utf8_control :: Word8 -> Bool |
|
477 |
is_utf8_control b = 128 <= b && b < 160 |
|
478 |
||
479 |
(|>) :: a -> (a -> b) -> b |
|
480 |
x |> f = f x |
|
481 |
||
482 |
explode :: Bytes -> [Symbol] |
|
483 |
explode string = scan 0 |
|
484 |
where |
|
485 |
byte = Bytes.index string |
|
486 |
substring i j = |
|
487 |
if i == j - 1 then Bytes.singleton (byte i) |
|
488 |
else Bytes.pack (map byte [i .. j - 1]) |
|
489 |
||
490 |
n = Bytes.length string |
|
491 |
test pred i = i < n && pred (byte i) |
|
492 |
test_char pred i = i < n && pred (Bytes.char (byte i)) |
|
493 |
many pred i = if test pred i then many pred (i + 1) else i |
|
494 |
maybe_char c i = if test_char (== c) i then i + 1 else i |
|
495 |
maybe_ascii_id i = |
|
496 |
if test_char is_ascii_letter i |
|
497 |
then many (is_ascii_letdig . Bytes.char) (i + 1) |
|
498 |
else i |
|
499 |
||
500 |
scan i = |
|
501 |
if i < n then |
|
502 |
let |
|
503 |
b = byte i |
|
504 |
c = Bytes.char b |
|
505 |
in |
|
506 |
{-encoded newline-} |
|
507 |
if c == '\r' then "\n" : scan (maybe_char '\n' (i + 1)) |
|
508 |
{-pseudo utf8: encoded ascii control-} |
|
509 |
else if b == 192 && test is_utf8_control (i + 1) && not (test is_utf8 (i + 2)) |
|
510 |
then Bytes.singleton (byte (i + 1) - 128) : scan (i + 2) |
|
511 |
{-utf8-} |
|
512 |
else if is_utf8 b then |
|
513 |
let j = many is_utf8_trailer (i + 1) |
|
514 |
in substring i j : scan j |
|
515 |
{-named symbol-} |
|
516 |
else if c == '\\' && test_char (== '<') (i + 1) then |
|
517 |
let j = (i + 2) |> maybe_char '^' |> maybe_ascii_id |> maybe_char '>' |
|
518 |
in substring i j : scan j |
|
519 |
{-single character-} |
|
520 |
else Bytes.singleton b : scan (i + 1) |
|
521 |
else [] |
|
74091 | 522 |
\<close> |
523 |
||
74095 | 524 |
generate_file "Isabelle/Buffer.hs" = \<open> |
525 |
{- Title: Isabelle/Buffer.hs |
|
526 |
Author: Makarius |
|
527 |
LICENSE: BSD 3-clause (Isabelle) |
|
528 |
||
529 |
Efficient buffer of byte strings. |
|
530 |
||
74178 | 531 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/buffer.ML\<close>. |
74095 | 532 |
-} |
533 |
||
534 |
module Isabelle.Buffer (T, empty, add, content) |
|
535 |
where |
|
536 |
||
537 |
import qualified Isabelle.Bytes as Bytes |
|
538 |
import Isabelle.Bytes (Bytes) |
|
539 |
||
540 |
||
541 |
newtype T = Buffer [Bytes] |
|
542 |
||
543 |
empty :: T |
|
544 |
empty = Buffer [] |
|
545 |
||
546 |
add :: Bytes -> T -> T |
|
547 |
add b (Buffer bs) = Buffer (if Bytes.null b then bs else b : bs) |
|
548 |
||
549 |
content :: T -> Bytes |
|
550 |
content (Buffer bs) = Bytes.concat (reverse bs) |
|
551 |
\<close> |
|
552 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
553 |
generate_file "Isabelle/Value.hs" = \<open> |
73246 | 554 |
{- Title: Isabelle/Value.hs |
69233 | 555 |
Author: Makarius |
556 |
LICENSE: BSD 3-clause (Isabelle) |
|
557 |
||
558 |
Plain values, represented as string. |
|
69280 | 559 |
|
74178 | 560 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/value.ML\<close>. |
69233 | 561 |
-} |
562 |
||
74095 | 563 |
{-# LANGUAGE OverloadedStrings #-} |
564 |
||
69233 | 565 |
module Isabelle.Value |
69452 | 566 |
(print_bool, parse_bool, parse_nat, print_int, parse_int, print_real, parse_real) |
69233 | 567 |
where |
568 |
||
569 |
import qualified Data.List as List |
|
570 |
import qualified Text.Read as Read |
|
74095 | 571 |
import Isabelle.Bytes (Bytes) |
572 |
import Isabelle.Library |
|
69233 | 573 |
|
574 |
||
575 |
{- bool -} |
|
576 |
||
74095 | 577 |
print_bool :: Bool -> Bytes |
69233 | 578 |
print_bool True = "true" |
579 |
print_bool False = "false" |
|
580 |
||
74095 | 581 |
parse_bool :: Bytes -> Maybe Bool |
69233 | 582 |
parse_bool "true" = Just True |
583 |
parse_bool "false" = Just False |
|
584 |
parse_bool _ = Nothing |
|
585 |
||
586 |
||
69452 | 587 |
{- nat -} |
588 |
||
74095 | 589 |
parse_nat :: Bytes -> Maybe Int |
69452 | 590 |
parse_nat s = |
74095 | 591 |
case Read.readMaybe (make_string s) of |
69452 | 592 |
Just n | n >= 0 -> Just n |
593 |
_ -> Nothing |
|
594 |
||
595 |
||
69233 | 596 |
{- int -} |
597 |
||
74095 | 598 |
print_int :: Int -> Bytes |
74128 | 599 |
print_int = show_bytes |
74095 | 600 |
|
601 |
parse_int :: Bytes -> Maybe Int |
|
602 |
parse_int = Read.readMaybe . make_string |
|
69233 | 603 |
|
604 |
||
605 |
{- real -} |
|
606 |
||
74095 | 607 |
print_real :: Double -> Bytes |
69233 | 608 |
print_real x = |
609 |
let s = show x in |
|
610 |
case span (/= '.') s of |
|
74095 | 611 |
(a, '.' : b) | List.all (== '0') b -> make_bytes a |
612 |
_ -> make_bytes s |
|
613 |
||
614 |
parse_real :: Bytes -> Maybe Double |
|
615 |
parse_real = Read.readMaybe . make_string |
|
69225 | 616 |
\<close> |
617 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
618 |
generate_file "Isabelle/Properties.hs" = \<open> |
69445 | 619 |
{- Title: Isabelle/Properties.hs |
69225 | 620 |
Author: Makarius |
621 |
LICENSE: BSD 3-clause (Isabelle) |
|
622 |
||
623 |
Property lists. |
|
69280 | 624 |
|
74178 | 625 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/properties.ML\<close>. |
69225 | 626 |
-} |
627 |
||
69477 | 628 |
module Isabelle.Properties (Entry, T, defined, get, get_value, put, remove) |
69225 | 629 |
where |
630 |
||
631 |
import qualified Data.List as List |
|
74095 | 632 |
import Isabelle.Bytes (Bytes) |
633 |
||
634 |
||
635 |
type Entry = (Bytes, Bytes) |
|
69225 | 636 |
type T = [Entry] |
637 |
||
74095 | 638 |
defined :: T -> Bytes -> Bool |
69225 | 639 |
defined props name = any (\(a, _) -> a == name) props |
640 |
||
74095 | 641 |
get :: T -> Bytes -> Maybe Bytes |
69225 | 642 |
get props name = List.lookup name props |
643 |
||
74095 | 644 |
get_value :: (Bytes -> Maybe a) -> T -> Bytes -> Maybe a |
69477 | 645 |
get_value parse props name = |
646 |
case get props name of |
|
647 |
Nothing -> Nothing |
|
648 |
Just s -> parse s |
|
649 |
||
69225 | 650 |
put :: Entry -> T -> T |
651 |
put entry props = entry : remove (fst entry) props |
|
652 |
||
74095 | 653 |
remove :: Bytes -> T -> T |
69225 | 654 |
remove name props = |
655 |
if defined props name then filter (\(a, _) -> a /= name) props |
|
656 |
else props |
|
657 |
\<close> |
|
658 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
659 |
generate_file "Isabelle/Markup.hs" = \<open> |
73246 | 660 |
{- Title: Isabelle/Markup.hs |
69225 | 661 |
Author: Makarius |
662 |
LICENSE: BSD 3-clause (Isabelle) |
|
663 |
||
664 |
Quasi-abstract markup elements. |
|
69280 | 665 |
|
74178 | 666 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/markup.ML\<close>. |
69225 | 667 |
-} |
668 |
||
74095 | 669 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 670 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
671 |
||
69234 | 672 |
module Isabelle.Markup ( |
673 |
T, empty, is_empty, properties, |
|
674 |
||
675 |
nameN, name, xnameN, xname, kindN, |
|
676 |
||
69315 | 677 |
bindingN, binding, entityN, entity, defN, refN, |
678 |
||
69288 | 679 |
completionN, completion, no_completionN, no_completion, |
680 |
||
69234 | 681 |
lineN, end_lineN, offsetN, end_offsetN, fileN, idN, positionN, position, |
74182 | 682 |
position_properties, def_name, |
69234 | 683 |
|
69291 | 684 |
expressionN, expression, |
685 |
||
686 |
citationN, citation, |
|
687 |
||
71489 | 688 |
pathN, path, urlN, url, docN, doc, |
69291 | 689 |
|
69248 | 690 |
markupN, consistentN, unbreakableN, indentN, widthN, |
691 |
blockN, block, breakN, break, fbreakN, fbreak, itemN, item, |
|
692 |
||
69968
1a400b14fd3a
clarified spell-checking (see also 30233285270a);
wenzelm
parents:
69794
diff
changeset
|
693 |
wordsN, words, |
69234 | 694 |
|
695 |
tfreeN, tfree, tvarN, tvar, freeN, free, skolemN, skolem, boundN, bound, varN, var, |
|
696 |
numeralN, numeral, literalN, literal, delimiterN, delimiter, inner_stringN, inner_string, |
|
69320 | 697 |
inner_cartoucheN, inner_cartouche, |
69234 | 698 |
token_rangeN, token_range, |
699 |
sortingN, sorting, typingN, typing, class_parameterN, class_parameter, |
|
700 |
||
701 |
antiquotedN, antiquoted, antiquoteN, antiquote, |
|
702 |
||
703 |
paragraphN, paragraph, text_foldN, text_fold, |
|
704 |
||
705 |
keyword1N, keyword1, keyword2N, keyword2, keyword3N, keyword3, quasi_keywordN, quasi_keyword, |
|
706 |
improperN, improper, operatorN, operator, stringN, string, alt_stringN, alt_string, |
|
69320 | 707 |
verbatimN, verbatim, cartoucheN, cartouche, commentN, comment, comment1N, comment1, |
708 |
comment2N, comment2, comment3N, comment3, |
|
69234 | 709 |
|
70667 | 710 |
forkedN, forked, joinedN, joined, runningN, running, finishedN, finished, |
69794 | 711 |
failedN, failed, canceledN, canceled, initializedN, initialized, finalizedN, finalized, |
712 |
consolidatedN, consolidated, |
|
713 |
||
69234 | 714 |
writelnN, writeln, stateN, state, informationN, information, tracingN, tracing, |
715 |
warningN, warning, legacyN, legacy, errorN, error, reportN, report, no_reportN, no_report, |
|
716 |
||
717 |
intensifyN, intensify, |
|
718 |
Output, no_output) |
|
69225 | 719 |
where |
720 |
||
69248 | 721 |
import Prelude hiding (words, error, break) |
74182 | 722 |
import Data.Map.Strict (Map) |
723 |
import qualified Data.Map.Strict as Map |
|
69234 | 724 |
|
725 |
import Isabelle.Library |
|
69225 | 726 |
import qualified Isabelle.Properties as Properties |
69248 | 727 |
import qualified Isabelle.Value as Value |
74095 | 728 |
import qualified Isabelle.Bytes as Bytes |
729 |
import Isabelle.Bytes (Bytes) |
|
69225 | 730 |
|
731 |
||
69234 | 732 |
{- basic markup -} |
733 |
||
74095 | 734 |
type T = (Bytes, Properties.T) |
69225 | 735 |
|
736 |
empty :: T |
|
737 |
empty = ("", []) |
|
738 |
||
739 |
is_empty :: T -> Bool |
|
740 |
is_empty ("", _) = True |
|
741 |
is_empty _ = False |
|
742 |
||
69234 | 743 |
properties :: Properties.T -> T -> T |
744 |
properties more_props (elem, props) = |
|
745 |
(elem, fold_rev Properties.put more_props props) |
|
746 |
||
74095 | 747 |
markup_elem :: Bytes -> T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
748 |
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
|
749 |
|
74095 | 750 |
markup_string :: Bytes -> Bytes -> Bytes -> T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
751 |
markup_string name prop = \s -> (name, [(prop, s)]) |
69234 | 752 |
|
753 |
||
754 |
{- misc properties -} |
|
755 |
||
74095 | 756 |
nameN :: Bytes |
69234 | 757 |
nameN = \<open>Markup.nameN\<close> |
758 |
||
74095 | 759 |
name :: Bytes -> T -> T |
69234 | 760 |
name a = properties [(nameN, a)] |
761 |
||
74095 | 762 |
xnameN :: Bytes |
69234 | 763 |
xnameN = \<open>Markup.xnameN\<close> |
764 |
||
74095 | 765 |
xname :: Bytes -> T -> T |
69234 | 766 |
xname a = properties [(xnameN, a)] |
767 |
||
74095 | 768 |
kindN :: Bytes |
69234 | 769 |
kindN = \<open>Markup.kindN\<close> |
770 |
||
771 |
||
69315 | 772 |
{- formal entities -} |
773 |
||
74095 | 774 |
bindingN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
775 |
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
|
776 |
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
|
777 |
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
|
778 |
|
74095 | 779 |
entityN :: Bytes |
69315 | 780 |
entityN = \<open>Markup.entityN\<close> |
74095 | 781 |
entity :: Bytes -> Bytes -> T |
69315 | 782 |
entity kind name = |
783 |
(entityN, |
|
74095 | 784 |
(if Bytes.null name then [] else [(nameN, name)]) <> |
785 |
(if Bytes.null kind then [] else [(kindN, kind)])) |
|
786 |
||
787 |
defN :: Bytes |
|
69315 | 788 |
defN = \<open>Markup.defN\<close> |
789 |
||
74095 | 790 |
refN :: Bytes |
69315 | 791 |
refN = \<open>Markup.refN\<close> |
792 |
||
793 |
||
69288 | 794 |
{- completion -} |
795 |
||
74095 | 796 |
completionN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
797 |
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
|
798 |
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
|
799 |
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
|
800 |
|
74095 | 801 |
no_completionN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
802 |
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
|
803 |
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
|
804 |
no_completion = markup_elem no_completionN |
69288 | 805 |
|
806 |
||
69234 | 807 |
{- position -} |
808 |
||
74095 | 809 |
lineN, end_lineN :: Bytes |
69234 | 810 |
lineN = \<open>Markup.lineN\<close> |
811 |
end_lineN = \<open>Markup.end_lineN\<close> |
|
812 |
||
74095 | 813 |
offsetN, end_offsetN :: Bytes |
69234 | 814 |
offsetN = \<open>Markup.offsetN\<close> |
815 |
end_offsetN = \<open>Markup.end_offsetN\<close> |
|
816 |
||
74095 | 817 |
fileN, idN :: Bytes |
69234 | 818 |
fileN = \<open>Markup.fileN\<close> |
819 |
idN = \<open>Markup.idN\<close> |
|
820 |
||
74095 | 821 |
positionN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
822 |
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
|
823 |
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
|
824 |
position = markup_elem positionN |
69234 | 825 |
|
74182 | 826 |
position_properties :: [Bytes] |
827 |
position_properties = [lineN, offsetN, end_offsetN, fileN, idN] |
|
828 |
||
829 |
||
830 |
{- position "def" names -} |
|
831 |
||
832 |
make_def :: Bytes -> Bytes |
|
833 |
make_def a = "def_" <> a |
|
834 |
||
835 |
def_names :: Map Bytes Bytes |
|
836 |
def_names = Map.fromList $ map (\a -> (a, make_def a)) position_properties |
|
837 |
||
838 |
def_name :: Bytes -> Bytes |
|
839 |
def_name a = |
|
840 |
case Map.lookup a def_names of |
|
841 |
Just b -> b |
|
842 |
Nothing -> make_def a |
|
843 |
||
69234 | 844 |
|
69291 | 845 |
{- expression -} |
846 |
||
74095 | 847 |
expressionN :: Bytes |
69291 | 848 |
expressionN = \<open>Markup.expressionN\<close> |
849 |
||
74095 | 850 |
expression :: Bytes -> T |
69291 | 851 |
expression kind = (expressionN, if kind == "" then [] else [(kindN, kind)]) |
852 |
||
853 |
||
854 |
{- citation -} |
|
855 |
||
74095 | 856 |
citationN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
857 |
citationN = \<open>Markup.citationN\<close> |
74095 | 858 |
citation :: Bytes -> T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
859 |
citation = markup_string nameN citationN |
69291 | 860 |
|
861 |
||
862 |
{- external resources -} |
|
863 |
||
74095 | 864 |
pathN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
865 |
pathN = \<open>Markup.pathN\<close> |
74095 | 866 |
path :: Bytes -> T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
867 |
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
|
868 |
|
74095 | 869 |
urlN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
870 |
urlN = \<open>Markup.urlN\<close> |
74095 | 871 |
url :: Bytes -> T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
872 |
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
|
873 |
|
74095 | 874 |
docN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
875 |
docN = \<open>Markup.docN\<close> |
74095 | 876 |
doc :: Bytes -> T |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
877 |
doc = markup_string docN nameN |
69291 | 878 |
|
879 |
||
69248 | 880 |
{- pretty printing -} |
881 |
||
74095 | 882 |
markupN, consistentN, unbreakableN, indentN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
883 |
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
|
884 |
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
|
885 |
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
|
886 |
indentN = \<open>Markup.indentN\<close> |
69248 | 887 |
|
74095 | 888 |
widthN :: Bytes |
69248 | 889 |
widthN = \<open>Markup.widthN\<close> |
890 |
||
74095 | 891 |
blockN :: Bytes |
69248 | 892 |
blockN = \<open>Markup.blockN\<close> |
893 |
block :: Bool -> Int -> T |
|
894 |
block c i = |
|
895 |
(blockN, |
|
74081 | 896 |
(if c then [(consistentN, Value.print_bool c)] else []) <> |
69248 | 897 |
(if i /= 0 then [(indentN, Value.print_int i)] else [])) |
898 |
||
74095 | 899 |
breakN :: Bytes |
69248 | 900 |
breakN = \<open>Markup.breakN\<close> |
901 |
break :: Int -> Int -> T |
|
902 |
break w i = |
|
903 |
(breakN, |
|
74081 | 904 |
(if w /= 0 then [(widthN, Value.print_int w)] else []) <> |
69248 | 905 |
(if i /= 0 then [(indentN, Value.print_int i)] else [])) |
906 |
||
74095 | 907 |
fbreakN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
908 |
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
|
909 |
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
|
910 |
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
|
911 |
|
74095 | 912 |
itemN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
913 |
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
|
914 |
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
|
915 |
item = markup_elem itemN |
69248 | 916 |
|
917 |
||
69234 | 918 |
{- text properties -} |
919 |
||
74095 | 920 |
wordsN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
921 |
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
|
922 |
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
|
923 |
words = markup_elem wordsN |
69234 | 924 |
|
925 |
||
926 |
{- inner syntax -} |
|
927 |
||
74095 | 928 |
tfreeN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
929 |
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
|
930 |
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
|
931 |
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
|
932 |
|
74095 | 933 |
tvarN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
934 |
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
|
935 |
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
|
936 |
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
|
937 |
|
74095 | 938 |
freeN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
939 |
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
|
940 |
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
|
941 |
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
|
942 |
|
74095 | 943 |
skolemN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
944 |
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
|
945 |
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
|
946 |
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
|
947 |
|
74095 | 948 |
boundN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
949 |
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
|
950 |
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
|
951 |
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
|
952 |
|
74095 | 953 |
varN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
954 |
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
|
955 |
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
|
956 |
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
|
957 |
|
74095 | 958 |
numeralN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
959 |
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
|
960 |
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
|
961 |
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
|
962 |
|
74095 | 963 |
literalN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
964 |
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
|
965 |
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
|
966 |
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
|
967 |
|
74095 | 968 |
delimiterN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
969 |
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
|
970 |
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
|
971 |
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
|
972 |
|
74095 | 973 |
inner_stringN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
974 |
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
|
975 |
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
|
976 |
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
|
977 |
|
74095 | 978 |
inner_cartoucheN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
979 |
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
|
980 |
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
|
981 |
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
|
982 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
983 |
|
74095 | 984 |
token_rangeN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
985 |
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
|
986 |
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
|
987 |
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
|
988 |
|
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
989 |
|
74095 | 990 |
sortingN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
991 |
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
|
992 |
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
|
993 |
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
|
994 |
|
74095 | 995 |
typingN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
996 |
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
|
997 |
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
|
998 |
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
|
999 |
|
74095 | 1000 |
class_parameterN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1001 |
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
|
1002 |
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
|
1003 |
class_parameter = markup_elem class_parameterN |
69234 | 1004 |
|
1005 |
||
1006 |
{- antiquotations -} |
|
1007 |
||
74095 | 1008 |
antiquotedN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1009 |
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
|
1010 |
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
|
1011 |
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
|
1012 |
|
74095 | 1013 |
antiquoteN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1014 |
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
|
1015 |
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
|
1016 |
antiquote = markup_elem antiquoteN |
69234 | 1017 |
|
1018 |
||
1019 |
{- text structure -} |
|
1020 |
||
74095 | 1021 |
paragraphN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1022 |
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
|
1023 |
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
|
1024 |
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
|
1025 |
|
74095 | 1026 |
text_foldN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1027 |
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
|
1028 |
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
|
1029 |
text_fold = markup_elem text_foldN |
69234 | 1030 |
|
1031 |
||
1032 |
{- outer syntax -} |
|
1033 |
||
74095 | 1034 |
keyword1N :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1035 |
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
|
1036 |
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
|
1037 |
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
|
1038 |
|
74095 | 1039 |
keyword2N :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1040 |
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
|
1041 |
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
|
1042 |
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
|
1043 |
|
74095 | 1044 |
keyword3N :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1045 |
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
|
1046 |
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
|
1047 |
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
|
1048 |
|
74095 | 1049 |
quasi_keywordN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1050 |
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
|
1051 |
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
|
1052 |
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
|
1053 |
|
74095 | 1054 |
improperN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1055 |
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
|
1056 |
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
|
1057 |
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
|
1058 |
|
74095 | 1059 |
operatorN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1060 |
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
|
1061 |
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
|
1062 |
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
|
1063 |
|
74095 | 1064 |
stringN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1065 |
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
|
1066 |
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
|
1067 |
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
|
1068 |
|
74095 | 1069 |
alt_stringN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1070 |
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
|
1071 |
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
|
1072 |
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
|
1073 |
|
74095 | 1074 |
verbatimN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1075 |
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
|
1076 |
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
|
1077 |
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
|
1078 |
|
74095 | 1079 |
cartoucheN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1080 |
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
|
1081 |
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
|
1082 |
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
|
1083 |
|
74095 | 1084 |
commentN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1085 |
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
|
1086 |
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
|
1087 |
comment = markup_elem commentN |
69234 | 1088 |
|
1089 |
||
69320 | 1090 |
{- comments -} |
1091 |
||
74095 | 1092 |
comment1N :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1093 |
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
|
1094 |
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
|
1095 |
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
|
1096 |
|
74095 | 1097 |
comment2N :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1098 |
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
|
1099 |
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
|
1100 |
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
|
1101 |
|
74095 | 1102 |
comment3N :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1103 |
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
|
1104 |
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
|
1105 |
comment3 = markup_elem comment3N |
69320 | 1106 |
|
1107 |
||
69793 | 1108 |
{- command status -} |
1109 |
||
70667 | 1110 |
forkedN, joinedN, runningN, finishedN, failedN, canceledN, |
74095 | 1111 |
initializedN, finalizedN, consolidatedN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1112 |
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
|
1113 |
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
|
1114 |
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
|
1115 |
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
|
1116 |
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
|
1117 |
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
|
1118 |
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
|
1119 |
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
|
1120 |
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
|
1121 |
|
70667 | 1122 |
forked, joined, running, finished, failed, canceled, |
69793 | 1123 |
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
|
1124 |
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
|
1125 |
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
|
1126 |
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
|
1127 |
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
|
1128 |
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
|
1129 |
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
|
1130 |
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
|
1131 |
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
|
1132 |
consolidated = markup_elem consolidatedN |
69793 | 1133 |
|
1134 |
||
69234 | 1135 |
{- messages -} |
1136 |
||
74095 | 1137 |
writelnN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1138 |
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
|
1139 |
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
|
1140 |
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
|
1141 |
|
74095 | 1142 |
stateN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1143 |
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
|
1144 |
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
|
1145 |
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
|
1146 |
|
74095 | 1147 |
informationN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1148 |
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
|
1149 |
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
|
1150 |
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
|
1151 |
|
74095 | 1152 |
tracingN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1153 |
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
|
1154 |
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
|
1155 |
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
|
1156 |
|
74095 | 1157 |
warningN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1158 |
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
|
1159 |
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
|
1160 |
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
|
1161 |
|
74095 | 1162 |
legacyN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1163 |
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
|
1164 |
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
|
1165 |
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
|
1166 |
|
74095 | 1167 |
errorN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1168 |
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
|
1169 |
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
|
1170 |
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
|
1171 |
|
74095 | 1172 |
reportN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1173 |
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
|
1174 |
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
|
1175 |
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
|
1176 |
|
74095 | 1177 |
no_reportN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1178 |
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
|
1179 |
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
|
1180 |
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
|
1181 |
|
74095 | 1182 |
intensifyN :: Bytes |
73199
d300574cee4e
more robust type signatures, notably for the sake of haskell-stack-trace-plugin-0.1.1.1;
wenzelm
parents:
73178
diff
changeset
|
1183 |
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
|
1184 |
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
|
1185 |
intensify = markup_elem intensifyN |
69234 | 1186 |
|
1187 |
||
1188 |
{- output -} |
|
69225 | 1189 |
|
74095 | 1190 |
type Output = (Bytes, Bytes) |
69225 | 1191 |
|
1192 |
no_output :: Output |
|
1193 |
no_output = ("", "") |
|
69222 | 1194 |
\<close> |
1195 |
||
74167 | 1196 |
generate_file "Isabelle/Position.hs" = \<open> |
1197 |
{- Title: Isabelle/Position.hs |
|
1198 |
Author: Makarius |
|
1199 |
LICENSE: BSD 3-clause (Isabelle) |
|
1200 |
||
74173 | 1201 |
Source positions starting from 1; values <= 0 mean "absent". Count Isabelle |
1202 |
symbols, not UTF8 bytes nor UTF16 characters. Position range specifies a |
|
1203 |
right-open interval offset .. end_offset (exclusive). |
|
74167 | 1204 |
|
74178 | 1205 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/position.ML\<close>. |
74167 | 1206 |
-} |
1207 |
||
1208 |
{-# LANGUAGE OverloadedStrings #-} |
|
1209 |
||
1210 |
module Isabelle.Position ( |
|
1211 |
T, line_of, column_of, offset_of, end_offset_of, file_of, id_of, |
|
74185 | 1212 |
start, none, put_file, file, file_only, put_id, id, id_only, |
74174 | 1213 |
symbol, symbol_explode, symbol_explode_string, shift_offsets, |
74184 | 1214 |
of_properties, properties_of, def_properties_of, entity_markup, make_entity_markup, |
74187 | 1215 |
Report, Report_Text, is_reported, is_reported_range, here, |
74167 | 1216 |
Range, no_range, no_range_position, range_position, range |
74184 | 1217 |
) |
1218 |
where |
|
74167 | 1219 |
|
74185 | 1220 |
import Prelude hiding (id) |
74168
f0b2136e2204
tuned signature: prefer existing Haskell operations;
wenzelm
parents:
74167
diff
changeset
|
1221 |
import Data.Maybe (isJust, fromMaybe) |
74182 | 1222 |
import Data.Bifunctor (first) |
74167 | 1223 |
import qualified Isabelle.Properties as Properties |
1224 |
import qualified Isabelle.Bytes as Bytes |
|
1225 |
import qualified Isabelle.Value as Value |
|
1226 |
import Isabelle.Bytes (Bytes) |
|
1227 |
import qualified Isabelle.Markup as Markup |
|
1228 |
import qualified Isabelle.YXML as YXML |
|
1229 |
import Isabelle.Library |
|
74173 | 1230 |
import qualified Isabelle.Symbol as Symbol |
1231 |
import Isabelle.Symbol (Symbol) |
|
74167 | 1232 |
|
1233 |
||
1234 |
{- position -} |
|
1235 |
||
1236 |
data T = |
|
1237 |
Position { |
|
1238 |
_line :: Int, |
|
1239 |
_column :: Int, |
|
1240 |
_offset :: Int, |
|
1241 |
_end_offset :: Int, |
|
1242 |
_file :: Bytes, |
|
1243 |
_id :: Bytes } |
|
1244 |
deriving (Eq, Ord) |
|
1245 |
||
74173 | 1246 |
valid, invalid :: Int -> Bool |
1247 |
valid i = i > 0 |
|
1248 |
invalid = not . valid |
|
74167 | 1249 |
|
1250 |
maybe_valid :: Int -> Maybe Int |
|
74173 | 1251 |
maybe_valid i = if valid i then Just i else Nothing |
1252 |
||
1253 |
if_valid :: Int -> Int -> Int |
|
1254 |
if_valid i i' = if valid i then i' else i |
|
74167 | 1255 |
|
1256 |
||
1257 |
{- fields -} |
|
1258 |
||
1259 |
line_of, column_of, offset_of, end_offset_of :: T -> Maybe Int |
|
1260 |
line_of = maybe_valid . _line |
|
1261 |
column_of = maybe_valid . _column |
|
1262 |
offset_of = maybe_valid . _offset |
|
1263 |
end_offset_of = maybe_valid . _end_offset |
|
1264 |
||
1265 |
file_of :: T -> Maybe Bytes |
|
1266 |
file_of = proper_string . _file |
|
1267 |
||
1268 |
id_of :: T -> Maybe Bytes |
|
1269 |
id_of = proper_string . _id |
|
1270 |
||
1271 |
||
1272 |
{- make position -} |
|
1273 |
||
1274 |
start :: T |
|
1275 |
start = Position 1 1 1 0 Bytes.empty Bytes.empty |
|
1276 |
||
1277 |
none :: T |
|
1278 |
none = Position 0 0 0 0 Bytes.empty Bytes.empty |
|
1279 |
||
1280 |
put_file :: Bytes -> T -> T |
|
1281 |
put_file file pos = pos { _file = file } |
|
1282 |
||
1283 |
file :: Bytes -> T |
|
1284 |
file file = put_file file start |
|
1285 |
||
1286 |
file_only :: Bytes -> T |
|
1287 |
file_only file = put_file file none |
|
1288 |
||
1289 |
put_id :: Bytes -> T -> T |
|
1290 |
put_id id pos = pos { _id = id } |
|
1291 |
||
74185 | 1292 |
id :: Bytes -> T |
1293 |
id id = put_id id start |
|
1294 |
||
1295 |
id_only :: Bytes -> T |
|
1296 |
id_only id = put_id id none |
|
1297 |
||
74167 | 1298 |
|
74176 | 1299 |
{- count position -} |
1300 |
||
1301 |
count_line :: Symbol -> Int -> Int |
|
1302 |
count_line "\n" line = if_valid line (line + 1) |
|
1303 |
count_line _ line = line |
|
1304 |
||
1305 |
count_column :: Symbol -> Int -> Int |
|
1306 |
count_column "\n" column = if_valid column 1 |
|
74177
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
1307 |
count_column s column = if Symbol.not_eof s then if_valid column (column + 1) else column |
74176 | 1308 |
|
1309 |
count_offset :: Symbol -> Int -> Int |
|
74177
a8b032dede5c
treat Symbol.eof as in ML (but: presently unused);
wenzelm
parents:
74176
diff
changeset
|
1310 |
count_offset s offset = if Symbol.not_eof s then if_valid offset (offset + 1) else offset |
74173 | 1311 |
|
74174 | 1312 |
symbol :: Symbol -> T -> T |
1313 |
symbol s pos = |
|
74167 | 1314 |
pos { |
74176 | 1315 |
_line = count_line s (_line pos), |
1316 |
_column = count_column s (_column pos), |
|
1317 |
_offset = count_offset s (_offset pos) } |
|
74173 | 1318 |
|
74174 | 1319 |
symbol_explode :: BYTES a => a -> T -> T |
1320 |
symbol_explode = fold symbol . Symbol.explode . make_bytes |
|
1321 |
||
1322 |
symbol_explode_string :: String -> T -> T |
|
1323 |
symbol_explode_string = symbol_explode |
|
74167 | 1324 |
|
1325 |
||
1326 |
{- shift offsets -} |
|
1327 |
||
1328 |
shift_offsets :: Int -> T -> T |
|
1329 |
shift_offsets shift pos = pos { _offset = offset', _end_offset = end_offset' } |
|
1330 |
where |
|
1331 |
offset = _offset pos |
|
1332 |
end_offset = _end_offset pos |
|
1333 |
offset' = if invalid offset || invalid shift then offset else offset + shift |
|
1334 |
end_offset' = if invalid end_offset || invalid shift then end_offset else end_offset + shift |
|
1335 |
||
1336 |
||
1337 |
{- markup properties -} |
|
1338 |
||
1339 |
get_string :: Properties.T -> Bytes -> Bytes |
|
74168
f0b2136e2204
tuned signature: prefer existing Haskell operations;
wenzelm
parents:
74167
diff
changeset
|
1340 |
get_string props name = fromMaybe "" (Properties.get_value Just props name) |
74167 | 1341 |
|
1342 |
get_int :: Properties.T -> Bytes -> Int |
|
74168
f0b2136e2204
tuned signature: prefer existing Haskell operations;
wenzelm
parents:
74167
diff
changeset
|
1343 |
get_int props name = fromMaybe 0 (Properties.get_value Value.parse_int props name) |
74167 | 1344 |
|
1345 |
of_properties :: Properties.T -> T |
|
1346 |
of_properties props = |
|
1347 |
none { |
|
1348 |
_line = get_int props Markup.lineN, |
|
1349 |
_offset = get_int props Markup.offsetN, |
|
1350 |
_end_offset = get_int props Markup.end_offsetN, |
|
1351 |
_file = get_string props Markup.fileN, |
|
1352 |
_id = get_string props Markup.idN } |
|
1353 |
||
1354 |
string_entry :: Bytes -> Bytes -> Properties.T |
|
1355 |
string_entry k s = if Bytes.null s then [] else [(k, s)] |
|
1356 |
||
1357 |
int_entry :: Bytes -> Int -> Properties.T |
|
1358 |
int_entry k i = if invalid i then [] else [(k, Value.print_int i)] |
|
1359 |
||
1360 |
properties_of :: T -> Properties.T |
|
1361 |
properties_of pos = |
|
1362 |
int_entry Markup.lineN (_line pos) ++ |
|
1363 |
int_entry Markup.offsetN (_offset pos) ++ |
|
1364 |
int_entry Markup.end_offsetN (_end_offset pos) ++ |
|
1365 |
string_entry Markup.fileN (_file pos) ++ |
|
1366 |
string_entry Markup.idN (_id pos) |
|
1367 |
||
1368 |
def_properties_of :: T -> Properties.T |
|
74182 | 1369 |
def_properties_of = properties_of #> map (first Markup.def_name) |
74167 | 1370 |
|
1371 |
entity_markup :: Bytes -> (Bytes, T) -> Markup.T |
|
1372 |
entity_markup kind (name, pos) = |
|
1373 |
Markup.entity kind name |> Markup.properties (def_properties_of pos) |
|
1374 |
||
74184 | 1375 |
make_entity_markup :: Bool -> Int -> Bytes -> (Bytes, T) -> Markup.T |
1376 |
make_entity_markup def serial kind (name, pos) = |
|
1377 |
let |
|
1378 |
props = |
|
1379 |
if def then (Markup.defN, Value.print_int serial) : properties_of pos |
|
1380 |
else (Markup.refN, Value.print_int serial) : def_properties_of pos |
|
1381 |
in Markup.entity kind name |> Markup.properties props |
|
74167 | 1382 |
|
1383 |
||
1384 |
{- reports -} |
|
1385 |
||
74187 | 1386 |
type Report = (T, Markup.T) |
1387 |
type Report_Text = (Report, Bytes) |
|
1388 |
||
74167 | 1389 |
is_reported :: T -> Bool |
1390 |
is_reported pos = isJust (offset_of pos) && isJust (id_of pos) |
|
1391 |
||
1392 |
is_reported_range :: T -> Bool |
|
1393 |
is_reported_range pos = is_reported pos && isJust (end_offset_of pos) |
|
1394 |
||
1395 |
||
1396 |
{- here: user output -} |
|
1397 |
||
1398 |
here :: T -> Bytes |
|
1399 |
here pos = if Bytes.null s2 then "" else s1 <> m1 <> s2 <> m2 |
|
1400 |
where |
|
1401 |
props = properties_of pos |
|
1402 |
(m1, m2) = YXML.output_markup (Markup.properties props Markup.position) |
|
1403 |
(s1, s2) = |
|
1404 |
case (line_of pos, file_of pos) of |
|
1405 |
(Just i, Nothing) -> (" ", "(line " <> Value.print_int i <> ")") |
|
1406 |
(Just i, Just name) -> (" ", "(line " <> Value.print_int i <> " of " <> quote name <> ")") |
|
1407 |
(Nothing, Just name) -> (" ", "(file " <> quote name <> ")") |
|
1408 |
_ -> if is_reported pos then ("", "\092<^here>") else ("", "") |
|
1409 |
||
1410 |
||
1411 |
{- range -} |
|
1412 |
||
1413 |
type Range = (T, T) |
|
1414 |
||
1415 |
no_range :: Range |
|
1416 |
no_range = (none, none) |
|
1417 |
||
1418 |
no_range_position :: T -> T |
|
1419 |
no_range_position pos = pos { _end_offset = 0 } |
|
1420 |
||
1421 |
range_position :: Range -> T |
|
1422 |
range_position (pos, pos') = pos { _end_offset = _offset pos' } |
|
1423 |
||
1424 |
range :: Range -> Range |
|
1425 |
range (pos, pos') = (range_position (pos, pos'), no_range_position pos') |
|
1426 |
\<close> |
|
1427 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1428 |
generate_file "Isabelle/XML.hs" = \<open> |
69445 | 1429 |
{- Title: Isabelle/XML.hs |
69225 | 1430 |
Author: Makarius |
1431 |
LICENSE: BSD 3-clause (Isabelle) |
|
1432 |
||
1433 |
Untyped XML trees and representation of ML values. |
|
69280 | 1434 |
|
74178 | 1435 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/xml.ML\<close>. |
69225 | 1436 |
-} |
1437 |
||
74095 | 1438 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 1439 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
1440 |
||
69225 | 1441 |
module Isabelle.XML (Attributes, Body, Tree(..), wrap_elem, unwrap_elem, content_of) |
1442 |
where |
|
1443 |
||
1444 |
import Isabelle.Library |
|
1445 |
import qualified Isabelle.Properties as Properties |
|
1446 |
import qualified Isabelle.Markup as Markup |
|
1447 |
import qualified Isabelle.Buffer as Buffer |
|
74095 | 1448 |
import qualified Isabelle.Bytes as Bytes |
1449 |
import Isabelle.Bytes (Bytes) |
|
69225 | 1450 |
|
1451 |
||
1452 |
{- types -} |
|
1453 |
||
1454 |
type Attributes = Properties.T |
|
1455 |
type Body = [Tree] |
|
74095 | 1456 |
data Tree = Elem (Markup.T, Body) | Text Bytes |
69225 | 1457 |
|
1458 |
||
1459 |
{- wrapped elements -} |
|
1460 |
||
69482 | 1461 |
wrap_elem :: ((Markup.T, Body), [Tree]) -> Tree |
69236 | 1462 |
wrap_elem (((a, atts), body1), body2) = |
69290 | 1463 |
Elem ((\<open>XML.xml_elemN\<close>, (\<open>XML.xml_nameN\<close>, a) : atts), Elem ((\<open>XML.xml_bodyN\<close>, []), body1) : body2) |
69225 | 1464 |
|
69482 | 1465 |
unwrap_elem :: Tree -> Maybe ((Markup.T, Body), [Tree]) |
69236 | 1466 |
unwrap_elem |
69290 | 1467 |
(Elem ((\<open>XML.xml_elemN\<close>, (\<open>XML.xml_nameN\<close>, a) : atts), Elem ((\<open>XML.xml_bodyN\<close>, []), body1) : body2)) = |
69236 | 1468 |
Just (((a, atts), body1), body2) |
69225 | 1469 |
unwrap_elem _ = Nothing |
1470 |
||
1471 |
||
1472 |
{- text content -} |
|
1473 |
||
69482 | 1474 |
add_content :: Tree -> Buffer.T -> Buffer.T |
69225 | 1475 |
add_content tree = |
1476 |
case unwrap_elem tree of |
|
1477 |
Just (_, ts) -> fold add_content ts |
|
1478 |
Nothing -> |
|
1479 |
case tree of |
|
69290 | 1480 |
Elem (_, ts) -> fold add_content ts |
69225 | 1481 |
Text s -> Buffer.add s |
1482 |
||
74095 | 1483 |
content_of :: Body -> Bytes |
69225 | 1484 |
content_of body = Buffer.empty |> fold add_content body |> Buffer.content |
1485 |
||
1486 |
||
1487 |
{- string representation -} |
|
1488 |
||
74095 | 1489 |
encode_char :: Char -> String |
1490 |
encode_char '<' = "<" |
|
1491 |
encode_char '>' = ">" |
|
1492 |
encode_char '&' = "&" |
|
1493 |
encode_char '\'' = "'" |
|
1494 |
encode_char '\"' = """ |
|
1495 |
encode_char c = [c] |
|
1496 |
||
1497 |
encode_text :: Bytes -> Bytes |
|
1498 |
encode_text = make_bytes . concatMap (encode_char . Bytes.char) . Bytes.unpack |
|
69225 | 1499 |
|
1500 |
instance Show Tree where |
|
1501 |
show tree = |
|
74095 | 1502 |
Buffer.empty |> show_tree tree |> Buffer.content |> make_string |
69225 | 1503 |
where |
69290 | 1504 |
show_tree (Elem ((name, atts), [])) = |
69225 | 1505 |
Buffer.add "<" #> Buffer.add (show_elem name atts) #> Buffer.add "/>" |
69290 | 1506 |
show_tree (Elem ((name, atts), ts)) = |
69225 | 1507 |
Buffer.add "<" #> Buffer.add (show_elem name atts) #> Buffer.add ">" #> |
1508 |
fold show_tree ts #> |
|
1509 |
Buffer.add "</" #> Buffer.add name #> Buffer.add ">" |
|
74095 | 1510 |
show_tree (Text s) = Buffer.add (encode_text s) |
69225 | 1511 |
|
1512 |
show_elem name atts = |
|
74095 | 1513 |
space_implode " " (name : map (\(a, x) -> a <> "=\"" <> encode_text x <> "\"") atts) |
69225 | 1514 |
\<close> |
1515 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1516 |
generate_file "Isabelle/XML/Encode.hs" = \<open> |
69445 | 1517 |
{- Title: Isabelle/XML/Encode.hs |
69240 | 1518 |
Author: Makarius |
1519 |
LICENSE: BSD 3-clause (Isabelle) |
|
1520 |
||
1521 |
XML as data representation language. |
|
69280 | 1522 |
|
74178 | 1523 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/xml.ML\<close>. |
69240 | 1524 |
-} |
1525 |
||
74095 | 1526 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 1527 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
1528 |
||
69240 | 1529 |
module Isabelle.XML.Encode ( |
70845 | 1530 |
A, T, V, P, |
69240 | 1531 |
|
1532 |
int_atom, bool_atom, unit_atom, |
|
1533 |
||
71490 | 1534 |
tree, properties, string, int, bool, unit, pair, triple, list, option, variant |
69240 | 1535 |
) |
1536 |
where |
|
1537 |
||
74168
f0b2136e2204
tuned signature: prefer existing Haskell operations;
wenzelm
parents:
74167
diff
changeset
|
1538 |
import Data.Maybe (fromJust) |
f0b2136e2204
tuned signature: prefer existing Haskell operations;
wenzelm
parents:
74167
diff
changeset
|
1539 |
|
69240 | 1540 |
import Isabelle.Library |
74095 | 1541 |
import Isabelle.Bytes (Bytes) |
69240 | 1542 |
import qualified Isabelle.Value as Value |
1543 |
import qualified Isabelle.Properties as Properties |
|
1544 |
import qualified Isabelle.XML as XML |
|
1545 |
||
1546 |
||
74095 | 1547 |
type A a = a -> Bytes |
69240 | 1548 |
type T a = a -> XML.Body |
74095 | 1549 |
type V a = a -> Maybe ([Bytes], XML.Body) |
1550 |
type P a = a -> [Bytes] |
|
69240 | 1551 |
|
1552 |
||
1553 |
-- atomic values |
|
1554 |
||
1555 |
int_atom :: A Int |
|
1556 |
int_atom = Value.print_int |
|
1557 |
||
1558 |
bool_atom :: A Bool |
|
1559 |
bool_atom False = "0" |
|
1560 |
bool_atom True = "1" |
|
1561 |
||
1562 |
unit_atom :: A () |
|
1563 |
unit_atom () = "" |
|
1564 |
||
1565 |
||
1566 |
-- structural nodes |
|
1567 |
||
69290 | 1568 |
node ts = XML.Elem ((":", []), ts) |
69240 | 1569 |
|
1570 |
vector = map_index (\(i, x) -> (int_atom i, x)) |
|
1571 |
||
69290 | 1572 |
tagged (tag, (xs, ts)) = XML.Elem ((int_atom tag, vector xs), ts) |
69240 | 1573 |
|
1574 |
||
1575 |
-- representation of standard types |
|
1576 |
||
1577 |
tree :: T XML.Tree |
|
1578 |
tree t = [t] |
|
1579 |
||
1580 |
properties :: T Properties.T |
|
69290 | 1581 |
properties props = [XML.Elem ((":", props), [])] |
69240 | 1582 |
|
74095 | 1583 |
string :: T Bytes |
69240 | 1584 |
string "" = [] |
1585 |
string s = [XML.Text s] |
|
1586 |
||
1587 |
int :: T Int |
|
1588 |
int = string . int_atom |
|
1589 |
||
1590 |
bool :: T Bool |
|
1591 |
bool = string . bool_atom |
|
1592 |
||
1593 |
unit :: T () |
|
1594 |
unit = string . unit_atom |
|
1595 |
||
1596 |
pair :: T a -> T b -> T (a, b) |
|
1597 |
pair f g (x, y) = [node (f x), node (g y)] |
|
1598 |
||
1599 |
triple :: T a -> T b -> T c -> T (a, b, c) |
|
1600 |
triple f g h (x, y, z) = [node (f x), node (g y), node (h z)] |
|
1601 |
||
1602 |
list :: T a -> T [a] |
|
1603 |
list f xs = map (node . f) xs |
|
1604 |
||
71490 | 1605 |
option :: T a -> T (Maybe a) |
1606 |
option _ Nothing = [] |
|
1607 |
option f (Just x) = [node (f x)] |
|
1608 |
||
69240 | 1609 |
variant :: [V a] -> T a |
74168
f0b2136e2204
tuned signature: prefer existing Haskell operations;
wenzelm
parents:
74167
diff
changeset
|
1610 |
variant fs x = [tagged (fromJust (get_index (\f -> f x) fs))] |
69240 | 1611 |
\<close> |
1612 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1613 |
generate_file "Isabelle/XML/Decode.hs" = \<open> |
69445 | 1614 |
{- Title: Isabelle/XML/Decode.hs |
69240 | 1615 |
Author: Makarius |
1616 |
LICENSE: BSD 3-clause (Isabelle) |
|
1617 |
||
1618 |
XML as data representation language. |
|
69280 | 1619 |
|
74178 | 1620 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/xml.ML\<close>. |
69240 | 1621 |
-} |
1622 |
||
74095 | 1623 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 1624 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
1625 |
||
69240 | 1626 |
module Isabelle.XML.Decode ( |
70845 | 1627 |
A, T, V, P, |
69240 | 1628 |
|
1629 |
int_atom, bool_atom, unit_atom, |
|
1630 |
||
71490 | 1631 |
tree, properties, string, int, bool, unit, pair, triple, list, option, variant |
69240 | 1632 |
) |
1633 |
where |
|
1634 |
||
1635 |
import Isabelle.Library |
|
74095 | 1636 |
import Isabelle.Bytes (Bytes) |
69240 | 1637 |
import qualified Isabelle.Value as Value |
1638 |
import qualified Isabelle.Properties as Properties |
|
1639 |
import qualified Isabelle.XML as XML |
|
1640 |
||
1641 |
||
74095 | 1642 |
type A a = Bytes -> a |
69240 | 1643 |
type T a = XML.Body -> a |
74095 | 1644 |
type V a = ([Bytes], XML.Body) -> a |
1645 |
type P a = [Bytes] -> a |
|
69240 | 1646 |
|
1647 |
err_atom = error "Malformed XML atom" |
|
1648 |
err_body = error "Malformed XML body" |
|
1649 |
||
1650 |
||
1651 |
{- atomic values -} |
|
1652 |
||
1653 |
int_atom :: A Int |
|
1654 |
int_atom s = |
|
1655 |
case Value.parse_int s of |
|
1656 |
Just i -> i |
|
1657 |
Nothing -> err_atom |
|
1658 |
||
1659 |
bool_atom :: A Bool |
|
1660 |
bool_atom "0" = False |
|
1661 |
bool_atom "1" = True |
|
1662 |
bool_atom _ = err_atom |
|
1663 |
||
1664 |
unit_atom :: A () |
|
1665 |
unit_atom "" = () |
|
1666 |
unit_atom _ = err_atom |
|
1667 |
||
1668 |
||
1669 |
{- structural nodes -} |
|
1670 |
||
69290 | 1671 |
node (XML.Elem ((":", []), ts)) = ts |
69240 | 1672 |
node _ = err_body |
1673 |
||
1674 |
vector atts = |
|
1675 |
map_index (\(i, (a, x)) -> if int_atom a == i then x else err_atom) atts |
|
1676 |
||
69290 | 1677 |
tagged (XML.Elem ((name, atts), ts)) = (int_atom name, (vector atts, ts)) |
69240 | 1678 |
tagged _ = err_body |
1679 |
||
1680 |
||
1681 |
{- representation of standard types -} |
|
1682 |
||
1683 |
tree :: T XML.Tree |
|
1684 |
tree [t] = t |
|
1685 |
tree _ = err_body |
|
1686 |
||
1687 |
properties :: T Properties.T |
|
69290 | 1688 |
properties [XML.Elem ((":", props), [])] = props |
69240 | 1689 |
properties _ = err_body |
1690 |
||
74095 | 1691 |
string :: T Bytes |
69240 | 1692 |
string [] = "" |
1693 |
string [XML.Text s] = s |
|
1694 |
string _ = err_body |
|
1695 |
||
1696 |
int :: T Int |
|
1697 |
int = int_atom . string |
|
1698 |
||
1699 |
bool :: T Bool |
|
1700 |
bool = bool_atom . string |
|
1701 |
||
1702 |
unit :: T () |
|
1703 |
unit = unit_atom . string |
|
1704 |
||
1705 |
pair :: T a -> T b -> T (a, b) |
|
1706 |
pair f g [t1, t2] = (f (node t1), g (node t2)) |
|
1707 |
pair _ _ _ = err_body |
|
1708 |
||
1709 |
triple :: T a -> T b -> T c -> T (a, b, c) |
|
1710 |
triple f g h [t1, t2, t3] = (f (node t1), g (node t2), h (node t3)) |
|
1711 |
triple _ _ _ _ = err_body |
|
1712 |
||
1713 |
list :: T a -> T [a] |
|
1714 |
list f ts = map (f . node) ts |
|
1715 |
||
1716 |
option :: T a -> T (Maybe a) |
|
1717 |
option _ [] = Nothing |
|
1718 |
option f [t] = Just (f (node t)) |
|
1719 |
option _ _ = err_body |
|
1720 |
||
1721 |
variant :: [V a] -> T a |
|
1722 |
variant fs [t] = (fs !! tag) (xs, ts) |
|
1723 |
where (tag, (xs, ts)) = tagged t |
|
1724 |
variant _ _ = err_body |
|
1725 |
\<close> |
|
1726 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1727 |
generate_file "Isabelle/YXML.hs" = \<open> |
69445 | 1728 |
{- Title: Isabelle/YXML.hs |
69288 | 1729 |
Author: Makarius |
1730 |
LICENSE: BSD 3-clause (Isabelle) |
|
1731 |
||
1732 |
Efficient text representation of XML trees. Suitable for direct |
|
1733 |
inlining into plain text. |
|
1734 |
||
74178 | 1735 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/yxml.ML\<close>. |
69288 | 1736 |
-} |
1737 |
||
74095 | 1738 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 1739 |
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-incomplete-patterns #-} |
1740 |
||
69288 | 1741 |
module Isabelle.YXML (charX, charY, strX, strY, detect, output_markup, |
1742 |
buffer_body, buffer, string_of_body, string_of, parse_body, parse) |
|
1743 |
where |
|
1744 |
||
1745 |
import qualified Data.List as List |
|
74095 | 1746 |
import Data.Word (Word8) |
69288 | 1747 |
|
1748 |
import Isabelle.Library |
|
74095 | 1749 |
import qualified Isabelle.Bytes as Bytes |
1750 |
import Isabelle.Bytes (Bytes) |
|
69288 | 1751 |
import qualified Isabelle.Markup as Markup |
1752 |
import qualified Isabelle.XML as XML |
|
1753 |
import qualified Isabelle.Buffer as Buffer |
|
1754 |
||
1755 |
||
1756 |
{- markers -} |
|
1757 |
||
74095 | 1758 |
charX, charY :: Word8 |
1759 |
charX = 5 |
|
1760 |
charY = 6 |
|
1761 |
||
1762 |
strX, strY, strXY, strXYX :: Bytes |
|
1763 |
strX = Bytes.singleton charX |
|
1764 |
strY = Bytes.singleton charY |
|
74081 | 1765 |
strXY = strX <> strY |
1766 |
strXYX = strXY <> strX |
|
69288 | 1767 |
|
74095 | 1768 |
detect :: Bytes -> Bool |
1769 |
detect = Bytes.any (\c -> c == charX || c == charY) |
|
69288 | 1770 |
|
1771 |
||
1772 |
{- output -} |
|
1773 |
||
1774 |
output_markup :: Markup.T -> Markup.Output |
|
1775 |
output_markup markup@(name, atts) = |
|
1776 |
if Markup.is_empty markup then Markup.no_output |
|
74095 | 1777 |
else (strXY <> name <> Bytes.concat (map (\(a, x) -> strY <> a <> "=" <> x) atts) <> strX, strXYX) |
69288 | 1778 |
|
1779 |
buffer_attrib (a, x) = |
|
1780 |
Buffer.add strY #> Buffer.add a #> Buffer.add "=" #> Buffer.add x |
|
1781 |
||
1782 |
buffer_body :: XML.Body -> Buffer.T -> Buffer.T |
|
1783 |
buffer_body = fold buffer |
|
1784 |
||
1785 |
buffer :: XML.Tree -> Buffer.T -> Buffer.T |
|
69290 | 1786 |
buffer (XML.Elem ((name, atts), ts)) = |
69288 | 1787 |
Buffer.add strXY #> Buffer.add name #> fold buffer_attrib atts #> Buffer.add strX #> |
1788 |
buffer_body ts #> |
|
1789 |
Buffer.add strXYX |
|
1790 |
buffer (XML.Text s) = Buffer.add s |
|
1791 |
||
74095 | 1792 |
string_of_body :: XML.Body -> Bytes |
69288 | 1793 |
string_of_body body = Buffer.empty |> buffer_body body |> Buffer.content |
1794 |
||
74095 | 1795 |
string_of :: XML.Tree -> Bytes |
69288 | 1796 |
string_of = string_of_body . single |
1797 |
||
1798 |
||
1799 |
{- parse -} |
|
1800 |
||
1801 |
-- split: fields or non-empty tokens |
|
1802 |
||
74095 | 1803 |
split :: Bool -> Word8 -> [Word8] -> [[Word8]] |
69288 | 1804 |
split _ _ [] = [] |
1805 |
split fields sep str = splitting str |
|
1806 |
where |
|
1807 |
splitting rest = |
|
1808 |
case span (/= sep) rest of |
|
1809 |
(_, []) -> cons rest [] |
|
1810 |
(prfx, _ : rest') -> cons prfx (splitting rest') |
|
1811 |
cons item = if fields || not (null item) then (:) item else id |
|
1812 |
||
1813 |
||
1814 |
-- structural errors |
|
1815 |
||
74095 | 1816 |
err :: Bytes -> a |
1817 |
err msg = error (make_string ("Malformed YXML: " <> msg)) |
|
1818 |
||
69288 | 1819 |
err_attribute = err "bad attribute" |
1820 |
err_element = err "bad element" |
|
74095 | 1821 |
|
1822 |
err_unbalanced :: Bytes -> a |
|
1823 |
err_unbalanced name = |
|
1824 |
if Bytes.null name then err "unbalanced element" |
|
1825 |
else err ("unbalanced element " <> quote name) |
|
69288 | 1826 |
|
1827 |
||
1828 |
-- stack operations |
|
1829 |
||
1830 |
add x ((elem, body) : pending) = (elem, x : body) : pending |
|
1831 |
||
74095 | 1832 |
push name atts pending = |
1833 |
if Bytes.null name then err_element |
|
1834 |
else ((name, atts), []) : pending |
|
1835 |
||
1836 |
pop (((name, atts), body) : pending) = |
|
1837 |
if Bytes.null name then err_unbalanced name |
|
1838 |
else add (XML.Elem ((name, atts), reverse body)) pending |
|
69288 | 1839 |
|
1840 |
||
1841 |
-- parsing |
|
1842 |
||
1843 |
parse_attrib s = |
|
74095 | 1844 |
case List.elemIndex (Bytes.byte '=') s of |
1845 |
Just i | i > 0 -> (Bytes.pack $ take i s, Bytes.pack $ drop (i + 1) s) |
|
69288 | 1846 |
_ -> err_attribute |
1847 |
||
74095 | 1848 |
parse_chunk [[], []] = pop |
1849 |
parse_chunk ([] : name : atts) = push (Bytes.pack name) (map parse_attrib atts) |
|
1850 |
parse_chunk txts = fold (add . XML.Text . Bytes.pack) txts |
|
1851 |
||
1852 |
parse_body :: Bytes -> XML.Body |
|
69288 | 1853 |
parse_body source = |
74095 | 1854 |
case fold parse_chunk chunks [((Bytes.empty, []), [])] of |
1855 |
[((name, _), result)] | Bytes.null name -> reverse result |
|
69288 | 1856 |
((name, _), _) : _ -> err_unbalanced name |
74095 | 1857 |
where chunks = source |> Bytes.unpack |> split False charX |> map (split True charY) |
1858 |
||
1859 |
parse :: Bytes -> XML.Tree |
|
69288 | 1860 |
parse source = |
1861 |
case parse_body source of |
|
1862 |
[result] -> result |
|
1863 |
[] -> XML.Text "" |
|
1864 |
_ -> err "multiple results" |
|
1865 |
\<close> |
|
1866 |
||
74091 | 1867 |
generate_file "Isabelle/Completion.hs" = \<open> |
1868 |
{- Title: Isabelle/Completion.hs |
|
1869 |
Author: Makarius |
|
1870 |
LICENSE: BSD 3-clause (Isabelle) |
|
1871 |
||
1872 |
Completion of names. |
|
1873 |
||
74178 | 1874 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/completion.ML\<close>. |
74091 | 1875 |
-} |
1876 |
||
74095 | 1877 |
{-# LANGUAGE OverloadedStrings #-} |
1878 |
||
74091 | 1879 |
module Isabelle.Completion ( |
1880 |
Name, T, names, none, make, markup_element, markup_report, make_report |
|
1881 |
) where |
|
1882 |
||
74095 | 1883 |
import qualified Isabelle.Bytes as Bytes |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1884 |
import qualified Isabelle.Name as Name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1885 |
import Isabelle.Name (Name) |
74091 | 1886 |
import qualified Isabelle.Properties as Properties |
1887 |
import qualified Isabelle.Markup as Markup |
|
74129 | 1888 |
import Isabelle.XML.Classes |
74091 | 1889 |
import qualified Isabelle.XML as XML |
1890 |
import qualified Isabelle.YXML as YXML |
|
1891 |
||
1892 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1893 |
type Names = [(Name, (Name, Name))] -- external name, kind, internal name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1894 |
data T = Completion Properties.T Int Names -- position, total length, names |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1895 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1896 |
names :: Int -> Properties.T -> Names -> T |
74091 | 1897 |
names limit props names = Completion props (length names) (take limit names) |
1898 |
||
1899 |
none :: T |
|
1900 |
none = names 0 [] [] |
|
1901 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1902 |
make :: Int -> (Name, Properties.T) -> ((Name -> Bool) -> Names) -> T |
74091 | 1903 |
make limit (name, props) make_names = |
74095 | 1904 |
if name /= "" && name /= "_" then |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1905 |
names limit props (make_names (Bytes.isPrefixOf (Name.clean name))) |
74091 | 1906 |
else none |
1907 |
||
1908 |
markup_element :: T -> (Markup.T, XML.Body) |
|
1909 |
markup_element (Completion props total names) = |
|
1910 |
if not (null names) then |
|
74129 | 1911 |
(Markup.properties props Markup.completion, encode (total, names)) |
74091 | 1912 |
else (Markup.empty, []) |
1913 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1914 |
markup_report :: [T] -> Name |
74095 | 1915 |
markup_report [] = Bytes.empty |
74091 | 1916 |
markup_report elems = |
1917 |
YXML.string_of $ XML.Elem (Markup.report, map (XML.Elem . markup_element) elems) |
|
1918 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
1919 |
make_report :: Int -> (Name, Properties.T) -> ((Name -> Bool) -> Names) -> Name |
74091 | 1920 |
make_report limit name_props make_names = |
1921 |
markup_report [make limit name_props make_names] |
|
1922 |
\<close> |
|
1923 |
||
1924 |
generate_file "Isabelle/File.hs" = \<open> |
|
1925 |
{- Title: Isabelle/File.hs |
|
1926 |
Author: Makarius |
|
1927 |
LICENSE: BSD 3-clause (Isabelle) |
|
1928 |
||
1929 |
File-system operations. |
|
1930 |
||
74178 | 1931 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/file.ML\<close>. |
74091 | 1932 |
-} |
1933 |
||
74098 | 1934 |
module Isabelle.File (read, write, append) where |
74091 | 1935 |
|
1936 |
import Prelude hiding (read) |
|
1937 |
import qualified System.IO as IO |
|
74098 | 1938 |
import qualified Data.ByteString as ByteString |
1939 |
import qualified Isabelle.Bytes as Bytes |
|
1940 |
import Isabelle.Bytes (Bytes) |
|
1941 |
||
1942 |
read :: IO.FilePath -> IO Bytes |
|
1943 |
read path = Bytes.make <$> IO.withFile path IO.ReadMode ByteString.hGetContents |
|
1944 |
||
1945 |
write :: IO.FilePath -> Bytes -> IO () |
|
1946 |
write path bs = IO.withFile path IO.WriteMode (\h -> ByteString.hPut h (Bytes.unmake bs)) |
|
1947 |
||
1948 |
append :: IO.FilePath -> Bytes -> IO () |
|
1949 |
append path bs = IO.withFile path IO.AppendMode (\h -> ByteString.hPut h (Bytes.unmake bs)) |
|
74091 | 1950 |
\<close> |
1951 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
1952 |
generate_file "Isabelle/Pretty.hs" = \<open> |
69445 | 1953 |
{- Title: Isabelle/Pretty.hs |
69248 | 1954 |
Author: Makarius |
1955 |
LICENSE: BSD 3-clause (Isabelle) |
|
1956 |
||
1957 |
Generic pretty printing module. |
|
69280 | 1958 |
|
74178 | 1959 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/pretty.ML\<close>. |
69248 | 1960 |
-} |
1961 |
||
74095 | 1962 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 1963 |
{-# OPTIONS_GHC -fno-warn-missing-signatures #-} |
1964 |
||
69248 | 1965 |
module Isabelle.Pretty ( |
1966 |
T, symbolic, formatted, unformatted, |
|
1967 |
||
1968 |
str, brk_indent, brk, fbrk, breaks, fbreaks, blk, block, strs, markup, mark, mark_str, marks_str, |
|
1969 |
item, text_fold, keyword1, keyword2, text, paragraph, para, quote, cartouche, separate, |
|
1970 |
commas, enclose, enum, list, str_list, big_list) |
|
1971 |
where |
|
1972 |
||
74095 | 1973 |
import qualified Data.List as List |
1974 |
||
1975 |
import qualified Isabelle.Bytes as Bytes |
|
1976 |
import Isabelle.Bytes (Bytes) |
|
74185 | 1977 |
import Isabelle.Library hiding (enclose, quote, separate, commas) |
69248 | 1978 |
import qualified Isabelle.Buffer as Buffer |
1979 |
import qualified Isabelle.Markup as Markup |
|
1980 |
import qualified Isabelle.XML as XML |
|
1981 |
import qualified Isabelle.YXML as YXML |
|
1982 |
||
1983 |
||
1984 |
data T = |
|
1985 |
Block Markup.T Bool Int [T] |
|
1986 |
| Break Int Int |
|
74095 | 1987 |
| Str Bytes |
69248 | 1988 |
|
1989 |
||
1990 |
{- output -} |
|
1991 |
||
74095 | 1992 |
symbolic_text s = if Bytes.null s then [] else [XML.Text s] |
69248 | 1993 |
|
1994 |
symbolic_markup markup body = |
|
1995 |
if Markup.is_empty markup then body |
|
69290 | 1996 |
else [XML.Elem (markup, body)] |
69248 | 1997 |
|
1998 |
symbolic :: T -> XML.Body |
|
1999 |
symbolic (Block markup consistent indent prts) = |
|
2000 |
concatMap symbolic prts |
|
2001 |
|> symbolic_markup block_markup |
|
2002 |
|> symbolic_markup markup |
|
2003 |
where block_markup = if null prts then Markup.empty else Markup.block consistent indent |
|
74095 | 2004 |
symbolic (Break wd ind) = [XML.Elem (Markup.break wd ind, symbolic_text (Bytes.spaces wd))] |
69248 | 2005 |
symbolic (Str s) = symbolic_text s |
2006 |
||
74095 | 2007 |
formatted :: T -> Bytes |
69248 | 2008 |
formatted = YXML.string_of_body . symbolic |
2009 |
||
74095 | 2010 |
unformatted :: T -> Bytes |
69248 | 2011 |
unformatted prt = Buffer.empty |> out prt |> Buffer.content |
2012 |
where |
|
2013 |
out (Block markup _ _ prts) = |
|
2014 |
let (bg, en) = YXML.output_markup markup |
|
2015 |
in Buffer.add bg #> fold out prts #> Buffer.add en |
|
74095 | 2016 |
out (Break _ wd) = Buffer.add (Bytes.spaces wd) |
69248 | 2017 |
out (Str s) = Buffer.add s |
2018 |
||
2019 |
||
2020 |
{- derived operations to create formatting expressions -} |
|
2021 |
||
2022 |
force_nat n | n < 0 = 0 |
|
2023 |
force_nat n = n |
|
2024 |
||
74095 | 2025 |
str :: BYTES a => a -> T |
2026 |
str = Str . make_bytes |
|
69248 | 2027 |
|
2028 |
brk_indent :: Int -> Int -> T |
|
2029 |
brk_indent wd ind = Break (force_nat wd) ind |
|
2030 |
||
2031 |
brk :: Int -> T |
|
2032 |
brk wd = brk_indent wd 0 |
|
2033 |
||
2034 |
fbrk :: T |
|
74095 | 2035 |
fbrk = Str "\n" |
69248 | 2036 |
|
2037 |
breaks, fbreaks :: [T] -> [T] |
|
2038 |
breaks = List.intersperse (brk 1) |
|
2039 |
fbreaks = List.intersperse fbrk |
|
2040 |
||
2041 |
blk :: (Int, [T]) -> T |
|
2042 |
blk (indent, es) = Block Markup.empty False (force_nat indent) es |
|
2043 |
||
2044 |
block :: [T] -> T |
|
2045 |
block prts = blk (2, prts) |
|
2046 |
||
74095 | 2047 |
strs :: BYTES a => [a] -> T |
69248 | 2048 |
strs = block . breaks . map str |
2049 |
||
2050 |
markup :: Markup.T -> [T] -> T |
|
2051 |
markup m = Block m False 0 |
|
2052 |
||
2053 |
mark :: Markup.T -> T -> T |
|
2054 |
mark m prt = if m == Markup.empty then prt else markup m [prt] |
|
2055 |
||
74095 | 2056 |
mark_str :: BYTES a => (Markup.T, a) -> T |
69248 | 2057 |
mark_str (m, s) = mark m (str s) |
2058 |
||
74095 | 2059 |
marks_str :: BYTES a => ([Markup.T], a) -> T |
69248 | 2060 |
marks_str (ms, s) = fold_rev mark ms (str s) |
2061 |
||
2062 |
item :: [T] -> T |
|
2063 |
item = markup Markup.item |
|
2064 |
||
2065 |
text_fold :: [T] -> T |
|
2066 |
text_fold = markup Markup.text_fold |
|
2067 |
||
74095 | 2068 |
keyword1, keyword2 :: BYTES a => a -> T |
69248 | 2069 |
keyword1 name = mark_str (Markup.keyword1, name) |
2070 |
keyword2 name = mark_str (Markup.keyword2, name) |
|
2071 |
||
74095 | 2072 |
text :: BYTES a => a -> [T] |
74132 | 2073 |
text = breaks . map str . filter (not . Bytes.null) . space_explode ' ' . make_bytes |
69248 | 2074 |
|
2075 |
paragraph :: [T] -> T |
|
2076 |
paragraph = markup Markup.paragraph |
|
2077 |
||
74095 | 2078 |
para :: BYTES a => a -> T |
69248 | 2079 |
para = paragraph . text |
2080 |
||
2081 |
quote :: T -> T |
|
74095 | 2082 |
quote prt = blk (1, [Str "\"", prt, Str "\""]) |
69248 | 2083 |
|
2084 |
cartouche :: T -> T |
|
74095 | 2085 |
cartouche prt = blk (1, [Str "\92<open>", prt, Str "\92<close>"]) |
2086 |
||
2087 |
separate :: BYTES a => a -> [T] -> [T] |
|
69248 | 2088 |
separate sep = List.intercalate [str sep, brk 1] . map single |
2089 |
||
2090 |
commas :: [T] -> [T] |
|
74095 | 2091 |
commas = separate ("," :: Bytes) |
2092 |
||
2093 |
enclose :: BYTES a => a -> a -> [T] -> T |
|
74081 | 2094 |
enclose lpar rpar prts = block (str lpar : prts <> [str rpar]) |
69248 | 2095 |
|
74095 | 2096 |
enum :: BYTES a => a -> a -> a -> [T] -> T |
69248 | 2097 |
enum sep lpar rpar = enclose lpar rpar . separate sep |
2098 |
||
74095 | 2099 |
list :: BYTES a => a -> a -> [T] -> T |
69248 | 2100 |
list = enum "," |
2101 |
||
74095 | 2102 |
str_list :: BYTES a => a -> a -> [a] -> T |
69248 | 2103 |
str_list lpar rpar = list lpar rpar . map str |
2104 |
||
74095 | 2105 |
big_list :: BYTES a => a -> [T] -> T |
69248 | 2106 |
big_list name prts = block (fbreaks (str name : prts)) |
2107 |
\<close> |
|
2108 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2109 |
generate_file "Isabelle/Name.hs" = \<open> |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2110 |
{- Title: Isabelle/Name.hs |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2111 |
Author: Makarius |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2112 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2113 |
Names of basic logical entities (variables etc.). |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2114 |
|
74178 | 2115 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/name.ML\<close>. |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2116 |
-} |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2117 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2118 |
{-# LANGUAGE OverloadedStrings #-} |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2119 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2120 |
module Isabelle.Name ( |
74194 | 2121 |
Name, |
2122 |
uu, uu_, aT, |
|
74196 | 2123 |
clean_index, clean, internal, skolem, is_internal, is_skolem, |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2124 |
Context, declare, is_declared, context, make_context, variant |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2125 |
) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2126 |
where |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2127 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2128 |
import Data.Word (Word8) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2129 |
import qualified Data.Set as Set |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2130 |
import Data.Set (Set) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2131 |
import qualified Isabelle.Bytes as Bytes |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2132 |
import Isabelle.Bytes (Bytes) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2133 |
import qualified Isabelle.Symbol as Symbol |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2134 |
import Isabelle.Library |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2135 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2136 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2137 |
type Name = Bytes |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2138 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2139 |
|
74194 | 2140 |
{- common defaults -} |
2141 |
||
2142 |
uu, uu_, aT :: Name |
|
2143 |
uu = "uu" |
|
2144 |
uu_ = "uu_" |
|
2145 |
aT = "'a" |
|
2146 |
||
2147 |
||
74196 | 2148 |
{- internal names -- NB: internal subsumes skolem -} |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2149 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2150 |
underscore :: Word8 |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2151 |
underscore = Bytes.byte '_' |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2152 |
|
74196 | 2153 |
internal, skolem :: Name -> Name |
2154 |
internal x = x <> "_" |
|
2155 |
skolem x = x <> "__" |
|
2156 |
||
2157 |
is_internal, is_skolem :: Name -> Bool |
|
2158 |
is_internal = Bytes.isSuffixOf "_" |
|
2159 |
is_skolem = Bytes.isSuffixOf "__" |
|
2160 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2161 |
clean_index :: Name -> (Name, Int) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2162 |
clean_index x = |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2163 |
if Bytes.null x || Bytes.last x /= underscore then (x, 0) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2164 |
else |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2165 |
let |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2166 |
rev = reverse (Bytes.unpack x) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2167 |
n = length (takeWhile (== underscore) rev) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2168 |
y = Bytes.pack (reverse (drop n rev)) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2169 |
in (y, n) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2170 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2171 |
clean :: Name -> Name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2172 |
clean = fst . clean_index |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2173 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2174 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2175 |
{- context for used names -} |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2176 |
|
74195 | 2177 |
newtype Context = Context (Set Name) |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2178 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2179 |
declare :: Name -> Context -> Context |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2180 |
declare x (Context names) = Context (Set.insert x names) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2181 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2182 |
is_declared :: Context -> Name -> Bool |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2183 |
is_declared (Context names) x = Set.member x names |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2184 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2185 |
context :: Context |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2186 |
context = Context (Set.fromList ["", "'"]) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2187 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2188 |
make_context :: [Name] -> Context |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2189 |
make_context used = fold declare used context |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2190 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2191 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2192 |
{- generating fresh names -} |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2193 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2194 |
bump_init :: Name -> Name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2195 |
bump_init str = str <> "a" |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2196 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2197 |
bump_string :: Name -> Name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2198 |
bump_string str = |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2199 |
let |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2200 |
a = Bytes.byte 'a' |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2201 |
z = Bytes.byte 'z' |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2202 |
bump (b : bs) | b == z = a : bump bs |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2203 |
bump (b : bs) | a <= b && b < z = b + 1 : bs |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2204 |
bump bs = a : bs |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2205 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2206 |
rev = reverse (Bytes.unpack str) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2207 |
part2 = reverse (takeWhile (Symbol.is_ascii_quasi . Bytes.char) rev) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2208 |
part1 = reverse (bump (drop (length part2) rev)) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2209 |
in Bytes.pack (part1 <> part2) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2210 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2211 |
variant :: Name -> Context -> (Name, Context) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2212 |
variant name names = |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2213 |
let |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2214 |
vary bump x = if is_declared names x then bump x |> vary bump_string else x |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2215 |
(x, n) = clean_index name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2216 |
x' = x |> vary bump_init |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2217 |
names' = declare x' names; |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2218 |
in (x' <> Bytes.pack (replicate n underscore), names') |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2219 |
\<close> |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2220 |
|
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
2221 |
generate_file "Isabelle/Term.hs" = \<open> |
69445 | 2222 |
{- Title: Isabelle/Term.hs |
69240 | 2223 |
Author: Makarius |
2224 |
LICENSE: BSD 3-clause (Isabelle) |
|
2225 |
||
2226 |
Lambda terms, types, sorts. |
|
69280 | 2227 |
|
74178 | 2228 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/term.scala\<close>. |
69240 | 2229 |
-} |
2230 |
||
74095 | 2231 |
{-# LANGUAGE OverloadedStrings #-} |
2232 |
||
69240 | 2233 |
module Isabelle.Term ( |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2234 |
Indexname, Sort, Typ(..), Term(..), |
74124 | 2235 |
Free, lambda, declare_frees, incr_boundvars, subst_bound, dest_abs, strip_abs, |
74197 | 2236 |
type_op0, type_op1, op0, op1, op2, typed_op0, typed_op1, typed_op2, binder, |
74105 | 2237 |
dummyS, dummyT, is_dummyT, propT, is_propT, (-->), dest_funT, (--->), |
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2238 |
aconv, list_comb, strip_comb, head_of |
74105 | 2239 |
) |
69240 | 2240 |
where |
2241 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2242 |
import Isabelle.Library |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2243 |
import qualified Isabelle.Name as Name |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2244 |
import Isabelle.Name (Name) |
74095 | 2245 |
|
74105 | 2246 |
infixr 5 --> |
2247 |
infixr ---> |
|
2248 |
||
2249 |
||
2250 |
{- types and terms -} |
|
2251 |
||
2252 |
type Indexname = (Name, Int) |
|
2253 |
||
2254 |
type Sort = [Name] |
|
2255 |
||
2256 |
data Typ = |
|
2257 |
Type (Name, [Typ]) |
|
2258 |
| TFree (Name, Sort) |
|
2259 |
| TVar (Indexname, Sort) |
|
2260 |
deriving (Show, Eq, Ord) |
|
2261 |
||
2262 |
data Term = |
|
2263 |
Const (Name, [Typ]) |
|
2264 |
| Free (Name, Typ) |
|
2265 |
| Var (Indexname, Typ) |
|
2266 |
| Bound Int |
|
2267 |
| Abs (Name, Typ, Term) |
|
2268 |
| App (Term, Term) |
|
2269 |
deriving (Show, Eq, Ord) |
|
2270 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2271 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2272 |
{- free and bound variables -} |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2273 |
|
74105 | 2274 |
type Free = (Name, Typ) |
2275 |
||
74106
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2276 |
lambda :: Free -> Term -> Term |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2277 |
lambda (name, typ) body = Abs (name, typ, abstract 0 body) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2278 |
where |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2279 |
abstract lev (Free (x, ty)) | name == x && typ == ty = Bound lev |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2280 |
abstract lev (Abs (a, ty, t)) = Abs (a, ty, abstract (lev + 1) t) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2281 |
abstract lev (App (t, u)) = App (abstract lev t, abstract lev u) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2282 |
abstract _ t = t |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2283 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2284 |
declare_frees :: Term -> Name.Context -> Name.Context |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2285 |
declare_frees (Free (x, _)) = Name.declare x |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2286 |
declare_frees (Abs (_, _, b)) = declare_frees b |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2287 |
declare_frees (App (t, u)) = declare_frees t #> declare_frees u |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2288 |
declare_frees _ = id |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2289 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2290 |
incr_boundvars :: Int -> Term -> Term |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2291 |
incr_boundvars inc = if inc == 0 then id else incr 0 |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2292 |
where |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2293 |
incr lev (Bound i) = if i >= lev then Bound (i + inc) else Bound i |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2294 |
incr lev (Abs (a, ty, b)) = Abs (a, ty, incr (lev + 1) b) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2295 |
incr lev (App (t, u)) = App (incr lev t, incr lev u) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2296 |
incr _ t = t |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2297 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2298 |
subst_bound :: Term -> Term -> Term |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2299 |
subst_bound arg = subst 0 |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2300 |
where |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2301 |
subst lev (Bound i) = |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2302 |
if i < lev then Bound i |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2303 |
else if i == lev then incr_boundvars lev arg |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2304 |
else Bound (i - 1) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2305 |
subst lev (Abs (a, ty, b)) = Abs (a, ty, subst (lev + 1) b) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2306 |
subst lev (App (t, u)) = App (subst lev t, subst lev u) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2307 |
subst _ t = t |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2308 |
|
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2309 |
dest_abs :: Name.Context -> Term -> Maybe (Free, Term) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2310 |
dest_abs names (Abs (x, ty, b)) = |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2311 |
let |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2312 |
(x', _) = Name.variant x (declare_frees b names) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2313 |
v = (x', ty) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2314 |
in Just (v, subst_bound (Free v) b) |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2315 |
dest_abs _ _ = Nothing |
4984fad0e91d
more operations, notably free and bound variables as in Isabelle/Pure;
wenzelm
parents:
74105
diff
changeset
|
2316 |
|
74124 | 2317 |
strip_abs :: Name.Context -> Term -> ([Free], Term) |
2318 |
strip_abs names tm = |
|
2319 |
case dest_abs names tm of |
|
2320 |
Just (v, t) -> |
|
2321 |
let (vs, t') = strip_abs names t' |
|
2322 |
in (v : vs, t') |
|
2323 |
Nothing -> ([], tm) |
|
2324 |
||
74105 | 2325 |
|
2326 |
{- type and term operators -} |
|
2327 |
||
2328 |
type_op0 :: Name -> (Typ, Typ -> Bool) |
|
2329 |
type_op0 name = (mk, is) |
|
2330 |
where |
|
2331 |
mk = Type (name, []) |
|
2332 |
is (Type (name, _)) = True |
|
2333 |
is _ = False |
|
2334 |
||
2335 |
type_op1 :: Name -> (Typ -> Typ, Typ -> Maybe Typ) |
|
2336 |
type_op1 name = (mk, dest) |
|
2337 |
where |
|
2338 |
mk ty = Type (name, [ty]) |
|
2339 |
dest (Type (name, [ty])) = Just ty |
|
2340 |
dest _ = Nothing |
|
2341 |
||
2342 |
type_op2 :: Name -> (Typ -> Typ -> Typ, Typ -> Maybe (Typ, Typ)) |
|
2343 |
type_op2 name = (mk, dest) |
|
2344 |
where |
|
2345 |
mk ty1 ty2 = Type (name, [ty1, ty2]) |
|
2346 |
dest (Type (name, [ty1, ty2])) = Just (ty1, ty2) |
|
2347 |
dest _ = Nothing |
|
2348 |
||
2349 |
op0 :: Name -> (Term, Term -> Bool) |
|
2350 |
op0 name = (mk, is) |
|
2351 |
where |
|
2352 |
mk = Const (name, []) |
|
2353 |
is (Const (c, _)) = c == name |
|
2354 |
is _ = False |
|
2355 |
||
2356 |
op1 :: Name -> (Term -> Term, Term -> Maybe Term) |
|
2357 |
op1 name = (mk, dest) |
|
2358 |
where |
|
2359 |
mk t = App (Const (name, []), t) |
|
2360 |
dest (App (Const (c, _), t)) | c == name = Just t |
|
2361 |
dest _ = Nothing |
|
2362 |
||
2363 |
op2 :: Name -> (Term -> Term -> Term, Term -> Maybe (Term, Term)) |
|
2364 |
op2 name = (mk, dest) |
|
2365 |
where |
|
2366 |
mk t u = App (App (Const (name, []), t), u) |
|
2367 |
dest (App (App (Const (c, _), t), u)) | c == name = Just (t, u) |
|
2368 |
dest _ = Nothing |
|
2369 |
||
74197 | 2370 |
typed_op0 :: Name -> (Typ -> Term, Term -> Maybe Typ) |
2371 |
typed_op0 name = (mk, dest) |
|
2372 |
where |
|
2373 |
mk ty = Const (name, [ty]) |
|
2374 |
dest (Const (c, [ty])) | c == name = Just ty |
|
2375 |
dest _ = Nothing |
|
2376 |
||
74188 | 2377 |
typed_op1 :: Name -> (Typ -> Term -> Term, Term -> Maybe (Typ, Term)) |
2378 |
typed_op1 name = (mk, dest) |
|
2379 |
where |
|
2380 |
mk ty t = App (Const (name, [ty]), t) |
|
2381 |
dest (App (Const (c, [ty]), t)) | c == name = Just (ty, t) |
|
2382 |
dest _ = Nothing |
|
2383 |
||
74105 | 2384 |
typed_op2 :: Name -> (Typ -> Term -> Term -> Term, Term -> Maybe (Typ, Term, Term)) |
2385 |
typed_op2 name = (mk, dest) |
|
2386 |
where |
|
2387 |
mk ty t u = App (App (Const (name, [ty]), t), u) |
|
2388 |
dest (App (App (Const (c, [ty]), t), u)) | c == name = Just (ty, t, u) |
|
2389 |
dest _ = Nothing |
|
2390 |
||
74124 | 2391 |
binder :: Name -> (Free -> Term -> Term, Name.Context -> Term -> Maybe (Free, Term)) |
2392 |
binder name = (mk, dest) |
|
2393 |
where |
|
2394 |
mk (a, ty) b = App (Const (name, [ty]), lambda (a, ty) b) |
|
2395 |
dest names (App (Const (c, _), t)) | c == name = dest_abs names t |
|
2396 |
dest _ _ = Nothing |
|
74105 | 2397 |
|
2398 |
||
2399 |
{- type operations -} |
|
69240 | 2400 |
|
2401 |
dummyS :: Sort |
|
2402 |
dummyS = [""] |
|
2403 |
||
74105 | 2404 |
dummyT :: Typ; is_dummyT :: Typ -> Bool |
2405 |
(dummyT, is_dummyT) = type_op0 \<open>\<^type_name>\<open>dummy\<close>\<close> |
|
2406 |
||
2407 |
propT :: Typ; is_propT :: Typ -> Bool |
|
2408 |
(propT, is_propT) = type_op0 \<open>\<^type_name>\<open>prop\<close>\<close> |
|
2409 |
||
2410 |
(-->) :: Typ -> Typ -> Typ; dest_funT :: Typ -> Maybe (Typ, Typ) |
|
2411 |
((-->), dest_funT) = type_op2 \<open>\<^type_name>\<open>fun\<close>\<close> |
|
2412 |
||
2413 |
(--->) :: [Typ] -> Typ -> Typ |
|
2414 |
[] ---> b = b |
|
2415 |
(a : as) ---> b = a --> (as ---> b) |
|
2416 |
||
2417 |
||
2418 |
{- term operations -} |
|
74100 | 2419 |
|
2420 |
aconv :: Term -> Term -> Bool |
|
2421 |
aconv (App (t1, u1)) (App (t2, u2)) = aconv t1 t2 && aconv u1 u2 |
|
2422 |
aconv (Abs (_, ty1, t1)) (Abs (_, ty2, t2)) = aconv t1 t2 && ty1 == ty2 |
|
2423 |
aconv a1 a2 = a1 == a2 |
|
2424 |
||
2425 |
list_comb :: Term -> [Term] -> Term |
|
2426 |
list_comb f [] = f |
|
2427 |
list_comb f (t : ts) = list_comb (App (f, t)) ts |
|
2428 |
||
2429 |
strip_comb :: Term -> (Term, [Term]) |
|
2430 |
strip_comb tm = strip (tm, []) |
|
2431 |
where |
|
2432 |
strip (App (f, t), ts) = strip (f, t : ts) |
|
2433 |
strip x = x |
|
2434 |
||
2435 |
head_of :: Term -> Term |
|
2436 |
head_of (App (f, _)) = head_of f |
|
2437 |
head_of u = u |
|
69240 | 2438 |
\<close> |
2439 |
||
74105 | 2440 |
generate_file "Isabelle/Pure.hs" = \<open> |
2441 |
{- Title: Isabelle/Term.hs |
|
2442 |
Author: Makarius |
|
2443 |
LICENSE: BSD 3-clause (Isabelle) |
|
2444 |
||
2445 |
Support for Isabelle/Pure logic. |
|
2446 |
||
74178 | 2447 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/logic.ML\<close>. |
74105 | 2448 |
-} |
2449 |
||
2450 |
{-# LANGUAGE OverloadedStrings #-} |
|
2451 |
||
2452 |
module Isabelle.Pure ( |
|
74188 | 2453 |
mk_forall_op, dest_forall_op, mk_forall, dest_forall, |
2454 |
mk_equals, dest_equals, mk_implies, dest_implies |
|
74105 | 2455 |
) |
2456 |
where |
|
2457 |
||
74124 | 2458 |
import qualified Isabelle.Name as Name |
74105 | 2459 |
import Isabelle.Term |
2460 |
||
74188 | 2461 |
mk_forall_op :: Typ -> Term -> Term; dest_forall_op :: Term -> Maybe (Typ, Term) |
2462 |
(mk_forall_op, dest_forall_op) = typed_op1 \<open>\<^const_name>\<open>Pure.all\<close>\<close> |
|
2463 |
||
74124 | 2464 |
mk_forall :: Free -> Term -> Term; dest_forall :: Name.Context -> Term -> Maybe (Free, Term) |
2465 |
(mk_forall, dest_forall) = binder \<open>\<^const_name>\<open>Pure.all\<close>\<close> |
|
74105 | 2466 |
|
2467 |
mk_equals :: Typ -> Term -> Term -> Term; dest_equals :: Term -> Maybe (Typ, Term, Term) |
|
2468 |
(mk_equals, dest_equals) = typed_op2 \<open>\<^const_name>\<open>Pure.eq\<close>\<close> |
|
2469 |
||
2470 |
mk_implies :: Term -> Term -> Term; dest_implies :: Term -> Maybe (Term, Term) |
|
2471 |
(mk_implies, dest_implies) = op2 \<open>\<^const_name>\<open>Pure.imp\<close>\<close> |
|
2472 |
\<close> |
|
2473 |
||
2474 |
generate_file "Isabelle/HOL.hs" = \<open> |
|
2475 |
{- Title: Isabelle/Term.hs |
|
2476 |
Author: Makarius |
|
2477 |
LICENSE: BSD 3-clause (Isabelle) |
|
2478 |
||
2479 |
Support for Isabelle/HOL logic. |
|
2480 |
||
74178 | 2481 |
See \<^file>\<open>$ISABELLE_HOME/src/HOL/Tools/hologic.ML\<close>. |
74105 | 2482 |
-} |
2483 |
||
2484 |
{-# LANGUAGE OverloadedStrings #-} |
|
2485 |
||
2486 |
module Isabelle.HOL ( |
|
2487 |
boolT, is_boolT, mk_trueprop, dest_trueprop, |
|
2488 |
mk_setT, dest_setT, mk_mem, dest_mem, |
|
2489 |
mk_eq, dest_eq, true, is_true, false, is_false, |
|
2490 |
mk_not, dest_not, mk_conj, dest_conj, mk_disj, dest_disj, |
|
2491 |
mk_imp, dest_imp, mk_iff, dest_iff, |
|
74188 | 2492 |
mk_all_op, dest_all_op, mk_ex_op, dest_ex_op, |
74197 | 2493 |
mk_all, dest_all, mk_ex, dest_ex, |
2494 |
mk_undefined, dest_undefined |
|
74105 | 2495 |
) |
2496 |
where |
|
2497 |
||
74124 | 2498 |
import qualified Isabelle.Name as Name |
74105 | 2499 |
import Isabelle.Term |
2500 |
||
2501 |
||
2502 |
boolT :: Typ; is_boolT :: Typ -> Bool |
|
2503 |
(boolT, is_boolT) = type_op0 \<open>\<^type_name>\<open>bool\<close>\<close> |
|
2504 |
||
2505 |
mk_trueprop :: Term -> Term; dest_trueprop :: Term -> Maybe Term |
|
2506 |
(mk_trueprop, dest_trueprop) = op1 \<open>\<^const_name>\<open>Trueprop\<close>\<close> |
|
2507 |
||
2508 |
mk_setT :: Typ -> Typ; dest_setT :: Typ -> Maybe Typ |
|
2509 |
(mk_setT, dest_setT) = type_op1 \<open>\<^type_name>\<open>set\<close>\<close> |
|
2510 |
||
2511 |
mk_mem :: Typ -> Term -> Term -> Term; dest_mem :: Term -> Maybe (Typ, Term, Term) |
|
2512 |
(mk_mem, dest_mem) = typed_op2 \<open>\<^const_name>\<open>Set.member\<close>\<close> |
|
2513 |
||
2514 |
mk_eq :: Typ -> Term -> Term -> Term; dest_eq :: Term -> Maybe (Typ, Term, Term) |
|
2515 |
(mk_eq, dest_eq) = typed_op2 \<open>\<^const_name>\<open>HOL.eq\<close>\<close> |
|
2516 |
||
2517 |
true :: Term; is_true :: Term -> Bool |
|
2518 |
(true, is_true) = op0 \<open>\<^const_name>\<open>True\<close>\<close> |
|
2519 |
||
2520 |
false :: Term; is_false :: Term -> Bool |
|
2521 |
(false, is_false) = op0 \<open>\<^const_name>\<open>False\<close>\<close> |
|
2522 |
||
2523 |
mk_not :: Term -> Term; dest_not :: Term -> Maybe Term |
|
2524 |
(mk_not, dest_not) = op1 \<open>\<^const_name>\<open>Not\<close>\<close> |
|
2525 |
||
2526 |
mk_conj :: Term -> Term -> Term; dest_conj :: Term -> Maybe (Term, Term) |
|
2527 |
(mk_conj, dest_conj) = op2 \<open>\<^const_name>\<open>conj\<close>\<close> |
|
2528 |
||
2529 |
mk_disj :: Term -> Term -> Term; dest_disj :: Term -> Maybe (Term, Term) |
|
2530 |
(mk_disj, dest_disj) = op2 \<open>\<^const_name>\<open>disj\<close>\<close> |
|
2531 |
||
2532 |
mk_imp :: Term -> Term -> Term; dest_imp :: Term -> Maybe (Term, Term) |
|
2533 |
(mk_imp, dest_imp) = op2 \<open>\<^const_name>\<open>implies\<close>\<close> |
|
2534 |
||
2535 |
mk_iff :: Term -> Term -> Term |
|
2536 |
mk_iff = mk_eq boolT |
|
2537 |
||
2538 |
dest_iff :: Term -> Maybe (Term, Term) |
|
2539 |
dest_iff tm = |
|
2540 |
case dest_eq tm of |
|
2541 |
Just (ty, t, u) | ty == boolT -> Just (t, u) |
|
2542 |
_ -> Nothing |
|
2543 |
||
74188 | 2544 |
mk_all_op :: Typ -> Term -> Term; dest_all_op :: Term -> Maybe (Typ, Term) |
2545 |
(mk_all_op, dest_all_op) = typed_op1 \<open>\<^const_name>\<open>All\<close>\<close> |
|
2546 |
||
2547 |
mk_ex_op :: Typ -> Term -> Term; dest_ex_op :: Term -> Maybe (Typ, Term) |
|
2548 |
(mk_ex_op, dest_ex_op) = typed_op1 \<open>\<^const_name>\<open>Ex\<close>\<close> |
|
2549 |
||
74124 | 2550 |
mk_all :: Free -> Term -> Term; dest_all :: Name.Context -> Term -> Maybe (Free, Term) |
2551 |
(mk_all, dest_all) = binder \<open>\<^const_name>\<open>All\<close>\<close> |
|
2552 |
||
2553 |
mk_ex :: Free -> Term -> Term; dest_ex :: Name.Context -> Term -> Maybe (Free, Term) |
|
2554 |
(mk_ex, dest_ex) = binder \<open>\<^const_name>\<open>Ex\<close>\<close> |
|
74197 | 2555 |
|
2556 |
mk_undefined :: Typ -> Term; dest_undefined :: Term -> Maybe Typ |
|
2557 |
(mk_undefined, dest_undefined) = typed_op0 \<open>\<^const_name>\<open>undefined\<close>\<close> |
|
74105 | 2558 |
\<close> |
2559 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
2560 |
generate_file "Isabelle/Term_XML/Encode.hs" = \<open> |
69445 | 2561 |
{- Title: Isabelle/Term_XML/Encode.hs |
69240 | 2562 |
Author: Makarius |
2563 |
LICENSE: BSD 3-clause (Isabelle) |
|
2564 |
||
2565 |
XML data representation of lambda terms. |
|
69280 | 2566 |
|
74178 | 2567 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/term_xml.ML\<close>. |
69240 | 2568 |
-} |
2569 |
||
2570 |
{-# LANGUAGE LambdaCase #-} |
|
2571 |
||
70845 | 2572 |
module Isabelle.Term_XML.Encode (indexname, sort, typ, typ_body, term) |
69240 | 2573 |
where |
2574 |
||
2575 |
import Isabelle.Library |
|
2576 |
import Isabelle.XML.Encode |
|
2577 |
import Isabelle.Term |
|
2578 |
||
70845 | 2579 |
indexname :: P Indexname |
2580 |
indexname (a, b) = if b == 0 then [a] else [a, int_atom b] |
|
69240 | 2581 |
|
2582 |
sort :: T Sort |
|
2583 |
sort = list string |
|
2584 |
||
2585 |
typ :: T Typ |
|
2586 |
typ ty = |
|
2587 |
ty |> variant |
|
2588 |
[\case { Type (a, b) -> Just ([a], list typ b); _ -> Nothing }, |
|
2589 |
\case { TFree (a, b) -> Just ([a], sort b); _ -> Nothing }, |
|
70845 | 2590 |
\case { TVar (a, b) -> Just (indexname a, sort b); _ -> Nothing }] |
2591 |
||
2592 |
typ_body :: T Typ |
|
2593 |
typ_body ty = if is_dummyT ty then [] else typ ty |
|
69240 | 2594 |
|
2595 |
term :: T Term |
|
2596 |
term t = |
|
2597 |
t |> variant |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70667
diff
changeset
|
2598 |
[\case { Const (a, b) -> Just ([a], list typ b); _ -> Nothing }, |
70845 | 2599 |
\case { Free (a, b) -> Just ([a], typ_body b); _ -> Nothing }, |
2600 |
\case { Var (a, b) -> Just (indexname a, typ_body b); _ -> Nothing }, |
|
2601 |
\case { Bound a -> Just ([], int a); _ -> Nothing }, |
|
69240 | 2602 |
\case { Abs (a, b, c) -> Just ([a], pair typ term (b, c)); _ -> Nothing }, |
2603 |
\case { App a -> Just ([], pair term term a); _ -> Nothing }] |
|
2604 |
\<close> |
|
2605 |
||
69444
c3c9440cbf9b
more formal Haskell project setup, with dependencies on packages from "stackage";
wenzelm
parents:
69381
diff
changeset
|
2606 |
generate_file "Isabelle/Term_XML/Decode.hs" = \<open> |
69445 | 2607 |
{- Title: Isabelle/Term_XML/Decode.hs |
69240 | 2608 |
Author: Makarius |
2609 |
LICENSE: BSD 3-clause (Isabelle) |
|
2610 |
||
2611 |
XML data representation of lambda terms. |
|
69280 | 2612 |
|
74178 | 2613 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/term_xml.ML\<close>. |
69240 | 2614 |
-} |
2615 |
||
73177 | 2616 |
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} |
2617 |
||
70845 | 2618 |
module Isabelle.Term_XML.Decode (indexname, sort, typ, typ_body, term) |
69240 | 2619 |
where |
2620 |
||
2621 |
import Isabelle.Library |
|
2622 |
import Isabelle.XML.Decode |
|
2623 |
import Isabelle.Term |
|
2624 |
||
2625 |
||
70845 | 2626 |
indexname :: P Indexname |
2627 |
indexname [a] = (a, 0) |
|
2628 |
indexname [a, b] = (a, int_atom b) |
|
2629 |
||
69240 | 2630 |
sort :: T Sort |
2631 |
sort = list string |
|
2632 |
||
2633 |
typ :: T Typ |
|
2634 |
typ ty = |
|
2635 |
ty |> variant |
|
2636 |
[\([a], b) -> Type (a, list typ b), |
|
2637 |
\([a], b) -> TFree (a, sort b), |
|
70845 | 2638 |
\(a, b) -> TVar (indexname a, sort b)] |
2639 |
||
2640 |
typ_body :: T Typ |
|
2641 |
typ_body [] = dummyT |
|
2642 |
typ_body body = typ body |
|
69240 | 2643 |
|
2644 |
term :: T Term |
|
2645 |
term t = |
|
2646 |
t |> variant |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70667
diff
changeset
|
2647 |
[\([a], b) -> Const (a, list typ b), |
70845 | 2648 |
\([a], b) -> Free (a, typ_body b), |
2649 |
\(a, b) -> Var (indexname a, typ_body b), |
|
2650 |
\([], a) -> Bound (int a), |
|
69240 | 2651 |
\([a], b) -> let (c, d) = pair typ term b in Abs (a, c, d), |
2652 |
\([], a) -> App (pair term term a)] |
|
2653 |
\<close> |
|
2654 |
||
74129 | 2655 |
generate_file "Isabelle/XML/Classes.hs" = \<open> |
2656 |
{- generated by Isabelle -} |
|
2657 |
||
2658 |
{- Title: Isabelle/XML/Classes.hs |
|
2659 |
Author: Makarius |
|
2660 |
LICENSE: BSD 3-clause (Isabelle) |
|
2661 |
||
2662 |
Type classes for XML data representation. |
|
2663 |
-} |
|
2664 |
||
2665 |
{-# LANGUAGE TypeSynonymInstances #-} |
|
2666 |
{-# LANGUAGE FlexibleInstances #-} |
|
2667 |
||
2668 |
module Isabelle.XML.Classes |
|
2669 |
(Encode_Atom(..), Decode_Atom(..), Encode (..), Decode (..)) |
|
2670 |
where |
|
2671 |
||
2672 |
import qualified Isabelle.XML as XML |
|
2673 |
import qualified Isabelle.XML.Encode as Encode |
|
2674 |
import qualified Isabelle.XML.Decode as Decode |
|
2675 |
import qualified Isabelle.Term_XML.Encode as Encode |
|
2676 |
import qualified Isabelle.Term_XML.Decode as Decode |
|
2677 |
import qualified Isabelle.Properties as Properties |
|
2678 |
import Isabelle.Bytes (Bytes) |
|
2679 |
import Isabelle.Term (Typ, Term) |
|
2680 |
||
2681 |
||
2682 |
class Encode_Atom a where encode_atom :: Encode.A a |
|
2683 |
class Decode_Atom a where decode_atom :: Decode.A a |
|
2684 |
||
2685 |
instance Encode_Atom Int where encode_atom = Encode.int_atom |
|
2686 |
instance Decode_Atom Int where decode_atom = Decode.int_atom |
|
2687 |
||
2688 |
instance Encode_Atom Bool where encode_atom = Encode.bool_atom |
|
2689 |
instance Decode_Atom Bool where decode_atom = Decode.bool_atom |
|
2690 |
||
2691 |
instance Encode_Atom () where encode_atom = Encode.unit_atom |
|
2692 |
instance Decode_Atom () where decode_atom = Decode.unit_atom |
|
2693 |
||
2694 |
||
2695 |
class Encode a where encode :: Encode.T a |
|
2696 |
class Decode a where decode :: Decode.T a |
|
2697 |
||
2698 |
instance Encode Bytes where encode = Encode.string |
|
2699 |
instance Decode Bytes where decode = Decode.string |
|
2700 |
||
2701 |
instance Encode Int where encode = Encode.int |
|
2702 |
instance Decode Int where decode = Decode.int |
|
2703 |
||
2704 |
instance Encode Bool where encode = Encode.bool |
|
2705 |
instance Decode Bool where decode = Decode.bool |
|
2706 |
||
2707 |
instance Encode () where encode = Encode.unit |
|
2708 |
instance Decode () where decode = Decode.unit |
|
2709 |
||
2710 |
instance (Encode a, Encode b) => Encode (a, b) |
|
2711 |
where encode = Encode.pair encode encode |
|
2712 |
instance (Decode a, Decode b) => Decode (a, b) |
|
2713 |
where decode = Decode.pair decode decode |
|
2714 |
||
2715 |
instance (Encode a, Encode b, Encode c) => Encode (a, b, c) |
|
2716 |
where encode = Encode.triple encode encode encode |
|
2717 |
instance (Decode a, Decode b, Decode c) => Decode (a, b, c) |
|
2718 |
where decode = Decode.triple decode decode decode |
|
2719 |
||
2720 |
instance Encode a => Encode [a] where encode = Encode.list encode |
|
2721 |
instance Decode a => Decode [a] where decode = Decode.list decode |
|
2722 |
||
2723 |
instance Encode a => Encode (Maybe a) where encode = Encode.option encode |
|
2724 |
instance Decode a => Decode (Maybe a) where decode = Decode.option decode |
|
2725 |
||
2726 |
instance Encode XML.Tree where encode = Encode.tree |
|
2727 |
instance Decode XML.Tree where decode = Decode.tree |
|
2728 |
||
2729 |
instance Encode Properties.T where encode = Encode.properties |
|
2730 |
instance Decode Properties.T where decode = Decode.properties |
|
2731 |
||
2732 |
instance Encode Typ where encode = Encode.typ |
|
2733 |
instance Decode Typ where decode = Decode.typ |
|
2734 |
||
2735 |
instance Encode Term where encode = Encode.term |
|
2736 |
instance Decode Term where decode = Decode.term |
|
2737 |
\<close> |
|
2738 |
||
69459 | 2739 |
generate_file "Isabelle/UUID.hs" = \<open> |
2740 |
{- Title: Isabelle/UUID.hs |
|
2741 |
Author: Makarius |
|
2742 |
LICENSE: BSD 3-clause (Isabelle) |
|
2743 |
||
2744 |
Universally unique identifiers. |
|
2745 |
||
2746 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/General/uuid.scala\<close>. |
|
2747 |
-} |
|
2748 |
||
74095 | 2749 |
module Isabelle.UUID (T, random, print, parse) |
69459 | 2750 |
where |
2751 |
||
74095 | 2752 |
import Prelude hiding (print) |
2753 |
||
69459 | 2754 |
import Data.UUID (UUID) |
2755 |
import qualified Data.UUID as UUID |
|
2756 |
import Data.UUID.V4 (nextRandom) |
|
2757 |
||
74084 | 2758 |
import qualified Isabelle.Bytes as Bytes |
2759 |
import Isabelle.Bytes (Bytes) |
|
2760 |
||
69459 | 2761 |
|
69462 | 2762 |
type T = UUID |
2763 |
||
2764 |
random :: IO T |
|
69459 | 2765 |
random = nextRandom |
2766 |
||
74095 | 2767 |
print :: T -> Bytes |
2768 |
print = Bytes.make . UUID.toASCIIBytes |
|
2769 |
||
2770 |
parse :: Bytes -> Maybe T |
|
2771 |
parse = UUID.fromASCIIBytes . Bytes.unmake |
|
69459 | 2772 |
\<close> |
2773 |
||
69448 | 2774 |
generate_file "Isabelle/Byte_Message.hs" = \<open> |
2775 |
{- Title: Isabelle/Byte_Message.hs |
|
69446 | 2776 |
Author: Makarius |
2777 |
LICENSE: BSD 3-clause (Isabelle) |
|
2778 |
||
69448 | 2779 |
Byte-oriented messages. |
2780 |
||
2781 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/byte_message.ML\<close> |
|
2782 |
and \<^file>\<open>$ISABELLE_HOME/src/Pure/PIDE/byte_message.scala\<close>. |
|
69446 | 2783 |
-} |
2784 |
||
74083 | 2785 |
{-# LANGUAGE OverloadedStrings #-} |
73177 | 2786 |
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} |
2787 |
||
69452 | 2788 |
module Isabelle.Byte_Message ( |
69467 | 2789 |
write, write_line, |
74088 | 2790 |
read, read_block, read_line, |
74187 | 2791 |
make_message, write_message, read_message, |
2792 |
exchange_message, exchange_message0, |
|
73178 | 2793 |
make_line_message, write_line_message, read_line_message, |
2794 |
read_yxml, write_yxml |
|
69452 | 2795 |
) |
69446 | 2796 |
where |
2797 |
||
69449 | 2798 |
import Prelude hiding (read) |
69454 | 2799 |
import Data.Maybe |
69446 | 2800 |
import qualified Data.ByteString as ByteString |
74084 | 2801 |
import qualified Isabelle.Bytes as Bytes |
2802 |
import Isabelle.Bytes (Bytes) |
|
74135 | 2803 |
import qualified Isabelle.Symbol as Symbol |
74080
5b68a5cd7061
prefer UTF8 implementation from Data.Text.Encoding (foreign C);
wenzelm
parents:
73246
diff
changeset
|
2804 |
import qualified Isabelle.UTF8 as UTF8 |
73178 | 2805 |
import qualified Isabelle.XML as XML |
2806 |
import qualified Isabelle.YXML as YXML |
|
73177 | 2807 |
|
69446 | 2808 |
import Network.Socket (Socket) |
74082 | 2809 |
import qualified Network.Socket.ByteString as Socket |
69446 | 2810 |
|
74088 | 2811 |
import Isabelle.Library |
69446 | 2812 |
import qualified Isabelle.Value as Value |
2813 |
||
2814 |
||
69452 | 2815 |
{- output operations -} |
2816 |
||
74084 | 2817 |
write :: Socket -> [Bytes] -> IO () |
2818 |
write socket = Socket.sendMany socket . map Bytes.unmake |
|
2819 |
||
2820 |
write_line :: Socket -> Bytes -> IO () |
|
74083 | 2821 |
write_line socket s = write socket [s, "\n"] |
69467 | 2822 |
|
69452 | 2823 |
|
2824 |
{- input operations -} |
|
2825 |
||
74084 | 2826 |
read :: Socket -> Int -> IO Bytes |
69452 | 2827 |
read socket n = read_body 0 [] |
69449 | 2828 |
where |
74084 | 2829 |
result = Bytes.concat . reverse |
69452 | 2830 |
read_body len ss = |
69449 | 2831 |
if len >= n then return (result ss) |
2832 |
else |
|
2833 |
(do |
|
74082 | 2834 |
s <- Socket.recv socket (min (n - len) 8192) |
69449 | 2835 |
case ByteString.length s of |
2836 |
0 -> return (result ss) |
|
74084 | 2837 |
m -> read_body (len + m) (Bytes.make s : ss)) |
2838 |
||
2839 |
read_block :: Socket -> Int -> IO (Maybe Bytes, Int) |
|
69452 | 2840 |
read_block socket n = do |
2841 |
msg <- read socket n |
|
74084 | 2842 |
let len = Bytes.length msg |
69452 | 2843 |
return (if len == n then Just msg else Nothing, len) |
69449 | 2844 |
|
74084 | 2845 |
read_line :: Socket -> IO (Maybe Bytes) |
69452 | 2846 |
read_line socket = read_body [] |
69446 | 2847 |
where |
74134 | 2848 |
result = trim_line . Bytes.pack . reverse |
69452 | 2849 |
read_body bs = do |
74082 | 2850 |
s <- Socket.recv socket 1 |
69446 | 2851 |
case ByteString.length s of |
2852 |
0 -> return (if null bs then Nothing else Just (result bs)) |
|
2853 |
1 -> |
|
2854 |
case ByteString.head s of |
|
2855 |
10 -> return (Just (result bs)) |
|
69452 | 2856 |
b -> read_body (b : bs) |
69446 | 2857 |
|
69448 | 2858 |
|
69454 | 2859 |
{- messages with multiple chunks (arbitrary content) -} |
2860 |
||
74084 | 2861 |
make_header :: [Int] -> [Bytes] |
74095 | 2862 |
make_header ns = [space_implode "," (map Value.print_int ns), "\n"] |
69454 | 2863 |
|
74084 | 2864 |
make_message :: [Bytes] -> [Bytes] |
2865 |
make_message chunks = make_header (map Bytes.length chunks) <> chunks |
|
2866 |
||
2867 |
write_message :: Socket -> [Bytes] -> IO () |
|
69476 | 2868 |
write_message socket = write socket . make_message |
69454 | 2869 |
|
74084 | 2870 |
parse_header :: Bytes -> [Int] |
69454 | 2871 |
parse_header line = |
2872 |
let |
|
74132 | 2873 |
res = map Value.parse_nat (space_explode ',' line) |
69454 | 2874 |
in |
2875 |
if all isJust res then map fromJust res |
|
74081 | 2876 |
else error ("Malformed message header: " <> quote (UTF8.decode line)) |
69454 | 2877 |
|
74084 | 2878 |
read_chunk :: Socket -> Int -> IO Bytes |
69454 | 2879 |
read_chunk socket n = do |
2880 |
res <- read_block socket n |
|
2881 |
return $ |
|
2882 |
case res of |
|
2883 |
(Just chunk, _) -> chunk |
|
2884 |
(Nothing, len) -> |
|
74081 | 2885 |
error ("Malformed message chunk: unexpected EOF after " <> |
2886 |
show len <> " of " <> show n <> " bytes") |
|
69454 | 2887 |
|
74084 | 2888 |
read_message :: Socket -> IO (Maybe [Bytes]) |
69454 | 2889 |
read_message socket = do |
2890 |
res <- read_line socket |
|
2891 |
case res of |
|
2892 |
Just line -> Just <$> mapM (read_chunk socket) (parse_header line) |
|
2893 |
Nothing -> return Nothing |
|
2894 |
||
74186 | 2895 |
exchange_message :: Socket -> [Bytes] -> IO (Maybe [Bytes]) |
2896 |
exchange_message socket msg = do |
|
2897 |
write_message socket msg |
|
2898 |
read_message socket |
|
2899 |
||
74187 | 2900 |
exchange_message0 :: Socket -> [Bytes] -> IO () |
2901 |
exchange_message0 socket msg = do |
|
2902 |
_ <- exchange_message socket msg |
|
2903 |
return () |
|
2904 |
||
69454 | 2905 |
|
69448 | 2906 |
-- hybrid messages: line or length+block (with content restriction) |
2907 |
||
74084 | 2908 |
is_length :: Bytes -> Bool |
69452 | 2909 |
is_length msg = |
74135 | 2910 |
not (Bytes.null msg) && Bytes.all_char (\c -> '0' <= c && c <= '9') msg |
74084 | 2911 |
|
2912 |
is_terminated :: Bytes -> Bool |
|
69452 | 2913 |
is_terminated msg = |
74135 | 2914 |
not (Bytes.null msg) && Symbol.is_ascii_line_terminator (Bytes.char $ Bytes.last msg) |
74084 | 2915 |
|
2916 |
make_line_message :: Bytes -> [Bytes] |
|
69476 | 2917 |
make_line_message msg = |
74084 | 2918 |
let n = Bytes.length msg in |
69476 | 2919 |
if is_length msg || is_terminated msg then |
74081 | 2920 |
error ("Bad content for line message:\n" <> take 100 (UTF8.decode msg)) |
69476 | 2921 |
else |
74135 | 2922 |
(if n > 100 || Bytes.any_char (== '\n') msg then make_header [n + 1] else []) <> [msg, "\n"] |
74084 | 2923 |
|
2924 |
write_line_message :: Socket -> Bytes -> IO () |
|
69476 | 2925 |
write_line_message socket = write socket . make_line_message |
69448 | 2926 |
|
74084 | 2927 |
read_line_message :: Socket -> IO (Maybe Bytes) |
69448 | 2928 |
read_line_message socket = do |
69446 | 2929 |
opt_line <- read_line socket |
2930 |
case opt_line of |
|
2931 |
Nothing -> return Nothing |
|
2932 |
Just line -> |
|
74095 | 2933 |
case Value.parse_nat line of |
69446 | 2934 |
Nothing -> return $ Just line |
74134 | 2935 |
Just n -> fmap trim_line . fst <$> read_block socket n |
73178 | 2936 |
|
2937 |
||
2938 |
read_yxml :: Socket -> IO (Maybe XML.Body) |
|
2939 |
read_yxml socket = do |
|
2940 |
res <- read_line_message socket |
|
74095 | 2941 |
return (YXML.parse_body <$> res) |
73178 | 2942 |
|
2943 |
write_yxml :: Socket -> XML.Body -> IO () |
|
2944 |
write_yxml socket body = |
|
74095 | 2945 |
write_line_message socket (YXML.string_of_body body) |
69446 | 2946 |
\<close> |
2947 |
||
71692 | 2948 |
generate_file "Isabelle/Isabelle_Thread.hs" = \<open> |
2949 |
{- Title: Isabelle/Isabelle_Thread.hs |
|
69473 | 2950 |
Author: Makarius |
2951 |
LICENSE: BSD 3-clause (Isabelle) |
|
2952 |
||
71692 | 2953 |
Isabelle-specific thread management. |
2954 |
||
2955 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/Concurrent/isabelle_thread.ML\<close> |
|
2956 |
and \<^file>\<open>$ISABELLE_HOME/src/Pure/Concurrent/isabelle_thread.scala\<close>. |
|
69473 | 2957 |
-} |
2958 |
||
2959 |
{-# LANGUAGE NamedFieldPuns #-} |
|
2960 |
||
71692 | 2961 |
module Isabelle.Isabelle_Thread ( |
69473 | 2962 |
ThreadId, Result, |
69494 | 2963 |
find_id, |
69473 | 2964 |
properties, change_properties, |
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
2965 |
add_resource, del_resource, bracket_resource, |
69497 | 2966 |
is_stopped, expose_stopped, stop, |
69496 | 2967 |
my_uuid, stop_uuid, |
69494 | 2968 |
Fork, fork_finally, fork) |
69473 | 2969 |
where |
2970 |
||
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
2971 |
import Data.Unique |
69473 | 2972 |
import Data.IORef |
2973 |
import System.IO.Unsafe |
|
2974 |
||
69494 | 2975 |
import qualified Data.List as List |
69497 | 2976 |
import Control.Monad (when, forM_) |
69473 | 2977 |
import Data.Map.Strict (Map) |
2978 |
import qualified Data.Map.Strict as Map |
|
2979 |
import Control.Exception as Exception |
|
2980 |
import Control.Concurrent (ThreadId) |
|
2981 |
import qualified Control.Concurrent as Concurrent |
|
2982 |
import Control.Concurrent.Thread (Result) |
|
2983 |
import qualified Control.Concurrent.Thread as Thread |
|
69494 | 2984 |
import qualified Isabelle.UUID as UUID |
69473 | 2985 |
import qualified Isabelle.Properties as Properties |
2986 |
||
2987 |
||
2988 |
{- thread info -} |
|
2989 |
||
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
2990 |
type Resources = Map Unique (IO ()) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
2991 |
data Info = Info {uuid :: UUID.T, props :: Properties.T, stopped :: Bool, resources :: Resources} |
69473 | 2992 |
type Infos = Map ThreadId Info |
2993 |
||
2994 |
lookup_info :: Infos -> ThreadId -> Maybe Info |
|
69494 | 2995 |
lookup_info infos id = Map.lookup id infos |
2996 |
||
2997 |
init_info :: ThreadId -> UUID.T -> Infos -> (Infos, ()) |
|
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
2998 |
init_info id uuid infos = (Map.insert id (Info uuid [] False Map.empty) infos, ()) |
69473 | 2999 |
|
3000 |
||
3001 |
{- global state -} |
|
3002 |
||
3003 |
{-# NOINLINE global_state #-} |
|
3004 |
global_state :: IORef Infos |
|
3005 |
global_state = unsafePerformIO (newIORef Map.empty) |
|
3006 |
||
69494 | 3007 |
find_id :: UUID.T -> IO (Maybe ThreadId) |
3008 |
find_id uuid = do |
|
3009 |
state <- readIORef global_state |
|
3010 |
return $ fst <$> List.find (\(_, Info{uuid = uuid'}) -> uuid == uuid') (Map.assocs state) |
|
3011 |
||
69473 | 3012 |
get_info :: ThreadId -> IO (Maybe Info) |
3013 |
get_info id = do |
|
3014 |
state <- readIORef global_state |
|
3015 |
return $ lookup_info state id |
|
3016 |
||
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3017 |
map_info :: ThreadId -> (Info -> Info) -> IO (Maybe Info) |
69473 | 3018 |
map_info id f = |
3019 |
atomicModifyIORef' global_state |
|
3020 |
(\infos -> |
|
3021 |
case lookup_info infos id of |
|
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3022 |
Nothing -> (infos, Nothing) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3023 |
Just info -> |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3024 |
let info' = f info |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3025 |
in (Map.insert id info' infos, Just info')) |
69473 | 3026 |
|
69495 | 3027 |
delete_info :: ThreadId -> IO () |
3028 |
delete_info id = |
|
3029 |
atomicModifyIORef' global_state (\infos -> (Map.delete id infos, ())) |
|
3030 |
||
69473 | 3031 |
|
3032 |
{- thread properties -} |
|
3033 |
||
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
3034 |
my_info :: IO (Maybe Info) |
69473 | 3035 |
my_info = do |
3036 |
id <- Concurrent.myThreadId |
|
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
3037 |
get_info id |
69473 | 3038 |
|
3039 |
properties :: IO Properties.T |
|
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
3040 |
properties = maybe [] props <$> my_info |
69473 | 3041 |
|
3042 |
change_properties :: (Properties.T -> Properties.T) -> IO () |
|
3043 |
change_properties f = do |
|
3044 |
id <- Concurrent.myThreadId |
|
3045 |
map_info id (\info -> info {props = f (props info)}) |
|
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3046 |
return () |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3047 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3048 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3049 |
{- managed resources -} |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3050 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3051 |
add_resource :: IO () -> IO Unique |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3052 |
add_resource resource = do |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3053 |
id <- Concurrent.myThreadId |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3054 |
u <- newUnique |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3055 |
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
|
3056 |
return u |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3057 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3058 |
del_resource :: Unique -> IO () |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3059 |
del_resource u = do |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3060 |
id <- Concurrent.myThreadId |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3061 |
map_info id (\info -> info {resources = Map.delete u (resources info)}) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3062 |
return () |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3063 |
|
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3064 |
bracket_resource :: IO () -> IO a -> IO a |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3065 |
bracket_resource resource body = |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3066 |
Exception.bracket (add_resource resource) del_resource (const body) |
69473 | 3067 |
|
3068 |
||
3069 |
{- stop -} |
|
3070 |
||
3071 |
is_stopped :: IO Bool |
|
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
3072 |
is_stopped = maybe False stopped <$> my_info |
69473 | 3073 |
|
69497 | 3074 |
expose_stopped :: IO () |
3075 |
expose_stopped = do |
|
3076 |
stopped <- is_stopped |
|
3077 |
when stopped $ throw ThreadKilled |
|
3078 |
||
69473 | 3079 |
stop :: ThreadId -> IO () |
69499
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3080 |
stop id = do |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3081 |
info <- map_info id (\info -> info {stopped = True}) |
638fdbbc7d1f
more Haskell operations: managed resources for threads;
wenzelm
parents:
69498
diff
changeset
|
3082 |
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
|
3083 |
sequence_ ops |
69473 | 3084 |
|
3085 |
||
69496 | 3086 |
{- UUID -} |
3087 |
||
69498
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
3088 |
my_uuid :: IO (Maybe UUID.T) |
22e958b76bf6
more robust: suitable defaults for unmanaged threads;
wenzelm
parents:
69497
diff
changeset
|
3089 |
my_uuid = fmap uuid <$> my_info |
69496 | 3090 |
|
3091 |
stop_uuid :: UUID.T -> IO () |
|
3092 |
stop_uuid uuid = do |
|
3093 |
id <- find_id uuid |
|
3094 |
forM_ id stop |
|
3095 |
||
3096 |
||
69473 | 3097 |
{- fork -} |
3098 |
||
69494 | 3099 |
type Fork a = (ThreadId, UUID.T, IO (Result a)) |
3100 |
||
3101 |
fork_finally :: IO a -> (Either SomeException a -> IO b) -> IO (Fork b) |
|
69473 | 3102 |
fork_finally body finally = do |
69494 | 3103 |
uuid <- UUID.random |
69473 | 3104 |
(id, result) <- |
3105 |
Exception.mask (\restore -> |
|
3106 |
Thread.forkIO |
|
3107 |
(Exception.try |
|
3108 |
(do |
|
3109 |
id <- Concurrent.myThreadId |
|
69494 | 3110 |
atomicModifyIORef' global_state (init_info id uuid) |
69495 | 3111 |
restore body) |
3112 |
>>= (\res -> do id <- Concurrent.myThreadId; delete_info id; finally res))) |
|
69494 | 3113 |
return (id, uuid, result) |
3114 |
||
3115 |
fork :: IO a -> IO (Fork a) |
|
69473 | 3116 |
fork body = fork_finally body Thread.result |
3117 |
\<close> |
|
3118 |
||
69455 | 3119 |
generate_file "Isabelle/Server.hs" = \<open> |
3120 |
{- Title: Isabelle/Server.hs |
|
3121 |
Author: Makarius |
|
3122 |
LICENSE: BSD 3-clause (Isabelle) |
|
3123 |
||
3124 |
TCP server on localhost. |
|
3125 |
-} |
|
3126 |
||
74127 | 3127 |
{-# LANGUAGE OverloadedStrings #-} |
3128 |
||
69465 | 3129 |
module Isabelle.Server ( |
3130 |
localhost_name, localhost, publish_text, publish_stdout, |
|
73178 | 3131 |
server, connection |
69465 | 3132 |
) |
3133 |
where |
|
69455 | 3134 |
|
69465 | 3135 |
import Control.Monad (forever, when) |
69455 | 3136 |
import qualified Control.Exception as Exception |
3137 |
import Network.Socket (Socket) |
|
3138 |
import qualified Network.Socket as Socket |
|
69472 | 3139 |
import qualified System.IO as IO |
74127 | 3140 |
import qualified Data.ByteString.Char8 as Char8 |
69455 | 3141 |
|
69462 | 3142 |
import Isabelle.Library |
74127 | 3143 |
import qualified Isabelle.Bytes as Bytes |
74084 | 3144 |
import Isabelle.Bytes (Bytes) |
69462 | 3145 |
import qualified Isabelle.UUID as UUID |
69465 | 3146 |
import qualified Isabelle.Byte_Message as Byte_Message |
71692 | 3147 |
import qualified Isabelle.Isabelle_Thread as Isabelle_Thread |
69462 | 3148 |
|
3149 |
||
3150 |
{- server address -} |
|
69455 | 3151 |
|
74127 | 3152 |
localhost_name :: Bytes |
69463 | 3153 |
localhost_name = "127.0.0.1" |
3154 |
||
69455 | 3155 |
localhost :: Socket.HostAddress |
3156 |
localhost = Socket.tupleToHostAddress (127, 0, 0, 1) |
|
3157 |
||
74127 | 3158 |
publish_text :: Bytes -> Bytes -> UUID.T -> Bytes |
69462 | 3159 |
publish_text name address password = |
74127 | 3160 |
"server " <> quote name <> " = " <> address <> |
74128 | 3161 |
" (password " <> quote (show_bytes password) <> ")" |
74127 | 3162 |
|
3163 |
publish_stdout :: Bytes -> Bytes -> UUID.T -> IO () |
|
74095 | 3164 |
publish_stdout name address password = |
74127 | 3165 |
Char8.putStrLn (Bytes.unmake $ publish_text name address password) |
69462 | 3166 |
|
3167 |
||
3168 |
{- server -} |
|
3169 |
||
74127 | 3170 |
server :: (Bytes -> UUID.T -> IO ()) -> (Socket -> IO ()) -> IO () |
69455 | 3171 |
server publish handle = |
69462 | 3172 |
Socket.withSocketsDo $ Exception.bracket open (Socket.close . fst) (uncurry loop) |
69455 | 3173 |
where |
74084 | 3174 |
open :: IO (Socket, Bytes) |
69455 | 3175 |
open = do |
69466 | 3176 |
server_socket <- Socket.socket Socket.AF_INET Socket.Stream Socket.defaultProtocol |
3177 |
Socket.bind server_socket (Socket.SockAddrInet 0 localhost) |
|
3178 |
Socket.listen server_socket 50 |
|
69462 | 3179 |
|
69466 | 3180 |
port <- Socket.socketPort server_socket |
74128 | 3181 |
let address = localhost_name <> ":" <> show_bytes port |
69462 | 3182 |
password <- UUID.random |
3183 |
publish address password |
|
69455 | 3184 |
|
74095 | 3185 |
return (server_socket, UUID.print password) |
69462 | 3186 |
|
74084 | 3187 |
loop :: Socket -> Bytes -> IO () |
69466 | 3188 |
loop server_socket password = forever $ do |
69480 | 3189 |
(connection, _) <- Socket.accept server_socket |
71692 | 3190 |
Isabelle_Thread.fork_finally |
69465 | 3191 |
(do |
3192 |
line <- Byte_Message.read_line connection |
|
3193 |
when (line == Just password) $ handle connection) |
|
69473 | 3194 |
(\finally -> do |
69472 | 3195 |
Socket.close connection |
69473 | 3196 |
case finally of |
69472 | 3197 |
Left exn -> IO.hPutStrLn IO.stderr $ Exception.displayException exn |
3198 |
Right () -> return ()) |
|
69455 | 3199 |
return () |
73178 | 3200 |
|
3201 |
||
3202 |
{- client connection -} |
|
3203 |
||
74095 | 3204 |
connection :: String -> Bytes -> (Socket -> IO a) -> IO a |
73178 | 3205 |
connection port password client = |
3206 |
Socket.withSocketsDo $ do |
|
3207 |
addr <- resolve |
|
3208 |
Exception.bracket (open addr) Socket.close body |
|
3209 |
where |
|
3210 |
resolve = do |
|
3211 |
let hints = |
|
3212 |
Socket.defaultHints { |
|
3213 |
Socket.addrFlags = [Socket.AI_NUMERICHOST, Socket.AI_NUMERICSERV], |
|
3214 |
Socket.addrSocketType = Socket.Stream } |
|
3215 |
head <$> Socket.getAddrInfo (Just hints) (Just "127.0.0.1") (Just port) |
|
3216 |
||
3217 |
open addr = do |
|
3218 |
socket <- Socket.socket (Socket.addrFamily addr) (Socket.addrSocketType addr) |
|
3219 |
(Socket.addrProtocol addr) |
|
3220 |
Socket.connect socket $ Socket.addrAddress addr |
|
3221 |
return socket |
|
3222 |
||
3223 |
body socket = do |
|
74095 | 3224 |
Byte_Message.write_line socket password |
73178 | 3225 |
client socket |
69455 | 3226 |
\<close> |
3227 |
||
74161 | 3228 |
generate_file "Isabelle/Time.hs" = \<open> |
3229 |
{- Title: Isabelle/Time.hs |
|
3230 |
Author: Makarius |
|
3231 |
LICENSE: BSD 3-clause (Isabelle) |
|
3232 |
||
3233 |
Time based on milliseconds. |
|
3234 |
||
3235 |
See \<^file>\<open>~~/src/Pure/General/time.scala\<close> |
|
3236 |
-} |
|
3237 |
||
3238 |
{-# LANGUAGE OverloadedStrings #-} |
|
3239 |
||
3240 |
module Isabelle.Time ( |
|
3241 |
Time, seconds, minutes, ms, zero, is_zero, is_relevant, |
|
3242 |
get_seconds, get_minutes, get_ms, message |
|
3243 |
) |
|
3244 |
where |
|
3245 |
||
3246 |
import Text.Printf (printf) |
|
3247 |
import Isabelle.Bytes (Bytes) |
|
3248 |
import Isabelle.Library |
|
3249 |
||
3250 |
||
3251 |
data Time = Time Int |
|
3252 |
||
3253 |
instance Eq Time where Time ms1 == Time ms2 = ms1 == ms2 |
|
3254 |
instance Ord Time where compare (Time ms1) (Time ms2) = compare ms1 ms2 |
|
3255 |
||
3256 |
seconds :: Double -> Time |
|
3257 |
seconds s = Time (round (s * 1000.0)) |
|
3258 |
||
3259 |
minutes :: Double -> Time |
|
3260 |
minutes m = Time (round (m * 60000.0)) |
|
3261 |
||
3262 |
ms :: Int -> Time |
|
3263 |
ms = Time |
|
3264 |
||
3265 |
zero :: Time |
|
3266 |
zero = ms 0 |
|
3267 |
||
3268 |
is_zero :: Time -> Bool |
|
3269 |
is_zero (Time ms) = ms == 0 |
|
3270 |
||
3271 |
is_relevant :: Time -> Bool |
|
3272 |
is_relevant (Time ms) = ms >= 1 |
|
3273 |
||
3274 |
get_seconds :: Time -> Double |
|
3275 |
get_seconds (Time ms) = fromIntegral ms / 1000.0 |
|
3276 |
||
3277 |
get_minutes :: Time -> Double |
|
3278 |
get_minutes (Time ms) = fromIntegral ms / 60000.0 |
|
3279 |
||
3280 |
get_ms :: Time -> Int |
|
3281 |
get_ms (Time ms) = ms |
|
3282 |
||
3283 |
instance Show Time where |
|
3284 |
show t = printf "%.3f" (get_seconds t) |
|
3285 |
||
3286 |
message :: Time -> Bytes |
|
3287 |
message t = make_bytes (show t) <> "s" |
|
3288 |
\<close> |
|
3289 |
||
3290 |
generate_file "Isabelle/Timing.hs" = \<open> |
|
3291 |
{- Title: Isabelle/Timing.hs |
|
3292 |
Author: Makarius |
|
3293 |
LICENSE: BSD 3-clause (Isabelle) |
|
3294 |
||
3295 |
Support for time measurement. |
|
3296 |
||
3297 |
See \<^file>\<open>~~/src/Pure/General/timing.ML\<close> |
|
3298 |
and \<^file>\<open>~~/src/Pure/General/timing.scala\<close> |
|
3299 |
-} |
|
3300 |
||
3301 |
module Isabelle.Timing ( |
|
3302 |
Timing (..), zero, is_zero, is_relevant |
|
3303 |
) |
|
3304 |
where |
|
3305 |
||
3306 |
import qualified Isabelle.Time as Time |
|
3307 |
import Isabelle.Time (Time) |
|
3308 |
||
3309 |
data Timing = Timing {elapsed :: Time, cpu :: Time, gc :: Time} |
|
3310 |
deriving (Show, Eq) |
|
3311 |
||
3312 |
zero :: Timing |
|
3313 |
zero = Timing Time.zero Time.zero Time.zero |
|
3314 |
||
3315 |
is_zero :: Timing -> Bool |
|
3316 |
is_zero t = Time.is_zero (elapsed t) && Time.is_zero (cpu t) && Time.is_zero (gc t) |
|
3317 |
||
3318 |
is_relevant :: Timing -> Bool |
|
3319 |
is_relevant t = Time.is_relevant (elapsed t) || Time.is_relevant (cpu t) || Time.is_relevant (gc t) |
|
3320 |
\<close> |
|
3321 |
||
3322 |
generate_file "Isabelle/Bash.hs" = \<open> |
|
3323 |
{- Title: Isabelle/Bash.hs |
|
3324 |
Author: Makarius |
|
3325 |
LICENSE: BSD 3-clause (Isabelle) |
|
3326 |
||
3327 |
Support for GNU bash. |
|
3328 |
||
3329 |
See \<^file>\<open>$ISABELLE_HOME/src/Pure/System/bash.ML\<close> |
|
3330 |
-} |
|
3331 |
||
3332 |
{-# LANGUAGE OverloadedStrings #-} |
|
3333 |
||
3334 |
module Isabelle.Bash ( |
|
3335 |
string, strings, |
|
3336 |
||
3337 |
Params, |
|
3338 |
get_script, get_input, get_cwd, get_putenv, get_redirect, |
|
3339 |
get_timeout, get_description, |
|
3340 |
script, input, cwd, putenv, redirect, timeout, description, |
|
3341 |
) |
|
3342 |
where |
|
3343 |
||
3344 |
import Text.Printf (printf) |
|
3345 |
import qualified Isabelle.Symbol as Symbol |
|
3346 |
import qualified Isabelle.Bytes as Bytes |
|
3347 |
import Isabelle.Bytes (Bytes) |
|
3348 |
import qualified Isabelle.Time as Time |
|
3349 |
import Isabelle.Time (Time) |
|
3350 |
import Isabelle.Library |
|
3351 |
||
3352 |
||
3353 |
{- concrete syntax -} |
|
3354 |
||
3355 |
string :: Bytes -> Bytes |
|
3356 |
string str = |
|
3357 |
if Bytes.null str then "\"\"" |
|
3358 |
else str |> Bytes.unpack |> map trans |> Bytes.concat |
|
3359 |
where |
|
3360 |
trans b = |
|
3361 |
case Bytes.char b of |
|
3362 |
'\t' -> "$'\\t'" |
|
3363 |
'\n' -> "$'\\n'" |
|
3364 |
'\f' -> "$'\\f'" |
|
3365 |
'\r' -> "$'\\r'" |
|
3366 |
c -> |
|
74169 | 3367 |
if Symbol.is_ascii_letter c || Symbol.is_ascii_digit c || c `elem` ("+,-./:_" :: String) |
74161 | 3368 |
then Bytes.singleton b |
3369 |
else if b < 32 || b >= 127 then make_bytes (printf "$'\\x%02x'" b :: String) |
|
3370 |
else "\\" <> Bytes.singleton b |
|
3371 |
||
3372 |
strings :: [Bytes] -> Bytes |
|
3373 |
strings = space_implode " " . map string |
|
3374 |
||
3375 |
||
3376 |
{- server parameters -} |
|
3377 |
||
3378 |
data Params = Params { |
|
3379 |
_script :: Bytes, |
|
3380 |
_input :: Bytes, |
|
3381 |
_cwd :: Maybe Bytes, |
|
3382 |
_putenv :: [(Bytes, Bytes)], |
|
3383 |
_redirect :: Bool, |
|
3384 |
_timeout :: Time, |
|
3385 |
_description :: Bytes} |
|
3386 |
deriving (Show, Eq) |
|
3387 |
||
3388 |
get_script :: Params -> Bytes |
|
3389 |
get_script = _script |
|
3390 |
||
3391 |
get_input :: Params -> Bytes |
|
3392 |
get_input = _input |
|
3393 |
||
3394 |
get_cwd :: Params -> Maybe Bytes |
|
3395 |
get_cwd = _cwd |
|
3396 |
||
3397 |
get_putenv :: Params -> [(Bytes, Bytes)] |
|
3398 |
get_putenv = _putenv |
|
3399 |
||
3400 |
get_redirect :: Params -> Bool |
|
3401 |
get_redirect = _redirect |
|
3402 |
||
3403 |
get_timeout :: Params -> Time |
|
3404 |
get_timeout = _timeout |
|
3405 |
||
3406 |
get_description :: Params -> Bytes |
|
3407 |
get_description = _description |
|
3408 |
||
3409 |
script :: Bytes -> Params |
|
3410 |
script script = Params script "" Nothing [] False Time.zero "" |
|
3411 |
||
3412 |
input :: Bytes -> Params -> Params |
|
3413 |
input input params = params { _input = input } |
|
3414 |
||
3415 |
cwd :: Bytes -> Params -> Params |
|
3416 |
cwd cwd params = params { _cwd = Just cwd } |
|
3417 |
||
3418 |
putenv :: [(Bytes, Bytes)] -> Params -> Params |
|
3419 |
putenv putenv params = params { _putenv = putenv } |
|
3420 |
||
3421 |
redirect :: Params -> Params |
|
3422 |
redirect params = params { _redirect = True } |
|
3423 |
||
3424 |
timeout :: Time -> Params -> Params |
|
3425 |
timeout timeout params = params { _timeout = timeout } |
|
3426 |
||
3427 |
description :: Bytes -> Params -> Params |
|
3428 |
description description params = params { _description = description } |
|
3429 |
\<close> |
|
3430 |
||
3431 |
generate_file "Isabelle/Process_Result.hs" = \<open> |
|
3432 |
{- Title: Isabelle/Process_Result.hs |
|
3433 |
Author: Makarius |
|
3434 |
LICENSE: BSD 3-clause (Isabelle) |
|
3435 |
||
3436 |
Result of system process. |
|
3437 |
||
3438 |
See \<^file>\<open>~~/src/Pure/System/process_result.ML\<close> |
|
3439 |
and \<^file>\<open>~~/src/Pure/System/process_result.scala\<close> |
|
3440 |
-} |
|
3441 |
||
3442 |
{-# LANGUAGE OverloadedStrings #-} |
|
3443 |
||
3444 |
module Isabelle.Process_Result ( |
|
3445 |
interrupt_rc, timeout_rc, |
|
3446 |
||
3447 |
T, make, rc, out_lines, err_lines, timing, timing_elapsed, out, err, ok, check |
|
3448 |
) |
|
3449 |
where |
|
3450 |
||
3451 |
import Isabelle.Time (Time) |
|
3452 |
import qualified Isabelle.Timing as Timing |
|
3453 |
import Isabelle.Timing (Timing) |
|
3454 |
import Isabelle.Bytes (Bytes) |
|
3455 |
import Isabelle.Library |
|
3456 |
||
3457 |
||
3458 |
interrupt_rc :: Int |
|
3459 |
interrupt_rc = 130 |
|
3460 |
||
3461 |
timeout_rc :: Int |
|
3462 |
timeout_rc = 142 |
|
3463 |
||
3464 |
data T = |
|
3465 |
Process_Result { |
|
3466 |
_rc :: Int, |
|
3467 |
_out_lines :: [Bytes], |
|
3468 |
_err_lines :: [Bytes], |
|
3469 |
_timing :: Timing} |
|
3470 |
deriving (Show, Eq) |
|
3471 |
||
3472 |
make :: Int -> [Bytes] -> [Bytes] -> Timing -> T |
|
3473 |
make = Process_Result |
|
3474 |
||
3475 |
rc :: T -> Int |
|
3476 |
rc = _rc |
|
3477 |
||
3478 |
out_lines :: T -> [Bytes] |
|
3479 |
out_lines = _out_lines |
|
3480 |
||
3481 |
err_lines :: T -> [Bytes] |
|
3482 |
err_lines = _err_lines |
|
3483 |
||
3484 |
timing :: T -> Timing |
|
3485 |
timing = _timing |
|
3486 |
||
3487 |
timing_elapsed :: T -> Time |
|
3488 |
timing_elapsed = Timing.elapsed . timing |
|
3489 |
||
3490 |
out :: T -> Bytes |
|
3491 |
out = trim_line . cat_lines . out_lines |
|
3492 |
||
3493 |
err :: T -> Bytes |
|
3494 |
err = trim_line . cat_lines . err_lines |
|
3495 |
||
3496 |
ok :: T -> Bool |
|
3497 |
ok result = rc result == 0 |
|
3498 |
||
3499 |
check :: T -> T |
|
3500 |
check result = if ok result then result else error (make_string $ err result) |
|
3501 |
\<close> |
|
3502 |
||
3503 |
generate_file "Isabelle/Options.hs" = \<open> |
|
3504 |
{- Title: Isabelle/Options.hs |
|
3505 |
Author: Makarius |
|
3506 |
LICENSE: BSD 3-clause (Isabelle) |
|
3507 |
||
3508 |
System options with external string representation. |
|
3509 |
||
3510 |
See \<^file>\<open>~~/src/Pure/System/options.ML\<close> |
|
3511 |
and \<^file>\<open>~~/src/Pure/System/options.scala\<close> |
|
3512 |
-} |
|
3513 |
||
3514 |
{-# LANGUAGE OverloadedStrings #-} |
|
3515 |
{-# LANGUAGE InstanceSigs #-} |
|
3516 |
||
3517 |
module Isabelle.Options ( |
|
3518 |
boolT, intT, realT, stringT, unknownT, |
|
3519 |
||
3520 |
T, typ, bool, int, real, seconds, string, |
|
3521 |
decode |
|
3522 |
) |
|
3523 |
where |
|
3524 |
||
3525 |
import qualified Data.Map.Strict as Map |
|
3526 |
import Data.Map.Strict (Map) |
|
3527 |
import qualified Isabelle.Properties as Properties |
|
3528 |
import Isabelle.Bytes (Bytes) |
|
3529 |
import qualified Isabelle.Value as Value |
|
3530 |
import qualified Isabelle.Time as Time |
|
3531 |
import Isabelle.Time (Time) |
|
3532 |
import Isabelle.Library |
|
3533 |
import qualified Isabelle.XML.Decode as Decode |
|
3534 |
import Isabelle.XML.Classes (Decode (..)) |
|
3535 |
||
3536 |
||
3537 |
{- representation -} |
|
3538 |
||
3539 |
boolT :: Bytes |
|
3540 |
boolT = "bool" |
|
3541 |
||
3542 |
intT :: Bytes |
|
3543 |
intT = "int" |
|
3544 |
||
3545 |
realT :: Bytes |
|
3546 |
realT = "real" |
|
3547 |
||
3548 |
stringT :: Bytes |
|
3549 |
stringT = "string" |
|
3550 |
||
3551 |
unknownT :: Bytes |
|
3552 |
unknownT = "unknown" |
|
3553 |
||
3554 |
data Opt = Opt { |
|
3555 |
_pos :: Properties.T, |
|
3556 |
_name :: Bytes, |
|
3557 |
_typ :: Bytes, |
|
3558 |
_value :: Bytes } |
|
3559 |
||
3560 |
data T = Options (Map Bytes Opt) |
|
3561 |
||
3562 |
||
3563 |
{- check -} |
|
3564 |
||
3565 |
check_name :: T -> Bytes -> Opt |
|
3566 |
check_name (Options map) name = |
|
3567 |
case Map.lookup name map of |
|
3568 |
Just opt | _typ opt /= unknownT -> opt |
|
3569 |
_ -> error (make_string ("Unknown system option " <> quote name)) |
|
3570 |
||
3571 |
check_type :: T -> Bytes -> Bytes -> Opt |
|
3572 |
check_type options name typ = |
|
3573 |
let |
|
3574 |
opt = check_name options name |
|
3575 |
t = _typ opt |
|
3576 |
in |
|
3577 |
if t == typ then opt |
|
3578 |
else error (make_string ("Ill-typed system option " <> quote name <> " : " <> t <> " vs. " <> typ)) |
|
3579 |
||
3580 |
||
3581 |
{- get typ -} |
|
3582 |
||
3583 |
typ :: T -> Bytes -> Bytes |
|
3584 |
typ options name = _typ (check_name options name) |
|
3585 |
||
3586 |
||
3587 |
{- get value -} |
|
3588 |
||
3589 |
get :: Bytes -> (Bytes -> Maybe a) -> T -> Bytes -> a |
|
3590 |
get typ parse options name = |
|
3591 |
let opt = check_type options name typ in |
|
3592 |
case parse (_value opt) of |
|
3593 |
Just x -> x |
|
3594 |
Nothing -> |
|
3595 |
error (make_string ("Malformed value for system option " <> quote name <> |
|
3596 |
" : " <> typ <> " =\n" <> quote (_value opt))) |
|
3597 |
||
3598 |
bool :: T -> Bytes -> Bool |
|
3599 |
bool = get boolT Value.parse_bool |
|
3600 |
||
3601 |
int :: T -> Bytes -> Int |
|
3602 |
int = get intT Value.parse_int |
|
3603 |
||
3604 |
real :: T -> Bytes -> Double |
|
3605 |
real = get realT Value.parse_real |
|
3606 |
||
3607 |
seconds :: T -> Bytes -> Time |
|
3608 |
seconds options = Time.seconds . real options |
|
3609 |
||
3610 |
string :: T -> Bytes -> Bytes |
|
3611 |
string = get stringT Just |
|
3612 |
||
3613 |
||
3614 |
{- decode -} |
|
3615 |
||
3616 |
instance Decode T where |
|
3617 |
decode :: Decode.T T |
|
3618 |
decode = |
|
3619 |
let |
|
3620 |
decode_entry :: Decode.T (Bytes, Opt) |
|
3621 |
decode_entry body = |
|
3622 |
let |
|
3623 |
(pos, (name, (typ, value))) = |
|
3624 |
Decode.pair Decode.properties (Decode.pair Decode.string (Decode.pair Decode.string Decode.string)) body |
|
3625 |
in (name, Opt { _pos = pos, _name = name, _typ = typ, _value = value }) |
|
3626 |
in Options . Map.fromList . Decode.list decode_entry |
|
3627 |
\<close> |
|
3628 |
||
70047
96fe857a7a6f
clarified signature: more explicit operations for corresponding Isar commands;
wenzelm
parents:
69968
diff
changeset
|
3629 |
export_generated_files _ |
69628 | 3630 |
|
69222 | 3631 |
end |