Annotate models and fields with policies
diff --git a/plyxproto/model.py b/plyxproto/model.py
index 3f33704..9cbdccc 100644
--- a/plyxproto/model.py
+++ b/plyxproto/model.py
@@ -83,7 +83,7 @@
class FieldDefinition(SourceElement):
def __init__(self, field_modifier, ftype, name, fieldId, fieldDirective, linespan=None, lexspan=None, p=None):
super(FieldDefinition, self).__init__(linespan=linespan, lexspan=lexspan, p=p)
- self._fields += ['field_modifier', 'ftype', 'name', 'fieldId', 'fieldDirective']
+ self._fields += ['field_modifier', 'ftype', 'name', 'fieldId', 'policy', 'fieldDirective']
self.name = name
Base.p(self.name, self)
self.field_modifier = field_modifier
@@ -91,6 +91,9 @@
self.ftype = ftype
Base.p(self.ftype, self)
self.fieldId = fieldId
+ Base.p(self.policy, self)
+ self.policy = policy
+
Base.p(self.fieldId, self)
self.fieldDirective = fieldDirective
Base.p(self.fieldDirective, self)
@@ -162,13 +165,19 @@
visitor.visit_LinkSpec_post(self)
class MessageDefinition(SourceElement):
- def __init__(self, name, bases, body, linespan=None, lexspan=None, p=None):
+ def __init__(self, name, policy, bases, body, linespan=None, lexspan=None, p=None):
super(MessageDefinition, self).__init__(linespan=linespan, lexspan=lexspan, p=p)
- self._fields += ['name', 'bases', 'body']
+ self._fields += ['name', 'policy', 'bases', 'body']
+
self.name = name
Base.p(self.name, self)
+
+ self.policy = policy
+ Base.p(self.policy, self)
+
self.bases = bases
Base.p(self.bases, self)
+
self.body = body
Base.p(self.body, self)
diff --git a/plyxproto/parser.py b/plyxproto/parser.py
index 443ebb1..6736e8a 100755
--- a/plyxproto/parser.py
+++ b/plyxproto/parser.py
@@ -171,6 +171,14 @@
p[0] = FieldDirective(Name(LU.i(p, 1)), LU.i(p, 3))
self.lh.set_parse_object(p[0], p)
+ def p_policy_opt_explicit(self, p):
+ '''policy_opt : DOUBLECOLON NAME'''
+ p[0] = p[2]
+
+
+ def p_policy_opt_empty(self, p):
+ '''policy_opt : empty'''
+ p[0] = None
def p_csv_expr(self, p):
'''csv_expr : LPAR csv RPAR'''
@@ -266,8 +274,8 @@
# Root of the field declaration.
def p_field_definition(self, p):
- '''field_definition : field_modifier field_type field_name EQ field_id field_directives SEMI'''
- p[0] = FieldDefinition(LU.i(p,1), LU.i(p,2), LU.i(p, 3), LU.i(p,5), LU.i(p,6))
+ '''field_definition : field_modifier field_type field_name policy_opt EQ field_id field_directives SEMI'''
+ p[0] = FieldDefinition(LU.i(p,1), LU.i(p,2), LU.i(p, 3), LU.i(p,4), LU.i(p,6), LU.i(p,7))
self.lh.set_parse_object(p[0], p)
# Root of the enum field declaration.
@@ -358,8 +366,8 @@
# Root of the message declaration.
# message_definition = MESSAGE_ - ident("messageId") + LBRACE + message_body("body") + RBRACE
def p_message_definition(self, p):
- '''message_definition : MESSAGE NAME csv_expr LBRACE message_body RBRACE'''
- p[0] = MessageDefinition(Name(LU.i(p, 2)), LU.i(p, 3), LU.i(p,5))
+ '''message_definition : MESSAGE NAME policy_opt csv_expr LBRACE message_body RBRACE'''
+ p[0] = MessageDefinition(Name(LU.i(p, 2)), LU.i(p,3), LU.i(p, 4), LU.i(p,6))
self.lh.set_parse_object(p[0], p)
# method_definition ::= 'rpc' ident '(' [ ident ] ')' 'returns' '(' [ ident ] ')' ';'