hyphen prefix for bash heredocs doesn't get highlighted properly
On top of normal heredocs (ie, <<EOF \\n \\n EOF
), Bash also supports heredocs that strip whitespace from the lines following, for consistent indentation using a hyphen prefix (ie, <<-EOF \\n \\n EOF
).
Example of broken highlighting: http://pygments.org/demo/6378/
Documentation for hyphen prefix: http://www.gnu.org/software/bash/manual/bashref.html#Redirections (scroll down to "3.6.6 Here Documents")
Reported by tianon
Comments (2)
-
-
Sorry I don't have a patch to attach, but if you go to source:pygments/lexers/other.py, you find the following line in `BashLexer`:
358 (r'<<\\s*(\\'?)\\\\?(\\w+)[\\w\\W]+?\\2', String),
To fix this, it should be as simple as changing that to this:
358 (r'<<\\s*-?\\s*(\\'?)\\\\?(\\w+)[\\w\\W]+?\\2', String),
I don't know for sure if the extra `
s*` is necessary, since I don't know if the hyphen must be directly adjacent to the `<<`, but I didn't know the delimiter itself didn't have to be either. - Log in to comment
Upon testing within the shell, adding a space between `<<` and `-` makes bash believe the hyphen either is the delimiter (in the case of `<< - EOF`) or is part of the delimiter (in the case of `<< -'test'`). Thus, the final version would be simply: