mathworks / MATLAB-Language-grammar

This repository contains a regular expression based language grammar for MATLAB to be used by GitHub Linguist for highlighting MATLAB code on GitHub
49 stars 17 forks source link

Escape characters are highlighted in character arrays #75

Open goldrik opened 8 months ago

goldrik commented 8 months ago

Describe the bug When initializing a raw string variable, escape characters (backslash + char) get highlighted by default. This occurs for character arrays (using single quotes), but not for strings (using double quotes).

For example, when defining a Windows path: temp_path = '\\somedrive\path\to\right\folder\'; In this case, the escape characters \\, \r, \t, and \f characters would be highlighted.

If you do the same but with double quotations, the error does not occur. This is the expected behavior.

dklilley commented 8 months ago

Hi @goldrik , thanks for reporting this!

For clarity, can you please attach an image showing this behavior?

goldrik commented 8 months ago

Yup, here's the same string, initialized as a character array, then as a string.

Screenshot 2024-01-05 at 1 52 34 PM 2
dklilley commented 8 months ago

I don't think it is a bug that the escape characters are being highlighted in character vectors - they are explicitly being tokenized as constant.character.escape.matlab. It is definitely incorrect, however, that they are being treated differently between char vectors and string arrays.

I am moving this issue over to the MATLAB-Language-grammar repository, because this is an issue with the grammar.