fostr/trans/haskell.str
Glen Whitney 5d81316ce2 feat: sequencing of expressions with newline to same indent
Also revised README to reflect greater emphasis on streams.

  Resolves #3.
2021-02-05 20:13:18 -08:00

55 lines
1.5 KiB
Plaintext

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
gets :: Show b => IO a -> b -> IO a
gets s d = do
temp <- s
putStr(show d)
return temp
main = do
[p]return [c]]
hs: Stream() -> ("stdio", "")
hs: Int(x) -> (x, "")
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")
hsget: (s, x, p, v) -> (v, <concat-strings>[p, $[[v] <- [s] `gets` [x]],
"\n"])
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)
strategies
haskell = bottomup(try(hs))
// 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