Replies: 2 comments 2 replies
-
Can you clarify what suggestion you are making (if any)? Or are you just curious whether we/@mvdan agree(s) that the parser and the interpreter being separate makes the latter harder to implement? |
Beta Was this translation helpful? Give feedback.
-
I should give a bit of historical context. The first use case was the formatter, so I only needed a static parser and printer. The interpreter was an extension of the project that started about two years later. You're right in saying that the project could be more sh/bash compliant if the parser was tightly coupled to an interpreter. You cite one case where that can be an advantage for real scripts - never parsing some lines. There are others, such as being able to parse array expressions differently depending on the interpreter state; see https://github.com/mvdan/sh#caveats. I still believe that having an entirely static parser is a good thing, and something we should keep around. But for those users who mainly use the interpreter and want close compatibility with sh/bash, I'm certainly open to ideas to improve compatibility. If all we want for now is to just be able to parse one line at a time when interpreting a script, I think the current parser should already support that. If we want more, such as interpreter-aware parsing of array expressions, that would likely require new API. |
Beta Was this translation helpful? Give feedback.
-
My ideas are not totally clear yet, so let me use this post as a way to unroll them.
Bash is a single-pass language where the parser and interpreter are inter-mingled. This allows doing crazy things like embed binary data into a script:
One of the things I noticed in this project's design, is that the parser and interpreter are separate. This makes sense because the project is also a code formatting tool, it's useful to have a separate parser. The formatted should probably not deal with crazy scripts like above.
I have a sense that this makes the
interp
package more difficult to implement. One indication is that there are more instances of the parser being spawned off instead of re-using the same one. It's a thought I had while working on #650.So it's just a thought. Maybe more clarity will appear with more conversation.
Beta Was this translation helpful? Give feedback.
All reactions