sphinx-contrib / matlabdomain

A Sphinx extension for documenting Matlab code
http://sphinxcontrib-matlabdomain.readthedocs.io/
Other
69 stars 45 forks source link

Wrong function name in tokens when defined without parentheses and docstring #199

Closed H0R5E closed 1 year ago

H0R5E commented 1 year ago

Hi,

Given a function defined like so in a file test.m:

function bob = test
bob = 1;
disp("bob")
end

In this case matlabdomain will generate a warning WARNING: [sphinxcontrib-matlabdomain] Unexpected function name: 'bob'. Expected 'test' in module ''.

The tokens provided to the MatFunction class seem to be wrong for this case. I captured them as follows:

[(Token.Text.Whitespace, '\n'), (Token.Keyword, 'end'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ')'), (Token.Literal.String, '"bob"'), (Token.Punctuation, '('), (Token.Name.Builtin, 'disp'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ';'), (Token.Literal.Number.Integer, '1'), (Token.Text, ' '), (Token.Punctuation, '='), (Token.Text, ' '), (Token.Name, 'bob'), (Token.Text.Whitespace, '\n'), (Token.Name, 'test'), (Token.Text, ' '), (Token.Punctuation, '='), (Token.Text, ' '), (Token.Name.Function, 'bob')]

Note the (Token.Name.Function, 'bob') at the end.

When you include parentheses the tokens are correct:

function bob = test()
bob = 1;
disp("bob")
end
[(Token.Text.Whitespace, '\n'), (Token.Keyword, 'end'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ')'), (Token.Literal.String, '"bob"'), (Token.Punctuation, '('), (Token.Name.Builtin, 'disp'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ';'), (Token.Literal.Number.Integer, '1'), (Token.Text, ' '), (Token.Punctuation, '='), (Token.Text, ' '), (Token.Name, 'bob'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ')'), (Token.Punctuation, '('), (Token.Name.Function, 'test')]

And also when you include a docstring:

function bob = test
%bob
bob = 1;
disp("bob")
end
[(Token.Text.Whitespace, '\n'), (Token.Keyword, 'end'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ')'), (Token.Literal.String, '"bob"'), (Token.Punctuation, '('), (Token.Name.Builtin, 'disp'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ';'), (Token.Literal.Number.Integer, '1'), (Token.Text, ' '), (Token.Punctuation, '='), (Token.Text, ' '), (Token.Name, 'bob'), (Token.Text.Whitespace, '\n'), (Token.Comment, '%bob'), (Token.Text.Whitespace, '\n'), (Token.Punctuation, ')'), (Token.Punctuation, '('), (Token.Name.Function, 'test')]

I've run these tests against the master branch. Any help would be greatly appreciated.

Best wishes,

Mat

joeced commented 1 year ago

Thanks for the detailed report. I'm away from my computer at the moment. I'll look into it as soon as I get back.

H0R5E commented 1 year ago

@joeced, I've offered a solution in #200