MATLAB: Make strings greedy + handle line feeds better

This commit is contained in:
Golmote 2017-10-22 15:02:28 +02:00
parent ea380c6c6c
commit 4cd4f01b87
4 changed files with 13 additions and 5 deletions

View File

@ -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/,

View File

@ -1 +1 @@
Prism.languages.matlab={string:/\B'(?:''|[^'\n])*'/,comment:[/%\{[\s\S]*?\}%/,/%.+/],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/,"function":/(?!\d)\w+(?=\s*\()/,operator:/\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,punctuation:/\.{3}|[.,;\[\](){}!]/};
Prism.languages.matlab={comment:[/%\{[\s\S]*?\}%/,/%.+/],string:{pattern:/\B'(?:''|[^'\r\n])*'/,greedy:!0},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/,"function":/(?!\d)\w+(?=\s*\()/,operator:/\.?[*^\/\\']|[+\-:@]|[<>=~]=?|&&?|\|\|?/,punctuation:/\.{3}|[.,;\[\](){}!]/};

View File

@ -2,13 +2,17 @@
%{}%
%{ foo
bar }%
% 'test'
%{ 'test' }%
----------------------------------------------------
[
["comment", "% foobar"],
["comment", "%{}%"],
["comment", "%{ foo\r\nbar }%"]
["comment", "%{ foo\r\nbar }%"],
["comment", "% 'test'"],
["comment", "%{ 'test' }%"]
]
----------------------------------------------------

View File

@ -1,11 +1,13 @@
''
'foo''bar'
'%s'
----------------------------------------------------
[
["string", "''"],
["string", "'foo''bar'"]
["string", "'foo''bar'"],
["string", "'%s'"]
]
----------------------------------------------------