a word beginning with the third character of the histchars parameter (‘#’ by default) causes that word and all the following characters up to a newline to be ignored.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Bash is like zsh, it doesn't specify a priority for the line continuation vs comment, but POSIX explicitly specifies that the line continuation is removed before the tokens are recognised, and therefore before the comment is recognised.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's not a huge bug but it can be fixed after checking and verifying bash and zsh behaviour.
I'm busy these days so anyone out there please feel free to tackle it.
I can confirm that bash handles comment lines in its own function, thus bypassing line continuation processing. I took a look at bash-5.0 sources, in parse.y[3268], in read_token (command), if the '#' char is found, then it performs discard_until ('\n'); which is a simple function that zaps everything until the newline.
Ray, there are many dusty corners in bash parsing. Thankfully, this is a low-hanging fruit that should not be too hard to fix -- one would probably take more time checking bash and zsh to verify correct behaviour. The bash parse.y is not an elegant bit of code, speaking as someone who had worked on bash highlighting for Scintilla. Heh.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"then it performs discard_until ('\n'); which is a simple function that zaps everything until the newline."
Perhaps it is in the shell's favor that this way of parsing is surely the simplest. As you show, it's not exactly complicated!
I sure appreciate your 'get it done' attitude, thanks, it makes reporting these things worth the trouble. So often the devs of various projects are more interested in the latest wiz-bang feature than in tidying up little bugs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
f the current character is a '#', it and all subsequent characters up to, but excluding, the next <newline> shall be discarded as a comment. The <newline> that ends the line is not considered part of the comment.
I think we can remove line continuation handling for comment line unless there is a shell that supports it.
Current code also has other bug (fourth line is also colored as comment):
#backslash1\echo1#backslash2\\echo2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A simpler example is:
which displays
not a commentwhen run with zsh or bash.There are separate elements in the zsh documentation for continuation and comments with no information on priority.
http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Quoting :
http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Comments :
Diff:
Bash is like zsh, it doesn't specify a priority for the line continuation vs comment, but POSIX explicitly specifies that the line continuation is removed before the tokens are recognised, and therefore before the comment is recognised.
Well the fact remains that all the shells I've tried do it the same way as zsh and bash. Shouldn't it work as the shell actually is?
It's not a huge bug but it can be fixed after checking and verifying bash and zsh behaviour.
I'm busy these days so anyone out there please feel free to tackle it.
I can confirm that bash handles comment lines in its own function, thus bypassing line continuation processing. I took a look at bash-5.0 sources, in
parse.y[3268], inread_token (command), if the'#'char is found, then it performsdiscard_until ('\n');which is a simple function that zaps everything until the newline.Ray, there are many dusty corners in bash parsing. Thankfully, this is a low-hanging fruit that should not be too hard to fix -- one would probably take more time checking bash and zsh to verify correct behaviour. The bash
parse.yis not an elegant bit of code, speaking as someone who had worked on bash highlighting for Scintilla. Heh."then it performs discard_until ('\n'); which is a simple function that zaps everything until the newline."
Perhaps it is in the shell's favor that this way of parsing is surely the simplest. As you show, it's not exactly complicated!
I sure appreciate your 'get it done' attitude, thanks, it makes reporting these things worth the trouble. So often the devs of various projects are more interested in the latest wiz-bang feature than in tidying up little bugs.
sh, bash, dash, ash, zsh, ksh, mksh, csh, tcsh and
bash --posixmode (all from latest msys2) all don't support line continuation for comment line.Per Shell Command Language (2.3 Token Recognition)
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
I think we can remove line continuation handling for comment line unless there is a shell that supports it.
Current code also has other bug (fourth line is also colored as comment):
Marked as fixed (with line continuation for comment line removed, see https://github.com/ScintillaOrg/lexilla/issues/195).