diff options
Diffstat (limited to 'Parser/asdl.py')
-rw-r--r-- | Parser/asdl.py | 18 |
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): |