execline-in-execline

From: Profpatsch <mail_at_profpatsch.de>
Date: Wed, 06 Jun 2018 20:44:12 +0200

I wonder if I can write nested execline scripts.

For example: I have a chaining program like `s6-tcpclient`:

```
#!execline
s6-tcpclient example.com 80
sh -c 'echo -en "GET / HTTP/1.0\nHost: example.com\n\n" 1>&7; cat <&6'
```

which I can run inside my execline script, obviously.
What I can also do is:

```
#!execline
define url example.com
s6-tcpclient $url 80
execlineb "
foreground {
  fdmove 1 7 echo -en \"…\"
  fdmove 0 6 cat
}
"
```

which uses an execline script as `prog` for `s6-tcpclient`.
Note the escaping I have to add to the echo string.

What I’m wondering is: since I am already inside the `execlineb`
script reader, why should I have to call it recursively?

I played with `runblock` a bit, since it seemed the most promising,
but couldn’t bring it do do something except throwing a “usage” or
“wrong number of arguments” error.

My idea is to have kind of “magic token” that causes the `execline`
parser to see rest of the file as an execline script, stopping the
tokenizer:

```
#!execline
define url example.com
s6-tcpclient $url 80
execline foreground {
  fdmove 1 7 echo -en "…"
  fdmove 0 6 cat
}
```

Which would be parsed to the standard:

```
define url example.com s6-tcpclient '$url' 80
execlineb -l foreground { fdmove 1 7 echo -en "…" } fdmove 0 6 cat
```

(newline for clarity)
The `-l` (for “line”, maybe `-v` for “verbatim”) instructs `execlineb`
to take the rest of its arguments as execline script (no `args`).

Execline can be used multiple times, since `execlineb` would stop
parsing at the first `execline` it encounters:

```
execline execline echo foo
=>
execlineb -l execline echo foo
=>
execlineb -l echo foo
=>
echo foo
```

Actually, stopping the parse at the first encounted `execline`
is a lie, since blocks have to be handled correctly:

```
foreground {
  execline echo foo
}
echo bar
=>
foreground " execlineb" " -l" " echo" " foo" "" echo bar
```

If I think about it, maybe there doesn’t have to be any
standard token, and just adding `-l` to `execlineb` gives us
all needed functionality already.


  Profpatsch

-- 
Written with Emacs (mu4e) on NixOS.
Q: Why is this email five sentences or less?
A: http://five.sentenc.es/
May take up to five days to read your message. If it’s urgent, call me.
Received on Wed Jun 06 2018 - 18:44:12 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC