New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shell substitutions with parentheses fail #118
Comments
@dirtyvagabond @aboytsov @egamble I was working on this bug a bit and came across a big problem in the parser. The monads in the parser are backtracking monads so they are not supposed to have side effects, however the monad that handles any shell substitution (command-sub) actually shells out right in the monad. When I was testing a fix to this bug, I noticed that it was shelling out twice because of the backtracking. Unfortunately, being able to do command-line substitution right in the parser is critical for defining variables and in-line shell commands. So this bug revealed a pretty deep problem. This may be the impetus we need to separate the lexer from the parser. |
@myronahn oh man, this sounds like a nice find. so... are you volunteering to do some hard core lexer/parser development? |
I agree that a proper parser/lexer separation is the right way to go about fixing it. But in the meantime, we can easily make sure every shell substitution is executed once by maintaining a global hashmap that stores the result of each run (and caches it for backtracking). Thoughts? |
I use memoization with fnparse in the parser for my language Timeless. It On Tue, Jan 21, 2014 at 11:53 AM, Artem Boytsov notifications@github.comwrote:
|
Good idea - hash map/memoization sounds good except for a couple of things:
However, these are probably very rare cases that can be ignored for now until the full parser/lexer separation. I might be able to detect when this happens and error out - but chances are, it would error out anyway. We'll probably have to memoize the line number (or something) with the shell command as well since it could be that the user actually wants to run the same shell command multiple times in different parts of the workflow. I'll play around with this to see if I can come up with a quick fix. |
Also memoize the calls to shell (along with file line/column) Clear memoize map when new workflow is run
@myronahn is this close-able? |
@dirtyvagabond Well the immediate issue is hack-fixed but I wouldn't call it a long-term fix. The deeper issue I brought up is still an issue. |
@amalloy may find this interesting, we recently talked about the parser/lexer separation considerations |
@myronahn I'm curious what sort of input causes the parser to backtrack enough to execute a shell expansion twice. I don't see any rules that would obviously cause this sort of issue. |
Anyway, we should be able to parse these just as well as bash does, and support |
@amalloy It's been a while since I've worked on this, but if I'm not mistaken, it was the original test case at the beginning of this bug that caused the backtrack (and I believe I put it in the regression test suite as well). |
We've been able to handle shell expansions containing |
The example below fails due to the closing parenthesis in the command, as the parser will consider the first closing parenthesis it finds to be the end of the shell substitution statement.
The text was updated successfully, but these errors were encountered: