feat WIP: checkpoint initial efforts on stream extraction

Adds ! operator and !! expression, with Python code gen and
  an item in tour.
  Still needs: other languages, check generated docs, and addition
  of standard input to test scheme.
This commit is contained in:
Glen Whitney 2021-03-01 20:51:12 -08:00
parent cc89ad1e93
commit 7c69b82484
5 changed files with 49 additions and 1 deletions

View file

@ -294,3 +294,36 @@ 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
illustratesthe use of `++` for string concatenation, as opposed to `+` for
(numerical) addition.
**/