Repository: pygments/pygments

Issue #1706: MatlabLexer parses command syntax wrong
Created: 2021-02-11T18:54:21Z
I'm on Pygments 2.7.4. I see that some changes have been made to this file (lexers/matlab.py), however this issue has not been fixed (I copied the latest version of the file over into my Pygments installation).
Related issue #1327 and PR # 1328. The bug is introduced in this PR, it seems it was trying to fix a similar case.
Currently, the following code is misinterpreted:
a
b = 5;
The a is seen as a "command syntax" (this is fine), but the command syntax follows on the next line, marking b = 5 as a string. The command syntax should end at the end of the line.
The following change fixes it in the cases I've examined. Old line 108:
(r'(?:^|(?<=;))(\s*)(\w+)([\s+)(?!=|\(|(?:%s)\s+)' % _operators,
             bygroups(Text, Name, Text), 'commandargs'),
New line 108:
(r'(?:^|(?<=;))(\s*)(\w+)([ \t]+)(?!=|\(|(?:%s)\s+)' % _operators,
             bygroups(Text, Name, Text), 'commandargs'),
The same line happens in the latest version of the file, at line number 142. The same change fixes the newest version too.

Duplicate issue #1490: Weird highlighting of Matlab lexer
Created: 2020-06-30T04:38:45Z
I'm using minted to highlight my code. I got a very weird highlighting, and it is different from the demo page. Please forgive me if I ignore any issue related to this problem.
I use pygmentize -f html -O full -O style=rainbow_dash -l Matlab -o test.html exp2_7.m and get the following html file:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<!--
generated by Pygments <https://pygments.org/>
Copyright 2006-2019 by the Pygments team.
Licensed under the BSD license, see LICENSE for details.
-->
<html>
<head>
  <title></title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <style type="text/css">
