mirror of
https://github.com/readthedocs/sphinx-autoapi
synced 2024-11-16 00:12:55 +00:00
Fix some more parsing issues
This commit is contained in:
parent
0faeb500ee
commit
2603729925
@ -318,26 +318,33 @@ class ParserExtra(parser.Parser):
|
|||||||
as ``__all__`` and class parent classes on class definition.
|
as ``__all__`` and class parent classes on class definition.
|
||||||
"""
|
"""
|
||||||
content = None
|
content = None
|
||||||
|
is_list = True
|
||||||
while self.current is not None:
|
while self.current is not None:
|
||||||
if self.current.kind == tk.OP and self.current.value in '[(':
|
if self.current.kind == tk.STRING:
|
||||||
|
content.append(self.parse_string())
|
||||||
|
elif self.current.kind == tk.NUMBER:
|
||||||
|
content.append(self.parse_number())
|
||||||
|
elif self.current.kind == tk.NAME:
|
||||||
|
# Handle generators
|
||||||
|
if self.current.value == 'for' and not content:
|
||||||
|
is_list = False
|
||||||
|
# TODO this is dropped for now, but will can be handled with an
|
||||||
|
# object lookup in the future, if we decide to track assignment.
|
||||||
|
# content.append(self.parse_object_identifier())
|
||||||
self.stream.move()
|
self.stream.move()
|
||||||
|
elif self.current.kind == tk.OP and self.current.value in '[(':
|
||||||
if content is None:
|
if content is None:
|
||||||
content = []
|
content = []
|
||||||
|
self.stream.move()
|
||||||
else:
|
else:
|
||||||
content.append(self.parse_iterable())
|
content.append(self.parse_iterable())
|
||||||
continue
|
continue
|
||||||
elif self.current.kind == tk.OP and self.current.value in '])':
|
elif self.current.kind == tk.OP and self.current.value in '])':
|
||||||
self.stream.move()
|
self.stream.move()
|
||||||
return content
|
if is_list:
|
||||||
elif self.current.kind == tk.STRING:
|
return content
|
||||||
content.append(self.parse_string())
|
# Discard generator because we can't do anything with them
|
||||||
elif self.current.kind == tk.NUMBER:
|
return []
|
||||||
content.append(self.parse_number())
|
|
||||||
elif self.current.kind == tk.NAME:
|
|
||||||
# TODO this is dropped for now, but will can be handled with an
|
|
||||||
# object lookup in the future, if we decide to track assignment.
|
|
||||||
# content.append(self.parse_object_identifier())
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
self.stream.move()
|
self.stream.move()
|
||||||
|
|
||||||
|
@ -66,3 +66,18 @@ class PythonParserTests(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
self.assertEqual(self.parse(source).all, ['foo', 'bar'])
|
self.assertEqual(self.parse(source).all, ['foo', 'bar'])
|
||||||
|
|
||||||
|
def test_parses_all_generator(self):
|
||||||
|
source = """
|
||||||
|
__all__ = [x for x in dir(token) if x[0] != '_'] + ['foo', 'bar']
|
||||||
|
"""
|
||||||
|
out = self.parse(source)
|
||||||
|
self.assertEqual(self.parse(source).all, ['foo', 'bar'])
|
||||||
|
|
||||||
|
def test_parses_name(self):
|
||||||
|
source = "foo.bar"
|
||||||
|
self.assertEqual(self.parse(source).children, [])
|
||||||
|
|
||||||
|
def test_parses_list(self):
|
||||||
|
source = "__all__ = [[1, 2], [3, 4]]"
|
||||||
|
self.assertEqual(self.parse(source).all, [[1, 2], [3, 4]])
|
||||||
|
Loading…
Reference in New Issue
Block a user