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