2021-01-30 23:37:53 +00:00
|
|
|
module haskell
|
2021-02-01 01:46:31 +00:00
|
|
|
imports libstrategolib signatures/- util
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
signature
|
|
|
|
constructors
|
|
|
|
TopLevel: Ex -> Ex
|
|
|
|
|
|
|
|
rules
|
2021-02-01 01:46:31 +00:00
|
|
|
/* Approach: Generate code from the bottom up.
|
|
|
|
At every node, we create a pair of the implementation and
|
|
|
|
necessary preamble of IO actions.
|
|
|
|
We concatenate preambles as we go up.
|
|
|
|
Finally, at the toplevel we emit the preamble before returning the
|
|
|
|
final value.
|
|
|
|
*/
|
|
|
|
|
|
|
|
hs: TopLevel((c,p)) -> $[import System.IO
|
2021-01-30 23:37:53 +00:00
|
|
|
data IOStream = StdIO
|
|
|
|
|
2021-02-06 04:55:17 +00:00
|
|
|
gets :: Show b => a -> b -> IO a
|
2021-02-06 04:13:18 +00:00
|
|
|
gets s d = do
|
2021-01-30 23:37:53 +00:00
|
|
|
putStr(show d)
|
2021-02-06 04:55:17 +00:00
|
|
|
return s
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
main = do
|
2021-02-01 01:46:31 +00:00
|
|
|
[p]return [c]]
|
2021-01-30 23:37:53 +00:00
|
|
|
|
2021-02-06 04:55:17 +00:00
|
|
|
hs: Stream() -> ("StdIO", "")
|
2021-02-01 01:46:31 +00:00
|
|
|
hs: Int(x) -> (x, "")
|
2021-02-06 04:13:18 +00:00
|
|
|
hs: Sum( (c, p), (d, q)) -> ($[([c] + [d])], <conc-strings>(p,q))
|
|
|
|
hs: Gets((c, p), (d, q)) -> <hsget>(c,d,<conc-strings>(p,q),<newname>"fosgt")
|
2021-02-01 01:46:31 +00:00
|
|
|
|
2021-02-06 04:13:18 +00:00
|
|
|
hsget: (s, x, p, v) -> (v, <concat-strings>[p, $[[v] <- [s] `gets` [x]],
|
|
|
|
"\n"])
|
2021-02-01 01:46:31 +00:00
|
|
|
|
2021-02-06 04:13:18 +00:00
|
|
|
hs: To( (c, p), (d, q)) -> <hsto>(c,d,<conc-strings>(p,q),<newname>"fosto")
|
|
|
|
|
|
|
|
hsto: (x, s, p, v) -> (v, <concat-strings>[p, $[let [v] = [x]], "\n",
|
|
|
|
$[[s] `gets` [v]], "\n"])
|
|
|
|
|
|
|
|
hs: Sequence(l) -> (<last; Fst>l, <map(Snd); concat-strings>l)
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
strategies
|
2021-02-01 08:29:00 +00:00
|
|
|
|
2021-02-06 04:13:18 +00:00
|
|
|
haskell = bottomup(try(hs))
|
2021-01-30 23:37:53 +00:00
|
|
|
|
|
|
|
// Interface haskell code generation with editor services and file system
|
|
|
|
to-haskell: (selected, _, _, path, project-path) -> (filename, result)
|
|
|
|
with filename := <guarantee-extension(|"hs")> path
|
|
|
|
; result := <haskell> selected
|