Really Weird Shell - the structural regular expression shell - Programming On Unix
tudurom
Here it is!

For the moment it can only execute piped commands, it doesn't even have variables or string substitution, and the only builtin is cd. The main innovation, though, is a special kind of pipe, called The Pizza.

It looks like this:

Code:
dmesg |> ,x/[lL]inux/ c/GNU+Linux/ |> ,p

What the above code is doing is changing all occurrences of "linux" or "Linux" to "GNU+Linux", then printing everything.

One complex example is the following:

Code:
cat text |> ,x/Ben|Dave/ {
    g/Ben/ c/Dave/
    g/Dave/ c/Ben/
} |> ,p | lolcat

This one changes all occurrences of "Dave" to "Ben" and "Ben" to "Dave" in parallel, then prints the whole file in rainbow colors!

This should become more useful after implementing variables, variable substitution and shell substitution. Stay tuned, and share your impressions!

To run it, make sure you have rustc and cargo installed, then run

Code:
cargo run
jkl
So, basically, you implemented the first version of UNIX pipes again?
evbo
A fellow sourcehut user, good man :)

As a Perl diehard, I say the more regular expression processing the better!
tudurom
Well, that was the idea. The shell is about dealing with text output from various programs that are connected through pipes. Why not provide the tools to manipulate the text output too?

It also works as an AWK alternative. If you don't put anything before the pizza operator, it will read from stdin.

Code:
BEGIN { /* code */ }
/a regex/ { /* more code */ }
END { /* code */ }

Turns into this:

Code:
# begin
|> ,x/a regex/ { body }
# end
tudurom
jkl Wrote:So, basically, you implemented the first version of UNIX pipes again?

The stuctural regular expression stuff is implemented too. The examples I gave actually work in the shell.
jkl
That's really nice. :-)
z3bra
Why did you choose to implement it as a shell rather than an interpreter like awk, or sed?
tudurom
z3bra Wrote:Why did you choose to implement it as a shell rather than an interpreter like awk, or sed?

As far as I know, there is no awk or sed using structural regular expressions, like sam does. My first intention was to build one. Then, I realised that it should be a full blown shell, because a shell's job is mainly to process output from different programs, which is usually text in the unix world. I feel that a shell without powerful text processing, or a text processor without powerful shell functionality, is incomplete. Both sh and awk are scripting languages, with variables, control structures, and both operate around string values. Why separate them?

Thus, I created (or I am in the process of creating) a complete shell. You can use it as a shell, you can use it as a text filter, you can use it for both. Text and processes are first class citizens.
z3bra
Quote:shell's job is mainly to process output from different programs

I disagree with that. The shell's job is to handle IPC, and that's it. Text processing is done by the processes themselves, the shell only connects outputs to the next process input.
Otherwise, you're creating a full blown text processor, that happens to have a way to start processes.

I love the structural expression approach, but I think you should focus on that rather than making a complete shell. That wouldn't make much difference:

Code:
dmesg |> ,x/[lL]inux/ c/GNU+Linux/ |> ,p

would then be (reusing sed's flags):

Code:
dmesg | se -e ',x/[lL]inux/ c/GNU+Linux/'
tudurom
z3bra Wrote:The shell's job is to handle IPC, and that's it. Text processing is done by the processes themselves, the shell only connects outputs to the next process input.

In theory, yes. In practice, virtually all shell scripts deal with text processing and filtering by calling grep, sed, awk and the others. These text processing programs are pointless without a shell to call them, and a shell is pointless without text processing programs or routines to handle the output of the other programs it is calling.

I am making an awk-like program. Shell pipes are just a small convenience, they don't add too much complexity.

The challenge that I'm facing is to make it work on a stream of text. Sed and awk operate on lines, structural regular expressions operate on characters or the whole text.




Members  |  Stats  |  Night Mode