Support package statement at block level
diff --git a/plyxproto/model.py b/plyxproto/model.py
index e94566c..7acf7a3 100644
--- a/plyxproto/model.py
+++ b/plyxproto/model.py
@@ -446,16 +446,13 @@
class ProtoFile(SourceElement):
- def __init__(self, pkg, body, linespan=None, lexspan=None, p=None):
+ def __init__(self, body, linespan=None, lexspan=None, p=None):
super(ProtoFile, self).__init__(linespan=linespan, lexspan=lexspan, p=p)
- self._fields += ['pkg', 'body']
- self.pkg = pkg
- Base.p(self.pkg, self)
+ self._fields += ['body']
self.body = body
Base.p(self.body, self)
def accept(self, visitor):
if visitor.visit_Proto(self):
- self.v(self.pkg, visitor)
self.v(self.body, visitor)
visitor.visit_Proto_post(self)
diff --git a/plyxproto/parser.py b/plyxproto/parser.py
index 4c80f6f..72899e1 100755
--- a/plyxproto/parser.py
+++ b/plyxproto/parser.py
@@ -441,24 +441,17 @@
p[0] = OptionStatement(Name(LU.i(p, 2)), LU.i(p,4))
self.lh.set_parse_object(p[0], p)
- # topLevelStatement = Group(message_definition | message_extension | enum_definition | service_definition | import_directive | option_directive)
+ # topLevelStatement = Group(message_definition | message_extension | enum_definition | service_definition | import_directive | option_directive | package_definition)
def p_topLevel(self,p):
'''topLevel : message_definition
| message_extension
| enum_definition
| service_definition
| import_directive
+ | package_directive
| option_directive'''
p[0] = p[1]
- def p_package_definition(self, p):
- '''package_definition : package_directive'''
- p[0] = p[1]
-
- def p_packages2(self, p):
- '''package_definition : empty'''
- p[0] = []
-
def p_statements2(self, p):
'''statements : topLevel
| statements topLevel'''
@@ -473,8 +466,8 @@
# parser = Optional(package_directive) + ZeroOrMore(topLevelStatement)
def p_protofile(self, p):
- '''protofile : package_definition statements'''
- p[0] = ProtoFile(LU.i(p,1), LU.i(p,2))
+ '''protofile : statements'''
+ p[0] = ProtoFile(LU.i(p,1))
self.lh.set_parse_object(p[0], p)
# Parsing starting point