nixpulvis / oursh

Your comrade through the perilous world of UNIX.
http://nixpulvis.com/oursh/oursh
MIT License
67 stars 6 forks source link

Equal sign "=" or "if" keyword as part of command argument not accepted - compatibility issue #70

Open cre4ture opened 8 months ago

cre4ture commented 8 months ago

Hi, I'm currently doing experiments with this crate as I try to use it as part of an other application das needs shell-style syntax parser. In general I had a good impression about the features an the quality of oursh. But after I ran some first tests I figured out that oursh currently has a major limitation: It doesn't allow the equal sign "=" or if keyword to be part of a programs argument list.

oursh -c "dd of=output.bin if=/dev/random bs=1 count=10"
unexpected token Equals found at 5-6, expecting one of: "\n", "&", "&&", ";", "<", "<&", "<>", ">", ">&", ">>", ">|", "IO_NUMBER", "WORD", "|", "||"
Parse: "dd of=output.bin if=/dev/random bs=1 count=10"
oursh -c "dd if=/dev/random of=output.bin bs=1 count=10"
unexpected token If found at 3-5, expecting one of: "\n", "&", "&&", ";", "<", "<&", "<>", "=", ">", ">&", ">>", ">|", "IO_NUMBER", "WORD", "|", "||"
Parse: "dd if=/dev/random of=output.bin bs=1 count=10"

Maybe there are even more things that are not allowed. I will probably go with an other crate anyway due to license restrictions. But I wanted you to know about the finding.

nixpulvis commented 7 months ago

It's been a while since I really made progress on this project, but I really appreciate the feedback.

I'm guessing it's broken and will need fixing as part of #27 since I believe the correct grammar only treats leading X=Y assignments specially.

There are other known issues with the grammar, not limited to, but including the cursed dangling else problem (if my memory serves).

I kind of lost steam for this project when I realized I needed a more rock solid foundations for the multi-language embedding, which I never took the time to solve (or is it unsolvable?).


I'm happy to open up the license, @cre4ture do you have any recommendations for a more permissive choice? MIT? Apache? Beerware?

nixpulvis commented 7 months ago

@cre4ture would you be interested in writing a failing test case for this? Otherwise I think I'll add one.

cre4ture commented 7 months ago

I'm also no license expert, nor do I have a dedicated opinion about it. But the project uutils that I currently contribute to is under MIT and I'm adviced to only use similar licenses (MIT, Apache, BSD, ...). Details: url.

I will leave the test case creation to you. oursh is a good project but currently not my focus.

nixpulvis commented 7 months ago

@cre4ture swapped the license over to MIT, but still haven't really had time to start working on this.

Thanks again for the issue though.

nixpulvis commented 6 months ago

Essentially:

FOO=1 BAR=2 echo BAZ=

FOO and BAR should be set, and BAZ= should be a single word printed to STDOUT.

Today, FOO=1 and BAR=2 are Assignment productions (see below):

https://github.com/nixpulvis/oursh/blob/d400267d4e0785805b9c14f9b3d74027ec162095/src/program/posix/mod.lalrpop#L241

However, later we want BAZ= to be a single WORD (including the equal sign). This is tricky because the lexer has no notion of where things are in the grammar. So it currently always treats the equal sign as a special token, not part of a WORD.