mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
unify some ast.argument's attrs; change Attribute column offset (closes #16795)
Patch from Sven Brauch.
This commit is contained in:
parent
c45e041bff
commit
cda75be02a
11 changed files with 250 additions and 235 deletions
|
|
@ -158,11 +158,19 @@ class ASDLParser(spark.GenericParser, object):
|
|||
msg="expected attributes, found %s" % id)
|
||||
return Sum(sum, attributes)
|
||||
|
||||
def p_product(self, info):
|
||||
def p_product_0(self, info):
|
||||
" product ::= ( fields ) "
|
||||
_0, fields, _1 = info
|
||||
return Product(fields)
|
||||
|
||||
def p_product_1(self, info):
|
||||
" product ::= ( fields ) Id ( fields ) "
|
||||
_0, fields, _1, id, _2, attributes, _3 = info
|
||||
if id.value != "attributes":
|
||||
raise ASDLSyntaxError(id.lineno,
|
||||
msg="expected attributes, found %s" % id)
|
||||
return Product(fields, attributes)
|
||||
|
||||
def p_sum_0(self, constructor):
|
||||
" sum ::= constructor "
|
||||
return [constructor[0]]
|
||||
|
|
@ -289,11 +297,15 @@ class Sum(AST):
|
|||
return "Sum(%s, %s)" % (self.types, self.attributes)
|
||||
|
||||
class Product(AST):
|
||||
def __init__(self, fields):
|
||||
def __init__(self, fields, attributes=None):
|
||||
self.fields = fields
|
||||
self.attributes = attributes or []
|
||||
|
||||
def __repr__(self):
|
||||
return "Product(%s)" % self.fields
|
||||
if self.attributes is None:
|
||||
return "Product(%s)" % self.fields
|
||||
else:
|
||||
return "Product(%s, %s)" % (self.fields, self.attributes)
|
||||
|
||||
class VisitorBase(object):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue