Skip to content

Commit

Permalink
MATLAB: Make strings greedy + handle line feeds better
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Oct 22, 2017
1 parent ea380c6 commit 4cd4f01
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions components/prism-matlab.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Prism.languages.matlab = {
// We put string before comment, because of printf() patterns that contain "%"
'string': /\B'(?:''|[^'\n])*'/,
'comment': [
/%\{[\s\S]*?\}%/,
/%.+/
],
'string': {
pattern: /\B'(?:''|[^'\r\n])*'/,
greedy: true
},
// FIXME We could handle imaginary numbers as a whole
'number': /\b-?(?:\d*\.?\d+(?:[eE][+-]?\d+)?(?:[ij])?|[ij])\b/,
'keyword': /\b(?:break|case|catch|continue|else|elseif|end|for|function|if|inf|NaN|otherwise|parfor|pause|pi|return|switch|try|while)\b/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-matlab.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion tests/languages/matlab/comment_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
%{}%
%{ foo
bar }%
% 'test'
%{ 'test' }%

----------------------------------------------------

[
["comment", "% foobar"],
["comment", "%{}%"],
["comment", "%{ foo\r\nbar }%"]
["comment", "%{ foo\r\nbar }%"],
["comment", "% 'test'"],
["comment", "%{ 'test' }%"]
]

----------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion tests/languages/matlab/string_feature.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
''
'foo''bar'
'%s'

----------------------------------------------------

[
["string", "''"],
["string", "'foo''bar'"]
["string", "'foo''bar'"],
["string", "'%s'"]
]

----------------------------------------------------
Expand Down

0 comments on commit 4cd4f01

Please sign in to comment.