nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.39k stars 56 forks source link

Fix handling comments in multiline cmds #225

Closed snejus closed 2 months ago

snejus commented 2 months ago

Fixes #224

snejus commented 2 months ago

Now regarding the test case with multiple comments - it actually evaluates to an invalid command if it's read literally (a comment between two flags does not make any sense).

Do you see any value in supporting this kind of thing? We could potentially pre-parse the command and ignore all comments altogether.

nat-n commented 2 months ago

Now regarding the test case with multiple comments - it actually evaluates to an invalid command if it's read literally (a comment between two flags does not make any sense).

Do you see any value in supporting this kind of thing? We could potentially pre-parse the command and ignore all comments altogether.

Your assessment is correct. Allowing a cmd to be split over multiple lines (with escaping the line break) with comments on multiple lines is a little bit weird... but harmless and IMO potentially a nice thing to be able to do.

I think the root cause of the issue here is that although I made the AST implementation faithful to a subset of bash, when actually used in the cmd task it's configured to only treat ; as a line terminator (not line breaks) and to later ignore lines with only whitespace or comments. However comments at the end of lines still end up terminating that line.

So to resolve this I just pushed a tweak to the cmd AST that allows tracking on the Line object how it was terminated, so that we can implicitly merge lines that were only terminated with a comment. WDYT?

nat-n commented 2 months ago

This looks good to me now. Thanks for working on it @snejus

snejus commented 2 months ago

Amazing, thanks for finishing this up!