Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support line continuations in parens and brackets #28

Merged
merged 1 commit into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions Account.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,26 @@
end
end
function r = multiplyBy(obj,n)
r = [obj.Value] * n;
r = [obj.Value( end ) ]* n;
n = 1;
nFactorial = 1;
while nFactorial < 1e100
n = n + 1;
nFactorial = nFactorial * n;
end
end
end
function r = multiplyBy(obj,n)
r = [obj.Value] * n;
n = 1;
nFactorial = 1;
while nFactorial < 1e100
n = n + 1;
nFactorial = nFactorial * n;
end
end
function r = plus(o1,o2)
r = o1.Value + o2.Value;
end
end
% Some events
end
function r = plus(o1,o2)
r = o1.Value + o2.Value;
end
end
% Some events
events (ListenAccess = protected) % A comment
% Event comment
StateChanged
% Event comment
StateChanged
end
% Some enumeration
% Some enumeration
enumeration % A comment
No (0)
Yes (1)
No (0)
Yes (1)
end
end
end
271 changes: 222 additions & 49 deletions Matlab.tmbundle/Syntaxes/MATLAB.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,102 @@
<key>patterns</key>
<array>
<dict>
<key>comment</key>
<string>This and #all_after_command_dual are split out so #command_dual can be excluded in things like (), {}, []</string>
<key>include</key>
<string>#classdef</string>
</dict>
<dict>
<key>include</key>
<string>#function</string>
</dict>
<dict>
<key>include</key>
<string>#blocks</string>
</dict>
<dict>
<key>include</key>
<string>#control_statements</string>
</dict>
<dict>
<key>include</key>
<string>#global_persistent</string>
<string>#all_before_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#line_continuation</string>
</dict>
<dict>
<key>include</key>
<string>#comments</string>
</dict>
<dict>
<key>include</key>
<string>#transpose</string>
</dict>
<dict>
<key>include</key>
<string>#constants</string>
</dict>
<dict>
<key>include</key>
<string>#variables</string>
</dict>
<dict>
<key>include</key>
<string>#end_in_parens</string>
<string>#all_after_command_dual</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>all_before_command_dual</key>
<dict>
<key>include</key>
<string>#numbers</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#classdef</string>
</dict>
<dict>
<key>include</key>
<string>#function</string>
</dict>
<dict>
<key>include</key>
<string>#blocks</string>
</dict>
<dict>
<key>include</key>
<string>#control_statements</string>
</dict>
<dict>
<key>include</key>
<string>#global_persistent</string>
</dict>
<dict>
<key>include</key>
<string>#parens</string>
</dict>
<dict>
<key>include</key>
<string>#square_brackets</string>
</dict>
<dict>
<key>include</key>
<string>#indexing_curly_brackets</string>
</dict>
<dict>
<key>include</key>
<string>#curly_brackets</string>
</dict>
</array>
</dict>
<key>all_after_command_dual</key>
<dict>
<key>include</key>
<string>#operators</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#string</string>
</dict>
<dict>
<key>include</key>
<string>#line_continuation</string>
</dict>
<dict>
<key>include</key>
<string>#comments</string>
</dict>
<dict>
<key>include</key>
<string>#transpose</string>
</dict>
<dict>
<key>include</key>
<string>#constants</string>
</dict>
<dict>
<key>include</key>
<string>#variables</string>
</dict>
<dict>
<key>include</key>
<string>#numbers</string>
</dict>
<dict>
<key>include</key>
<string>#operators</string>
</dict>
</array>
</dict>
</array>
<key>repository</key>
<dict>
<key>blocks</key>
<dict>
<key>patterns</key>
Expand Down Expand Up @@ -1181,6 +1215,145 @@
<key>name</key>
<string>meta.globalpersistent.matlab</string>
</dict>
<key>parens</key>
<dict>
<key>begin</key>
<string>\(</string>
<key>end</key>
<string>(\)|(?<!\.\.\.).\n)</string>
<key>comment</key>
<string>We don't include $self here to avoid matching command syntax inside (), [], {}</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#end_in_parens</string>
</dict>
<dict>
<key>include</key>
<string>#all_before_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#all_after_command_dual</string>
</dict>
<dict>
<key>comment</key>
<string>These block keywords pick up any such missed keywords when the block matching for things like (), if-end, etc. don't work. Useful for when someone has partially written</string>
<key>include</key>
<string>#block_keywords</string>
</dict>
</array>
</dict>
<key>square_brackets</key>
<dict>
<key>begin</key>
<string>\[</string>
<key>end</key>
<string>\]</string>
<key>comment</key>
<string>We don't include $self here to avoid matching command syntax inside (), [], {}</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#all_before_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#all_after_command_dual</string>
</dict>
<dict>
<key>comment</key>
<string>These block keywords pick up any such missed keywords when the block matching for things like (), if-end, etc. don't work. Useful for when someone has partially written</string>
<key>include</key>
<string>#block_keywords</string>
</dict>
</array>
</dict>
<key>curly_brackets</key>
<dict>
<key>begin</key>
<string>\{</string>
<key>end</key>
<string>\}</string>
<key>comment</key>
<string>We don't include $self here to avoid matching command syntax inside (), [], {}</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#end_in_parens</string>
</dict>
<dict>
<key>include</key>
<string>#all_before_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#all_after_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#end_in_parens</string>
</dict>
<dict>
<key>comment</key>
<string>These block keywords pick up any such missed keywords when the block matching for things like (), if-end, etc. don't work. Useful for when someone has partially written</string>
<key>include</key>
<string>#block_keywords</string>
</dict>
</array>
</dict>
<key>indexing_curly_brackets</key>
<dict>
<key>Comment</key>
<string>Match identifier{idx, idx, } and stop at newline without ... This helps with partially written code like x{idx </string>
<key>begin</key>
<string>([a-zA-Z][a-zA-Z0-9_\.]*\s*)\{</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
</array>
</dict>
</dict>
<key>end</key>
<string>(\}|(?<!\.\.\.).\n)</string>
<key>comment</key>
<string>We don't include $self here to avoid matching command syntax inside (), [], {}</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#end_in_parens</string>
</dict>
<dict>
<key>include</key>
<string>#all_before_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#all_after_command_dual</string>
</dict>
<dict>
<key>include</key>
<string>#end_in_parens</string>
</dict>
<dict>
<key>comment</key>
<string>These block keywords pick up any such missed keywords when the block matching for things like (), if-end, etc. don't work. Useful for when someone has partially written</string>
<key>include</key>
<string>#block_keywords</string>
</dict>
</array>
</dict>
<key>line_continuation</key>
<dict>
<key>captures</key>
Expand Down
2 changes: 1 addition & 1 deletion controlFlow.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
otherwise
end
try
if y < 10
if y( end ) < 10
disp('y < 10');
elseif y < 20
disp('y < 20');
Expand Down
16 changes: 16 additions & 0 deletions lineContinuations.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
vector = [ ... comment
1 ... commentary
2 ...
3 ... some comments
];

cellvector = { ... comment
1 ... comment
2 ...
3 ... comment
};

output = foo( ...
arg1, ...comment
arg2 ... comment
);