Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lib/test/test_asdl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ def test_product(self):
alias = self.types['alias']
self.assertEqual(
str(alias),
'Product([Field(identifier, name), Field(identifier, asname, opt=True)], '
'Product([Field(identifier, name), Field(identifier, asname, quantifiers=[OPTIONAL])], '
'[Field(int, lineno), Field(int, col_offset), '
'Field(int, end_lineno, opt=True), Field(int, end_col_offset, opt=True)])')
'Field(int, end_lineno, quantifiers=[OPTIONAL]), Field(int, end_col_offset, quantifiers=[OPTIONAL])])')

def test_attributes(self):
stmt = self.types['stmt']
self.assertEqual(len(stmt.attributes), 4)
self.assertEqual(repr(stmt.attributes[0]), 'Field(int, lineno)')
self.assertEqual(repr(stmt.attributes[1]), 'Field(int, col_offset)')
self.assertEqual(repr(stmt.attributes[2]), 'Field(int, end_lineno, opt=True)')
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, opt=True)')
self.assertEqual(repr(stmt.attributes[2]), 'Field(int, end_lineno, quantifiers=[OPTIONAL])')
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, quantifiers=[OPTIONAL])')

def test_constructor_fields(self):
ehandler = self.types['excepthandler']
Expand Down
20 changes: 12 additions & 8 deletions Parser/asdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,21 @@ def __str__(self):
return "{}{} {}".format(self.type, extra, self.name)

def __repr__(self):
extra = ""
for mod in self.quantifiers:
if mod is Quantifier.SEQUENCE:
extra += ", SEQUENCE"
elif mod is Quantifier.OPTIONAL:
extra += ", OPTIONAL"
if self.quantifiers:
texts = []
for mod in self.quantifiers:
if mod is Quantifier.SEQUENCE:
texts.append("SEQUENCE")
elif mod is Quantifier.OPTIONAL:
texts.append("OPTIONAL")
extra = ", quantifiers=[{}]".format(", ".join(texts))
else:
extra = ""

if self.name is None:
return 'Field({0.type}, quantifiers=[{1}])'.format(self, extra)
return 'Field({0.type}{1})'.format(self, extra)
else:
return 'Field({0.type}, {0.name}, quantifiers=[{1}])'.format(self, extra)
return 'Field({0.type}, {0.name}{1})'.format(self, extra)

class Sum(AST):
def __init__(self, types, attributes=None):
Expand Down
Loading