summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2021-03-01 11:43:48 +0100
committerGeorg Brandl <georg@python.org>2021-03-01 11:43:48 +0100
commitec83fdf152e35cb338bf2738d9ce2d6c1c38c2d5 (patch)
tree90df2aff415db2fe1f984ef6a8b9baaccac0e4ba
parent37113b095ee9a445187a8478589010347b7a9687 (diff)
downloadpygments-git-ec83fdf152e35cb338bf2738d9ce2d6c1c38c2d5.tar.gz
octave: add multiline comments
fixes #1726
-rw-r--r--pygments/lexers/matlab.py21
-rw-r--r--tests/snippets/octave/test_multilinecomment.txt18
2 files changed, 32 insertions, 7 deletions
diff --git a/pygments/lexers/matlab.py b/pygments/lexers/matlab.py
index 7e091022..2e5db693 100644
--- a/pygments/lexers/matlab.py
+++ b/pygments/lexers/matlab.py
@@ -3145,18 +3145,20 @@ class OctaveLexer(RegexLexer):
tokens = {
'root': [
- # We should look into multiline comments
+ (r'%\{\s*\n', Comment.Multiline, 'blockcomment'),
(r'[%#].*$', Comment),
(r'^\s*function\b', Keyword, 'deffunc'),
# from 'iskeyword' on hg changeset 8cc154f45e37
(words((
- '__FILE__', '__LINE__', 'break', 'case', 'catch', 'classdef', 'continue', 'do', 'else',
- 'elseif', 'end', 'end_try_catch', 'end_unwind_protect', 'endclassdef',
- 'endevents', 'endfor', 'endfunction', 'endif', 'endmethods', 'endproperties',
- 'endswitch', 'endwhile', 'events', 'for', 'function', 'get', 'global', 'if', 'methods',
- 'otherwise', 'persistent', 'properties', 'return', 'set', 'static', 'switch', 'try',
- 'until', 'unwind_protect', 'unwind_protect_cleanup', 'while'), suffix=r'\b'),
+ '__FILE__', '__LINE__', 'break', 'case', 'catch', 'classdef',
+ 'continue', 'do', 'else', 'elseif', 'end', 'end_try_catch',
+ 'end_unwind_protect', 'endclassdef', 'endevents', 'endfor',
+ 'endfunction', 'endif', 'endmethods', 'endproperties', 'endswitch',
+ 'endwhile', 'events', 'for', 'function', 'get', 'global', 'if',
+ 'methods', 'otherwise', 'persistent', 'properties', 'return',
+ 'set', 'static', 'switch', 'try', 'until', 'unwind_protect',
+ 'unwind_protect_cleanup', 'while'), suffix=r'\b'),
Keyword),
(words(builtin_kw + command_kw + function_kw + loadable_kw + mapping_kw,
@@ -3192,6 +3194,11 @@ class OctaveLexer(RegexLexer):
(r'[a-zA-Z_]\w*', Name),
(r'.', Text),
],
+ 'blockcomment': [
+ (r'^\s*%\}', Comment.Multiline, '#pop'),
+ (r'^.*\n', Comment.Multiline),
+ (r'.', Comment.Multiline),
+ ],
'string': [
(r"[^']*'", String, '#pop'),
],
diff --git a/tests/snippets/octave/test_multilinecomment.txt b/tests/snippets/octave/test_multilinecomment.txt
new file mode 100644
index 00000000..4d03d51e
--- /dev/null
+++ b/tests/snippets/octave/test_multilinecomment.txt
@@ -0,0 +1,18 @@
+---input---
+%{
+This is a long comment
+ %}
+This isnt
+
+---tokens---
+'%{\n' Comment.Multiline
+
+'This is a long comment\n' Comment.Multiline
+
+' %}' Comment.Multiline
+'\n' Text
+
+'This' Name
+' ' Text
+'isnt' Name
+'\n' Text