Issue #414 resolved

Matlab lexer: Doesn't properly handle transpose operator

Anonymous created an issue

The Matlab lexer handles the special case where a single quote is used as a transpose operator, instead of as the marker to start and end strings. However, the way the code is written, there is a side effect: whatever came right before the transpose operater gets turned into plain Text, even if it's supposed to be a Punctuation.

Most of these work, except for the ones with comments: {{{ 'abc' abc' [1 2 3] [1 2 3]' % Right bracket not recognized '[1 2 3]' f(a) f(a)' % Right paren not recognized }}} Use the Tango color scheme here to see that it's not quite right: http://pygments.org/demo/1799/

This is the present code: {{{ (r'([\w\)\]]+)(\')', bygroups(Text, Operator)), }}}

I believe that replacing it with this should fix it. This says to recognize the single quote as an operater, as long as it's preceded by letters/nums or ] or ). It's not perfect - it won't catch cases where there's a space before the transpose operator. But it should be an improvement on the current version because it won't turn the preceding stuff into Text. {{{ (r'(?<=[\w\)\]])\'', Operator), }}}

Similarly, this might be a better way to start a string. Instead of looking for a plain single quote, this looks for a single quote as long as it's NOT preceded by words/nums or ] or ). I believe that a string can't start right after these characters. {{{ (r'(?<![\w\)\]])\'', String, 'string'), }}}

Reported by guest

Comments (6)

  1. Ryan Ollos

    I'm seeing a problem with the transpose operator, using Pygments 1.4 on Trac 0.12.2. I thought I'd post here before opening a new issue.

    The problem may only occur when using the dot-transpose operator: .'

    After using the dot-transpose operator (period followed by a single quote), all text that follows is highlighted in pink, as is done for strings, which are also delimited by single quotes.

    See attached image for an example.

  2. Log in to comment