diff --git a/syntax/fostr.sdf3 b/syntax/fostr.sdf3 index 4dc4569..c346eee 100644 --- a/syntax/fostr.sdf3 +++ b/syntax/fostr.sdf3 @@ -42,14 +42,18 @@ context-free syntax Ex.Stream = Ex.Sum = < + > {left} Ex.Gets = [[Ex] << [Ex]] {left} + Ex.DefGets = [<<< [Ex]] Ex.To = [[Ex] >> [Ex]] {left} + Ex.DefTo = [[Ex] >>>] Ex = <()> {bracket} context-free priorities Ex.To + > Ex.DefTo > Ex.Sum + > Ex.DefGets > Ex.Gets, // prevent cycle: no singletons diff --git a/tests/basic.spt b/tests/basic.spt index e1cadf9..494cafb 100644 --- a/tests/basic.spt +++ b/tests/basic.spt @@ -231,3 +231,15 @@ run desugar-fostr to TopLevel(Sequence([ Terminate(Sum(Int("11"), To(Int("12"), Stream()))), To(To(Int("13"), Stream()), Stream()) ])) + +test emit_several_default [[ +<<< 1 + 2; 3 >>> +(4 + 5) >>> >> stream; stream << 6; +<<< 7 << 75 +<<< 8 + + (9+10); +11 + 12 >>>; 13 >>> + >>> +]] parse succeeds +/** writes +3399677527121313*/ diff --git a/tests/emit_several.fos b/tests/emit_several.fos index c806fd3..e7cbac5 100644 --- a/tests/emit_several.fos +++ b/tests/emit_several.fos @@ -1,7 +1,7 @@ -stream << 1 + 2; 3 >> stream -(4 + 5) >> stream; stream << 6; -stream << 7 -stream << 8 +<<< 1 + 2; 3 >>> +(4 + 5) >>> >> stream; stream << 6; +<<< 7 << 75 +<<< 8 + (9+10); -11 + 12 >> stream; 13 >> stream - >> stream +11 + 12 >>>; 13 >>> + >>> diff --git a/tests/hw.fos b/tests/hw.fos index 90fc0d4..19eade4 100644 --- a/tests/hw.fos +++ b/tests/hw.fos @@ -1 +1 @@ -stream << 'Hello, world!' +<<< 'Hello, world!' diff --git a/trans/desugar.str b/trans/desugar.str index bfb4ecf..7276f38 100644 --- a/trans/desugar.str +++ b/trans/desugar.str @@ -15,7 +15,9 @@ rules seqFlatten: Sequence(l) -> Sequence() <+ ![])>l) + defStream: DefGets(x) -> Gets(Stream(), x) + defStream: DefTo(x) -> To(x, Stream()) + strategies - desugar-fostr = bottomup(try(deISe <+ seqFlatten)) - \ No newline at end of file + desugar-fostr = bottomup(try(defStream <+ deISe <+ seqFlatten)) diff --git a/trans/haskell.str b/trans/haskell.str index 560b29c..fc75a7b 100644 --- a/trans/haskell.str +++ b/trans/haskell.str @@ -19,7 +19,8 @@ rules returning the final value. */ - hs: (_, TopLevel(val)) -> $[import System.IO + hs: (_, TopLevel(val)) -> $[-- Preamble from fostr + import System.IO data IOStream = StdIO gets :: Show b => a -> b -> IO a diff --git a/trans/javascript.str b/trans/javascript.str index 645cc63..1fd2900 100644 --- a/trans/javascript.str +++ b/trans/javascript.str @@ -2,13 +2,16 @@ module javascript imports libstrategolib signatures/- util rules - js: TopLevel(x) -> $[const Stdio = { + js: TopLevel(x) -> $[// Fostr preamble + const Stdio = { gets: v => { process.stdout.write(String(v)); return Stdio; }, } function to(data, strm) { strm.gets(data); return data; } + // End of preamble + [x]] js: Stream() -> $[Stdio] diff --git a/trans/python.str b/trans/python.str index 7aa4e06..068f05a 100644 --- a/trans/python.str +++ b/trans/python.str @@ -2,7 +2,8 @@ module python imports libstrategolib signatures/- util rules - py: TopLevel(x) -> $[import sys + py: TopLevel(x) -> $[## Fostr preamble + import sys class StdioC: def gets(self, v): print(v, file=sys.stdout, end='') @@ -11,6 +12,8 @@ rules strm.gets(data) return data Stdio = StdioC() + ## End of preamble + [x]] py: Stream() -> $[Stdio]