Skip to content

Commit

Permalink
Add Matlab2017a strings to Matlab lexer (#1048)
Browse files Browse the repository at this point in the history
Starting with Matlab R2017a you can create strings using double quotes.
This adds support for that.
  • Loading branch information
bebuch authored and pyrmont committed May 28, 2019
1 parent 4ca2e67 commit e5ec8df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 9 additions & 2 deletions lib/rouge/lexers/matlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions spec/visual/samples/matlab
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down

0 comments on commit e5ec8df

Please sign in to comment.