summaryrefslogtreecommitdiffstats
path: root/Parser/asdl.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-03-18 17:48:58 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-03-18 17:48:58 (GMT)
commitcda75be02a79686a8e634576600814271536bc1a (patch)
treeb456968bae7bcdebceb833e7b13dae163d732d36 /Parser/asdl.py
parentc45e041bff4a5f9aa137dcd4933c72a9221cd7d5 (diff)
downloadcpython-cda75be02a79686a8e634576600814271536bc1a.zip
cpython-cda75be02a79686a8e634576600814271536bc1a.tar.gz
cpython-cda75be02a79686a8e634576600814271536bc1a.tar.bz2
unify some ast.argument's attrs; change Attribute column offset (closes #16795)
Patch from Sven Brauch.
Diffstat (limited to 'Parser/asdl.py')
-rw-r--r--Parser/asdl.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Parser/asdl.py b/Parser/asdl.py
index 1f98ada..7df76c0 100644
--- a/Parser/asdl.py
+++ b/Parser/asdl.py
@@ -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):