defunkt/coffee-mode

Syntax highlighting breaks on a particular regex

Closed this issue · 6 comments

A coffeescript-ified version of this regex breaks syntax highlighting for me in emacs 24.4, coffee-mode 0.5.5 (as reported by M-x coffee-version):

            # daringfireball.net/2010/07/improved_regex_for_matching_urls
            # modifed to allow ftp urls
            # doesn't handle all our cases, but is good enough for now
            linkRegex = ///
                \b
                (                                      # Capture 1: entire matched URL
                  (?:
                    ftp|https?://                      # ftp or http or https protocol
                    |                                  #   or
                    www\d{0,3}[.]                      # "www.", "www1.", "www2." … "www999."
                    |                                  #   or
                    [a-z0-9.\-]+[.][a-z]{2,4}/         # looks like domain name followed by a slash
                  )
                  (?:                                  # One or more:
                    [^\s()<>]+                         # Run of non-space, non-()<>
                    |                                  #   or
                    \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
                  )+
                  (?:                                  # End with:
                    \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
                    |                                  #   or
                    [^\s`!()\[\]{};:'".,<>?«»“”‘’]     # not a space or one of these punct chars
                  )
                )
                ///gi

Thanks!

coffee-mode does not support block regexp yet.
We should support this feature(However its support is difficult, I have to get more
understanding of Emacs syntax highlighting).

I'm the maintainer for elixir-mode, and one of the best resources I had for creating that mode's current syntax highlighting scheme is this excellent blog series by @lunaryorn, who maintains puppet-mode.

You should absolutely check it out! Extremely helpful.

Thanks for information.

I've started chipping away at this here. I have highlighting working for block regexes except needing to really refine the parser so that in-line comments are still highlighted as comments instead of with font-lock-constant-face.

Not sure if this is a separate issue, but it's also broken for a regex inside of a string interpolation block:

foo = "=HYPERLINK(\"#{url}\", \"#{text.replace(/"/g, "'")}\")"

The closing double quotes and parenthesis are both mistaken.

Edit: Simplified the problem, it's unrelated to regex: #285

I fixed breaking syntax highlighting issue.

Before

old

Current

current

It is good to highlight multiline regexp same as single line regexp
however it is too difficult for me with current design.