Commits

Georg Brandl committed 59408e7

Closes #776: implement more comment types for MATLAB.

Comments (0)

Files changed (2)

pygments/lexers/math.py

            'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
            'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer']
 
+
 class JuliaLexer(RegexLexer):
     name = 'Julia'
     aliases = ['julia','jl']
 class MatlabLexer(RegexLexer):
     """
     For Matlab source code.
-    Contributed by Ken Schutte <kschutte@csail.mit.edu>.
 
     *New in Pygments 0.10.*
     """
             # line starting with '!' is sent as a system command.  not sure what
             # label to use...
             (r'^!.*', String.Other),
+            (r'%\{\s*\n', Comment.Multiline, 'blockcomment'),
             (r'%.*$', Comment),
             (r'^\s*function', Keyword, 'deffunc'),
 
 
             ("(" + "|".join(elfun+specfun+elmat) + r')\b',  Name.Builtin),
 
+            # line continuation with following comment:
+            (r'\.\.\..*$', Comment),
+
             # operators:
             (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
             # operators requiring escape for re:
         'string': [
             (r'[^\']*\'', String, '#pop')
         ],
+        'blockcomment': [
+            (r'^\s*%\}', Comment.Multiline, '#pop'),
+            (r'^.*\n', Comment.Multiline),
+            (r'.', Comment.Multiline),
+        ],
         'deffunc': [
             (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
              bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,

tests/examplefiles/matlab_sample

 a = rand(30);
 b = rand(30);
 
-c = a .* b ./ a \ (b .* a + b - a);
+c = a .* b ./ a \ ... comment at end of line and continuation
+    (b .* a + b - a);
 
 c = a' * b';  % note: these ticks are for transpose, not quotes.
 
 function y=myfunc(x)
 y = exp(x);
 
-
+ {%
+a block comment
+ %}