grncdr / js-shell-parse

parse bash, with javascript (UNMAINTAINED)
MIT License
90 stars 13 forks source link

Intentional inconsistency? #8

Closed wilmoore closed 8 years ago

wilmoore commented 8 years ago

I wasn't sure if this was intentional; however, I did notice some inconsistency when I have a variable assignment that includes an in-line comment:

actual
parse('DOMAIN="example.com" # with a comment')[0].type
// => 'command'
expected
parse('DOMAIN="example.com" # with a comment')[0].type
// => 'variableAssignment'

On the other hand, I get exactly what I'm expecting if I remove the comment:

parse('DOMAIN="example.com")[0].type
// => 'variableAssignment'

Not a huge deal as I can sort of work around this; however, I thought I'd mention it in case I was missing something.

piranna commented 8 years ago

I also get command when assigning the variable to nothing:

DOMAIN=
grncdr commented 8 years ago

This isn't exactly intentional, the issue is that comments aren't parsed at all right now.

@dthree this is one of the areas where peg parsing is somewhat awkward. Parsing comments cleanly would require sticking the comment rule in the grammar everywhere a comment might appear (which is a lot of places). You could instead preprocess the input to remove all input after a # on each line, but then your preprocessor has to be aware of quotes & heredocs.

piranna commented 8 years ago

@dthree this is one of the areas where peg parsing is somewhat awkward. Parsing comments cleanly would require sticking the comment rule in the grammar everywhere a comment might appear (which is a lot of places).

Not a lot of places, just before newlines... ;-)

dthree commented 8 years ago

@grncdr gotcha