Literals are read by a grammar, not elaborated

(std run) declares its pipelines with def/grammar, and the compiler checks
a pipeline literal against it where it is written.

🤖 Generated with [ECA](https://eca.dev)

Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
Linus Björnstam 2026-10-22 16:36:09 +02:00
parent 4952b06c2c
commit 47d6ab62d0

View file

@ -68,7 +68,7 @@ This sums every line and every char read from stdin. When the port is closed, th
0)
}
Bjolang does type elaboration on literals. That means that if a function takes a (List CmdStuff) argument and you pass it '(pipe (cat "notes.txt") ,shout (grep "bomb")) it gets elaborated into (list (CmdPipe (Cmd 'cat (CmdString "notes.txt") (CmdFilter shout) (Cmd 'grep "bomb")))). For the type elaboration in (std run) this is not quite typesafe, even though it catches most of the issues, but with some care you can make type safe DSLs that can be typechecked.
Bjolang can read a literal with a grammar. @code{def/grammar} declares the syntax of the literals and the types they become, and (std run) declares one for pipelines, called @code{Form}. @code{run/string} takes a @code{Form}, so @code{'(pipe (cat "notes.txt") ,shout (grep "BOMB"))} is read as @code{(FPipe (list (FCmd (list (WSym 'cat) (WStr "notes.txt"))) (FFilter shout) (FCmd (list (WSym 'grep) (WStr "BOMB")))))}. The compiler checks the literal against the grammar where it is written, so a pipeline that does not fit is a compile error, and @code{,shout} has to be a filter. You can declare grammars for DSLs of your own the same way.
The example below pipes the output (as in a commandline pipe) from a file through a bjolang function that upcases it and then greps it for "bomb". The shout function is completely async, and suspends if it cannot read from @code{in} or write to @code{out}.