Skip to content

Commit b7aacf6

Browse files
authored
Add support for function with outputs but no inputs (#200)
* Add support for function with outputs but no inputs This commit adds a specific lexer for a function with outputs but no inputs (or parentheses) * Appease the black gods * Fix typo in comment
1 parent 7f29c80 commit b7aacf6

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

sphinxcontrib/mat_lexer.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,15 @@ class MatlabLexer(RegexLexer):
338338
),
339339
"#pop",
340340
),
341-
# function with no args
341+
# function with outputs but no inputs
342+
(
343+
r"(\s*)(?:(.+)(\s*)(=)(\s*))?([a-zA-Z_]\w*)",
344+
bygroups(
345+
Whitespace, Text, Whitespace, Punctuation, Whitespace, Name.Function
346+
),
347+
"#pop",
348+
),
349+
# function with no inputs or outputs
342350
(r"(\s*)([a-zA-Z_]\w*)", bygroups(Text, Name.Function), "#pop"),
343351
],
344352
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function result = f_no_input_no_parentheses_no_docstring
2+
result = 1

tests/test_matlabify.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def test_module(mod):
6868
"Bool",
6969
"ClassWithEvent",
7070
"f_no_input_no_output_no_parentheses",
71+
"f_no_input_no_parentheses_no_docstring",
7172
"ClassWithCommentHeader",
7273
"f_with_comment_header",
7374
"f_with_dummy_argument",

tests/test_parse_mfile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ def test_no_input_no_output_no_parentheses():
210210
)
211211

212212

213+
def test_no_input_no_parentheses_no_docstring():
214+
mfile = os.path.join(
215+
DIRNAME, "test_data", "f_no_input_no_parentheses_no_docstring.m"
216+
)
217+
obj = mat_types.MatObject.parse_mfile(
218+
mfile, "f_no_input_no_parentheses_no_docstring", "test_data"
219+
)
220+
assert obj.name == "f_no_input_no_parentheses_no_docstring"
221+
assert obj.retv == ["result"]
222+
assert obj.args is None
223+
224+
213225
def test_ClassWithCommentHeader():
214226
mfile = os.path.join(DIRNAME, "test_data", "ClassWithCommentHeader.m")
215227
obj = mat_types.MatObject.parse_mfile(mfile, "ClassWithCommentHeader", "test_data")

0 commit comments

Comments
 (0)