diff --git a/bin/extract_tests.xsh b/bin/extract_tests.xsh index 422acb1..1d8c59f 100644 --- a/bin/extract_tests.xsh +++ b/bin/extract_tests.xsh @@ -13,9 +13,6 @@ DESTINATION = 'tests/extracted' # Extension for extracted files: EXT = 'fos' -# Extension for desired input: -INP = 'in' - # Extension for expectations: EXP = 'expect' @@ -37,11 +34,6 @@ for path in TEST_LIST: expath = destdir / f"{name}.{EXT}" expath.write_text(example) echo Wrote @(expath) - im = re.search(r'/\*\*\s+accepts.*?\n([\s\S]*?)\*\*/', details[em.end():]) - if im: - ipath = destdir / f"{name}.{INP}" - ipath.write_text(im[1]) - echo " ...and" @(ipath) xm = re.search(r'/\*\*\s+writes.*?\n([\s\S]*?)\*\*/', details[em.end():]) if xm: xpath = destdir / f"{name}.{EXP}" diff --git a/bin/run_tests b/bin/run_tests index da49485..90ccaa7 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -9,14 +9,8 @@ diffed=0 for dir in tests/extracted/*; do for file in $dir/*.$ext; do ((total++)) - if [[ -f ${file%.*}.in ]]; then - cat ${file%.*}.in | $command $file > $file.out - result=$? - else - $command $file > $file.out - result=$? - fi - if [[ $result -ne 0 ]]; then + $command $file > $file.out + if [[ $? -ne 0 ]]; then echo ERROR: $command $file failed. ((failed++)) else diff --git a/mkdocs.yml b/mkdocs.yml index c2d5242..e316a98 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -9,7 +9,7 @@ plugins: - search - semiliterate: ignore_folders: [target, lib] - exclude_extensions: ['.o', '.hi', '.cmi', '.cmo'] + exclude_extensions: ['.o', '.hi'] extract_standard_markdown: terminate: theme: diff --git a/syntax/fostr.sdf3 b/syntax/fostr.sdf3 index f782466..8624b58 100644 --- a/syntax/fostr.sdf3 +++ b/syntax/fostr.sdf3 @@ -42,13 +42,10 @@ context-free syntax Ex.EscString = STRING Ex.Stream = Ex.Sum = < + > {left} - Ex.Concat = < ++ > {left} Ex.Gets = [[Ex] << [Ex]] {left} Ex.DefGets = [<<< [Ex]] Ex.To = [[Ex] >> [Ex]] {left} Ex.DefTo = [[Ex] >>>] - Ex.Emits = <!> - Ex.DefEmits = Ex = <()> {bracket} @@ -56,7 +53,7 @@ context-free priorities Ex.To > Ex.DefTo - > {Ex.Sum Ex.Concat} + > Ex.Sum > Ex.DefGets > Ex.Gets, diff --git a/tests/basic.spt b/tests/basic.spt index 3d5a4a6..a5e98c0 100644 --- a/tests/basic.spt +++ b/tests/basic.spt @@ -293,38 +293,4 @@ test emit_several_default [[ >>> ]] parse succeeds /** writes -3399677527121313**/ - -/** md -### Streams are bidirectional - -So far we have only sent items to a stream. But we can extract them from -streams as well, with the `!` postfix operator. `!!` all by itself abbreviates -`stream!`, i.e., extraction from the standard stream. For example, - -```fostr -**/ - -/** md */ test custom_hw [[ -<<< "What is your name?\n" -<<< 'Hello, ' ++ !! -]] /* **/ -parse to TopLevel(Sequence([ - DefGets(EscString("\"What is your name?\n\"")), - DefGets(Concat(LitString("'Hello, '"),DefEmits())) -])) -/** accepts -Kilroy -**/ -/** writes -What is your name? -Hello, Kilroy -**/ - -/** md -``` - -queries users for their name and then writes a customized greeting. It also -illustrates the use of `++` for string concatenation, as opposed to `+` for -(numerical) addition. -**/ +3399677527121313*/ diff --git a/trans/desugar.str b/trans/desugar.str index b22ebd8..7276f38 100644 --- a/trans/desugar.str +++ b/trans/desugar.str @@ -17,7 +17,6 @@ rules defStream: DefGets(x) -> Gets(Stream(), x) defStream: DefTo(x) -> To(x, Stream()) - defStream: DefEmits() -> Emits(Stream()) strategies diff --git a/trans/haskell.str b/trans/haskell.str index 0e0eb15..0b08716 100644 --- a/trans/haskell.str +++ b/trans/haskell.str @@ -23,7 +23,6 @@ rules import System.IO data IOStream = StdIO - -- Danger: These currently assume the stream is StdIO gets :: Show b => a -> b -> IO a gets s d = do putStr(show d) @@ -34,10 +33,6 @@ rules putStr(d) return s - emit s = do - l <- getLine - return (l ++ "\n") - main = do [()]return [val]] @@ -46,7 +41,6 @@ rules hs: (_, LitString(x)) -> x hs: (_, EscString(x)) -> x hs: (_, Sum(x, y)) -> $[([x] + [y])] - hs: (_, Concat(x, y)) -> $[([x] ++ [y])] hs: (Gets(_, xn), Gets(s, x)) -> v with v := "_fostr_get" @@ -58,10 +52,6 @@ rules hs_gets: (s, xn, x ) -> $[[s] [xn] [x]] hs_getOp = get-type; (?STRING() < !"`getsStr`" + !"`gets`") - hs: (_, Emits(s)) -> v - with v := "_fostr_emitted" - ; [$[[v] <- emit [s]]] - hs: (_, Terminate(x)) -> $[[x];;] hs: (_, Sequence(l)) -> l /* One drawback of using paramorphism is we have to handle lists diff --git a/trans/javascript.str b/trans/javascript.str index 9b596ad..3a847e2 100644 --- a/trans/javascript.str +++ b/trans/javascript.str @@ -3,41 +3,24 @@ imports libstrategolib signatures/- util rules js: TopLevel(x) -> $[// Fostr preamble - const _fostr_readline = require('readline'); - const _fostr_events = require('events'); - const _fostr_rl = _fostr_readline.createInterface({input: process.stdin}); const Stdio = { - gets: v => { process.stdout.write(String(v)); return Stdio; }, - emit: async () => { - const [line] = await _fostr_events.once(_fostr_rl, 'line'); - return line + "\n"; } + gets: v => { process.stdout.write(String(v)); return Stdio; }, } function to(data, strm) { strm.gets(data); return data; } - - const _fostr_body = async () => { // End of preamble - [x] - - // Fostr coda - _fostr_rl.close() - } - _fostr_body(); - ] - with line := "[line]" + [x]] js: Stream() -> $[Stdio] js: Int(x) -> x js: LitString(x) -> x js: EscString(x) -> x - js: Sum(x, y) -> $[[x] + [y]] - js: Concat(x, y) -> $[[x] + [y]] + js: Sum(x,y) -> $[[x] + [y]] js: Gets(x, y) -> $[[x].gets([y])] js: To(x, y) -> $[to([x],[y])] - js: Emits(x) -> $[(await [x].emit())] js: Terminate(x) -> x js: Sequence(l) -> l diff --git a/trans/ocaml.str b/trans/ocaml.str index 049dbf4..11fcdca 100644 --- a/trans/ocaml.str +++ b/trans/ocaml.str @@ -12,10 +12,9 @@ imports libstrategolib signatures/- util signature/TYPE analysis rules ml: (_, TopLevel(x)) -> $[(* fostr preamble *) - type stream = { getS: string -> stream; emitS: unit -> string } + type stream = { getS: string -> stream } let rec stdio = { - getS = (fun s -> print_string s; stdio); - emitS = (fun () -> (read_line ()) ^ "\n"); + getS = (fun s -> print_string s; stdio) };; (* End of preamble *) @@ -25,15 +24,11 @@ rules ml: (_, Int(x)) -> x ml: (_, LitString(x)) -> $[{|[x]|}] ml: (_, EscString(x)) -> x - ml: (_, Sum(x, y)) -> $[[x] + [y]] - ml: (_, Concat(x, y)) -> $[[x] ^ [y]] - + ml: (_, Sum(x,y)) -> $[[x] + [y]] ml: (Gets(_,yn), Gets(x, y)) -> $[([x]).getS ([(yn,y)])] ml: (To(xn,_), To(x, y)) -> $[let _fto = ([x]) in (ignore (([y]).getS ([(xn,"_fto")])); _fto)] - ml: (_, Emits(s)) -> $[[s].emitS ()] - ml: (_, Terminate(x)) -> x ml: (_, Sequence(l)) -> l diff --git a/trans/python.str b/trans/python.str index f42b1cb..6449417 100644 --- a/trans/python.str +++ b/trans/python.str @@ -8,8 +8,6 @@ rules def gets(self, v): print(v, file=sys.stdout, end='') return self - def emit(self): - return input() + "\n" # Python inconsistently strips when using input def to(data,strm): strm.gets(data) return data @@ -23,10 +21,8 @@ rules py: LitString(x) -> $[r[x]] py: EscString(x) -> x py: Sum(x,y) -> $[[x] + [y]] - py: Concat(x,y) -> $[[x] + [y]] py: Gets(x, y) -> $[[x].gets([y])] py: To(x, y) -> $[to([x],[y])] - py: Emits(x) -> $[[x].emit()] py: Terminate(x) -> $[[x];] py: Sequence(l) -> l diff --git a/trans/statics.stx b/trans/statics.stx index ce99bf7..340a1df 100644 --- a/trans/statics.stx +++ b/trans/statics.stx @@ -222,13 +222,6 @@ This pattern lets us specify error messages. type_Ex(e2) == STREAM() | error $[Items may only be sent to Streams.]@e2. /* **/ - ty_Ex(Concat(e1, e2)) = STRING() :- - type_Ex(e1) == STRING() | error $[Expression [e1] not String in concat.]@e1, - type_Ex(e2) == STRING() | error $[Expression [e2] not String in concat.]@e2. - - ty_Ex(Emits(e)) = STRING() :- // At the moment, only stream is stdio - type_Ex(e) == STREAM() | error $[Only Streams may emit items.]@e. - /** md ```