hyphen prefix for bash heredocs doesn't get highlighted properly

Issue #526 new
Anonymous created an issue

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)

  1. Anonymous

    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:

       358             (r'<<-?\\s*(\\'?)\\\\?(\\w+)[\\w\\W]+?\\2', String),
  2. Anonymous

    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.

  3. Log in to comment