fostr/trans/haskell.str

52 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

module haskell
imports libstrategolib signatures/- util
signature
constructors
TopLevel: Ex -> Ex
rules
/* 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
data IOStream = StdIO
stdio :: IO IOStream
stdio = return StdIO
receives :: Show b => IO a -> b -> IO a
receives s d = do
temp <- s
putStr(show d)
return temp
main = do
[p]return [c]]
hs: Stdio() -> ("stdio", "")
hs: Int(x) -> (x, "")
hs: Sum((c,p)) -> ($[sum [c]], p)
hs: Receives((c, p), (d, s)) -> ($[[c] `receives` [d]], <conc-strings>(p,s))
hs: Enters((c, p), (d, s)) -> <hsenter>(c,d,<conc-strings>(p,s),<newname>"fos")
hsenter: (x, s, p, v) -> (v, <concat-strings>[$[[p]let [v] = [x]], "\n",
$[[s] `receives` [v]], "\n"])
hslist: x -> (<map(Fst); join(|", "); brack>x, <map(Snd); concat-strings>x)
brack: x -> $<[<x>]>
strategies
haskell = bottomup(try(hs <+ hslist))
// 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