chroma icon indicating copy to clipboard operation
chroma copied to clipboard

Error in Sass lexer

Open seibei-iguchi opened this issue 7 years ago • 5 comments

It seems there is an error in the Sass lexer.

The following code:

.icon {
    $size: 1em;

    width: $size;
    height: $size;
}

will produce the following HTML:

<div class="highlight">
    <pre class="chroma">
        <code class="language-scss" data-lang="scss"><span class="nc">.icon</span> <span class="p">{</span>
    <span class="nv">$size</span><span class="o">:</span> <span class="mi">1</span><span class="kt">em</span><span class="p">;</span>

    <span class="nt">width</span><span class="nd">:</span> <span class="err">$</span><span class="nt">size</span><span class="o">;</span>
    <span class="nt">height</span><span class="nd">:</span> <span class="err">$</span><span class="nt">size</span><span class="o">;</span>
<span class="p">}</span>
        </code>
    </pre>
</div>

Notice the .err classes when using the defined variable, which should be valid syntax. The variable declaration seems to be fine.

seibei-iguchi avatar Nov 23 '18 08:11 seibei-iguchi

I can't figure out why this happens.

The NameVariable regex on this line of the lexer says [!$][\w-]+. That matches the variable names from the issue report above precisely:

regex-example

Yet the style is not applied. If I make a separate style line in the lexer like so:

{`[!$][\w-]+`, NameVariable, nil},

and place that line near the top (so it should trigger before the others), then it still doesn't activate. Hopefully someone else has a better idea. :slightly_smiling_face:

Jos512 avatar Jan 25 '19 16:01 Jos512

We are hitting this in Bootstrap through Hugo which I'm in the middle of migrating to.

Is there any chance that this gets fixed?

XhmikosR avatar Feb 04 '19 15:02 XhmikosR

I took a new, fresh look today but still ran into the problem I described above. If Alec (or someone else) can give me a hint, I'd happily send in a PR.

(Or if someone else sends a pull request is fine too, I'm not tied to this issue. :slightly_smiling_face:)

Jos512 avatar Feb 07 '19 16:02 Jos512

I wish my Go knowledge was good enough to look at it :/

On Thu, Feb 7, 2019, 18:29 Jos512 <[email protected] wrote:

I took a new, fresh look today but still ran into the problem I described above. If Alec (or someone else) can give me a hint, I'd happily send in a PR. (Or if someone else sends a pull request is fine too, I'm not tied to this issue. 🙂)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/alecthomas/chroma/issues/200#issuecomment-461499089, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVVtYdfqVoQK5KkaQRMD-DfQ4SWgaj-ks5vLFRzgaJpZM4YwPBX .

XhmikosR avatar Feb 07 '19 20:02 XhmikosR

If you look in the Sass lexer, you'll notice:

			// { `[ \t]*`, ?? <function _indentation at 0x106932e18> ??, nil },
			// { `//[^\n]*`, ?? <function _starts_block.<locals>.callback at 0x106936048> ??, Push("root") },
			// { `/\*[^\n]*`, ?? <function _starts_block.<locals>.callback at 0x1069360d0> ??, Push("root") },

This means that the original Python lexer used custom functions to do some part of its processing, which I didn't convert.

alecthomas avatar Apr 22 '19 09:04 alecthomas