diff --git a/lib/rouge/lexers/matlab.rb b/lib/rouge/lexers/matlab.rb index ecd378d79e..56d94bc562 100644 --- a/lib/rouge/lexers/matlab.rb +++ b/lib/rouge/lexers/matlab.rb @@ -58,15 +58,22 @@ def self.builtins rule /\d+L/, Num::Integer::Long rule /\d+/, Num::Integer - rule /'(?=(.*'))/, Str::Single, :string + rule /'(?=(.*'))/, Str::Single, :chararray + rule /"(?=(.*"))/, Str::Double, :string rule /'/, Operator end - state :string do + state :chararray do rule /[^']+/, Str::Single rule /''/, Str::Escape rule /'/, Str::Single, :pop! end + + state :string do + rule /[^"]+/, Str::Double + rule /""/, Str::Escape + rule /"/, Str::Double, :pop! + end end end end diff --git a/spec/visual/samples/matlab b/spec/visual/samples/matlab index cb20f8318b..0ddf565358 100644 --- a/spec/visual/samples/matlab +++ b/spec/visual/samples/matlab @@ -3,8 +3,11 @@ function zz=sample(aa) % some comments %%%%%%%%%%%%%%%%%% -x = 'a string'; % some 'ticks' in a comment -y = 'a string with ''interal'' quotes'; +x = "a string"; % some "ticks" in a comment +y = "a string with ""interal"" quotes"; + +x = 'a char array'; % some 'ticks' in a comment +y = 'a char array with ''interal'' quotes'; for i=1:20 disp(i); @@ -18,7 +21,8 @@ c = a .* b ./ a \ ... comment at end of line and continuation c = a' * b'; % note: these ticks are for transpose, not quotes. -disp('a comment symbol, %, in a string'); +disp("a comment symbol, %, in a string"); +disp('a comment symbol, %, in a char array'); !echo abc % this isn't a comment - it's passed to system command