diff options
author | Antony Lee <anntzer.lee@gmail.com> | 2019-11-26 17:29:50 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2019-11-27 06:29:53 +0100 |
commit | afc4856087923db94674351a7c8988f222d20392 (patch) | |
tree | 0cd228363544628421fcf3b022bb9fc448163e9f | |
parent | 1d5f36e04b4cc0f8dddc62823b6a92de78847883 (diff) | |
download | pygments-git-afc4856087923db94674351a7c8988f222d20392.tar.gz |
MATLAB allows keywords to be used as field names.
... so don't highlight them as keywords in that position.
Example MATLAB session showcasing this "feature":
>> x.for = 42
x =
struct with fields:
for: 42
>> x
x =
struct with fields:
for: 42
>> x.for
ans =
42
-rw-r--r-- | pygments/lexers/matlab.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/pygments/lexers/matlab.py b/pygments/lexers/matlab.py index ee85d088..f687810b 100644 --- a/pygments/lexers/matlab.py +++ b/pygments/lexers/matlab.py @@ -84,11 +84,14 @@ class MatlabLexer(RegexLexer): (r'^\s*function\b', Keyword, 'deffunc'), # from 'iskeyword' on version 7.11 (R2010): - (words(( - 'break', 'case', 'catch', 'classdef', 'continue', 'else', 'elseif', - 'end', 'enumerated', 'events', 'for', 'function', 'global', 'if', - 'methods', 'otherwise', 'parfor', 'persistent', 'properties', - 'return', 'spmd', 'switch', 'try', 'while'), suffix=r'\b'), + # Check that there is no preceding dot, as keywords are valid field + # names. + (words(('break', 'case', 'catch', 'classdef', 'continue', 'else', + 'elseif', 'end', 'enumerated', 'events', 'for', 'function', + 'global', 'if', 'methods', 'otherwise', 'parfor', + 'persistent', 'properties', 'return', 'spmd', 'switch', + 'try', 'while'), + prefix=r'(?<!\.)', suffix=r'\b'), Keyword), ("(" + "|".join(elfun + specfun + elmat) + r')\b', Name.Builtin), |