feat: sequencing of expressions with newline to same indent (#11)
All checks were successful
continuous-integration/drone/push Build is passing

feat: sequencing of expressions with newline to same indent

  Also revised README to reflect greater emphasis on streams.
  Haskell code generation unsurprisingly required a fairly significant
  rework.

  Resolves #3.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: #11
Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net>
Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
This commit is contained in:
Glen Whitney 2021-02-06 05:11:41 +00:00
parent c4d3f66c51
commit 991976d3a8
10 changed files with 131 additions and 89 deletions

View file

@ -17,33 +17,32 @@ rules
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
gets :: Show b => a -> b -> IO a
gets s d = do
putStr(show d)
return temp
return s
main = do
[p]return [c]]
hs: Stdio() -> ("stdio", "")
hs: Stream() -> ("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")
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")
hsenter: (x, s, p, v) -> (v, <concat-strings>[$[[p]let [v] = [x]], "\n",
$[[s] `receives` [v]], "\n"])
hsget: (s, x, p, v) -> (v, <concat-strings>[p, $[[v] <- [s] `gets` [x]],
"\n"])
hslist: x -> (<map(Fst); join(|", "); brack>x, <map(Snd); concat-strings>x)
brack: x -> $<[<x>]>
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 <+ hslist))
haskell = bottomup(try(hs))
// Interface haskell code generation with editor services and file system
to-haskell: (selected, _, _, path, project-path) -> (filename, result)

View file

@ -7,25 +7,24 @@ signature
rules
js: TopLevel(x) -> $[const Stdio = {
receives: v => { process.stdout.write(String(v)); return Stdio; },
gets: v => { process.stdout.write(String(v)); return Stdio; },
}
function forwards(data, strm) {
strm.receives(data);
function to(data, strm) {
strm.gets(data);
return data;
}
[x]]
js: Stdio() -> $[Stdio]
js: Stream() -> $[Stdio]
js: Int(x) -> x
js: Sum(x) -> $[[x].reduce((v,w) => v+w)]
js: Receives(x, y) -> $[[x].receives([y])]
js: Enters(x, y) -> $[forwards([x],[y])]
jslist: x -> $<[<<join(|", ")>x>]>
js: Sum(x,y) -> $[[x] + [y]]
js: Gets(x, y) -> $[[x].gets([y])]
js: To(x, y) -> $[to([x],[y])]
js: Sequence(l) -> <join(|";\n")>l
strategies
javascript = bottomup(try(js <+ jslist))
javascript = bottomup(try(js))
// Interface javascript code generation with editor services and file system
to-javascript: (selected, _, _, path, project-path) -> (filename, result)

View file

@ -9,26 +9,25 @@ rules
py: TopLevel(x) -> $[import sys
class StdioC:
def receives(self, v):
def gets(self, v):
print(v, file=sys.stdout, end='')
return self
def forwards(data,strm):
strm.receives(data)
def to(data,strm):
strm.gets(data)
return data
Stdio = StdioC()
[x]]
py: Stdio() -> $[Stdio]
py: Int(x) -> x
py: Sum(x) -> $[sum([x])]
py: Receives(x, y) -> $[[x].receives([y])]
py: Enters(x, y) -> $[forwards([x],[y])]
pylist: x -> $<[<<join(|", ")>x>]>
py: Stream() -> $[Stdio]
py: Int(x) -> x
py: Sum(x,y) -> $[[x] + [y]]
py: Gets(x, y) -> $[[x].gets([y])]
py: To(x, y) -> $[to([x],[y])]
py: Sequence(l) -> <join(|"\n")>l
strategies
python = bottomup(try(py <+ pylist))
python = bottomup(try(py))
// Interface python code generation with editor services and file system
to-python: (selected, _, _, path, project-path) -> (filename, result)

View file

@ -3,7 +3,7 @@ imports libstrategolib
rules
join(|infix) : [] -> ""
join(|infix) : [x | xs] -> $[[x][<prejoin(|infix)>xs]]
join(|infix) : [x | xs] -> <conc-strings>(x, <prejoin(|infix)>xs)
prejoin(|infix) : [] -> ""
prejoin(|infix) : [x | xs] -> $[[infix][x][<prejoin(|infix)>xs]]
prejoin(|infix) : [x | xs] -> <concat-strings>[infix,x,<prejoin(|infix)>xs]