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