/*
generated by Pygments <https://pygments.org/>
Copyright 2006-2019 by the Pygments team.
Licensed under the BSD license, see LICENSE for details.
*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%; }
body .hll { background-color: #ffffcc }
body  { background: #ffffff; color: #4d4d4d }
body .c { color: #0080ff; font-style: italic } /* Comment */
body .err { color: #ffffff; background-color: #cc0000 } /* Error */
body .k { color: #2c5dcd; font-weight: bold } /* Keyword */
body .o { color: #2c5dcd } /* Operator */
body .ch { color: #0080ff; font-style: italic } /* Comment.Hashbang */
body .cm { color: #0080ff; font-style: italic } /* Comment.Multiline */
body .cp { color: #0080ff } /* Comment.Preproc */
body .cpf { color: #0080ff; font-style: italic } /* Comment.PreprocFile */
body .c1 { color: #0080ff; font-style: italic } /* Comment.Single */
body .cs { color: #0080ff; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { background-color: #ffcccc; border: 1px solid #c5060b } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #ff0000 } /* Generic.Error */
body .gh { color: #2c5dcd; font-weight: bold } /* Generic.Heading */
body .gi { background-color: #ccffcc; border: 1px solid #00cc00 } /* Generic.Inserted */
body .go { color: #aaaaaa } /* Generic.Output */
body .gp { color: #2c5dcd; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #2c5dcd; font-weight: bold } /* Generic.Subheading */
body .gt { color: #c5060b } /* Generic.Traceback */
body .kc { color: #2c5dcd; font-weight: bold } /* Keyword.Constant */
body .kd { color: #2c5dcd; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #2c5dcd; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #2c5dcd } /* Keyword.Pseudo */
body .kr { color: #2c5dcd; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #5918bb; font-weight: bold } /* Keyword.Type */
body .m { color: #5918bb; font-weight: bold } /* Literal.Number */
body .s { color: #00cc66 } /* Literal.String */
body .na { color: #2c5dcd; font-style: italic } /* Name.Attribute */
body .nb { color: #5918bb; font-weight: bold } /* Name.Builtin */
body .nc { text-decoration: underline } /* Name.Class */
body .no { color: #318495 } /* Name.Constant */
body .nd { color: #ff8000; font-weight: bold } /* Name.Decorator */
body .ni { color: #5918bb; font-weight: bold } /* Name.Entity */
body .ne { color: #5918bb; font-weight: bold } /* Name.Exception */
body .nf { color: #ff8000; font-weight: bold } /* Name.Function */
body .nt { color: #2c5dcd; font-weight: bold } /* Name.Tag */
body .ow { color: #2c5dcd; font-weight: bold } /* Operator.Word */
body .w { color: #cbcbcb } /* Text.Whitespace */
body .mb { color: #5918bb; font-weight: bold } /* Literal.Number.Bin */
body .mf { color: #5918bb; font-weight: bold } /* Literal.Number.Float */
body .mh { color: #5918bb; font-weight: bold } /* Literal.Number.Hex */
body .mi { color: #5918bb; font-weight: bold } /* Literal.Number.Integer */
body .mo { color: #5918bb; font-weight: bold } /* Literal.Number.Oct */
body .sa { color: #00cc66 } /* Literal.String.Affix */
body .sb { color: #00cc66 } /* Literal.String.Backtick */
body .sc { color: #00cc66 } /* Literal.String.Char */
body .dl { color: #00cc66 } /* Literal.String.Delimiter */
body .sd { color: #00cc66; font-style: italic } /* Literal.String.Doc */
body .s2 { color: #00cc66 } /* Literal.String.Double */
body .se { color: #c5060b; font-weight: bold } /* Literal.String.Escape */
body .sh { color: #00cc66 } /* Literal.String.Heredoc */
body .si { color: #00cc66 } /* Literal.String.Interpol */
body .sx { color: #318495 } /* Literal.String.Other */
body .sr { color: #00cc66 } /* Literal.String.Regex */
body .s1 { color: #00cc66 } /* Literal.String.Single */
body .ss { color: #c5060b; font-weight: bold } /* Literal.String.Symbol */
body .bp { color: #5918bb; font-weight: bold } /* Name.Builtin.Pseudo */
body .fm { color: #ff8000; font-weight: bold } /* Name.Function.Magic */
body .il { color: #5918bb; font-weight: bold } /* Literal.Number.Integer.Long */

  </style>
</head>
<body>
<h2></h2>

<div class="highlight"><pre><span></span><span class="k">function</span><span class="w"> </span>output <span class="p">=</span><span class="w"> </span><span class="nf">zigzag</span><span class="p">(</span>input<span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="n">r</span><span class="p">,</span> <span class="n">c</span><span class="p">]</span> <span class="p">=</span> <span class="nb">size</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
    <span class="n">output</span> <span class="p">=</span> <span class="nb">zeros</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">r</span> <span class="o">*</span> <span class="n">c</span><span class="p">);</span>
    <span class="nb">i</span> <span class="p">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="nb">j</span> <span class="p">=</span> <span class="mi">1</span><span class="p">;</span>
    <span class="n">cnt</span> <span class="p">=</span> <span class="mi">1</span><span class="p">;</span>
    
    <span class="k">while</span> <span class="p">((</span><span class="nb">i</span> <span class="o">&lt;=</span> <span class="n">r</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="nb">j</span> <span class="o">&lt;=</span> <span class="n">c</span><span class="p">))</span>
        <span class="n">output</span><span class="p">(</span><span class="n">cnt</span><span class="p">)</span> <span class="p">=</span> <span class="n">input</span><span class="p">(</span><span class="nb">i</span><span class="p">,</span> <span class="nb">j</span><span class="p">);</span>
        <span class="n">cnt</span> <span class="p">=</span> <span class="n">cnt</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="nb">mod</span><span class="p">(</span><span class="nb">i</span> <span class="o">+</span> <span class="nb">j</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span> <span class="c">% odd =&gt; down</span>
            <span class="k">if</span> <span class="p">(</span><span class="nb">i</span> <span class="o">==</span> <span class="n">r</span><span class="p">)</span>
                <span class="nb">j</span> <span class="p">=</span> <span class="nb">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
            <span class="k">elseif</span> <span class="p">(</span><span class="nb">j</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
                <span class="nb">i</span> <span class="p">=</span> <span class="nb">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
            <span class="n">else</span>
                <span class="s">i</span> <span class="s">=</span> <span class="s">i</span> <span class="s">+</span> <span class="s">1</span><span class="p">;</span>
                <span class="nb">j</span> <span class="p">=</span> <span class="nb">j</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
            <span class="n">end</span>
        <span class="s">else</span> <span class="s">%</span> <span class="s">even</span> <span class="s">=&gt;</span> <span class="s">up</span>
            <span class="k">if</span> <span class="p">(</span><span class="nb">j</span> <span class="o">==</span> <span class="n">c</span><span class="p">)</span>
                <span class="nb">i</span> <span class="p">=</span> <span class="nb">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
            <span class="k">elseif</span> <span class="p">(</span><span class="nb">i</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
                <span class="nb">j</span> <span class="p">=</span> <span class="nb">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
            <span class="n">else</span>
                <span class="s">i</span> <span class="s">=</span> <span class="s">i</span> <span class="s">-</span> <span class="s">1</span><span class="p">;</span>
                <span class="nb">j</span> <span class="p">=</span> <span class="nb">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
            <span class="n">end</span>
        <span class="s">end</span>
    <span class="n">end</span>
<span class="s">end</span>
</pre></div>
</body>
</html>
I think some lines are mistakenly recognized as Literal.String. And the demo page give this

Closing comment (2021-02-13T07:05:56Z): I think this is the same as #1706.