def p_dotname(self, p): '''dotname : NAME | dotname DOT NAME''' if len(p) == 2: p[0] = [LU(p, 1)] else: p[0] = p[1] + [LU(p, 3)]
def p_field_directive_plus(self, p): '''field_directive_plus : field_directive | field_directive_plus COMMA field_directive''' if len(p) == 2: p[0] = [LU(p, 1)] else: p[0] = p[1] + [LU(p, 3)]
def p_csv(self, p): '''csv : dotname | csv COMMA dotname''' if len(p) == 2: p[0] = [LU(p, 1)] else: p[0] = p[1] + [LU(p, 3)]
def p_fieldName(self, p): '''field_name : STARTTOKEN | NAME | MESSAGE | MAX''' p[0] = Name(LU.i(p, 1)) self.lh.set_parse_object(p[0], p) p[0].deriveLex()
def p_map_definition(self, p): '''map_definition : MAP NAME POLICYBODY''' ltxt = p[3].lstrip('<').rstrip('>') l = ast.parse(ltxt).body[0] if not isinstance(l, ast.Expr): raise PythonError("map operator needs to be an expression") elif not isinstance(l.value, ast.Lambda): raise PythonError("map operator needs to be a lambda") p[0] = MapDefinition(Name(LU.i(p, 2)), ltxt) self.lh.set_parse_object(p[0], p)
def p_policy_definition(self, p): '''policy_definition : POLICY NAME POLICYBODY''' try: fol = self.fol_parser.parse(p[3], lexer=self.fol_lexer) except FOLParsingError as e: lineno, lexpos, length = e.error_range raise ParsingError( "Policy parsing error in policy %s" % p[2], (p.lineno(3) + lineno, lexpos + p.lexpos(3), length)) p[0] = PolicyDefinition(Name(LU.i(p, 2)), fol) self.lh.set_parse_object(p[0], p)
def p_primitive_type(self, p): '''primitive_type : DOUBLE | FLOAT | INT32 | INT64 | UINT32 | UINT64 | SINT32 | SINT64 | FIXED32 | FIXED64 | SFIXED32 | SFIXED64 | BOOL | STRING | BYTES''' p[0] = LU.i(p, 1)
def p_message_definition(self, p): '''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)
def p_method_definition(self, p): '''method_definition : RPC NAME LPAR NAME RPAR RETURNS LPAR NAME RPAR''' p[0] = MethodDefinition(Name(LU.i(p, 2)), Name(LU.i(p, 4)), Name(LU.i(p, 8))) self.lh.set_parse_object(p[0], p)
def p_rvalue2(self, p): '''rvalue : NAME''' p[0] = Name(LU.i(p, 1)) self.lh.set_parse_object(p[0], p) p[0].deriveLex()
def p_message_extension(self, p): '''message_extension : EXTEND NAME LBRACE message_body RBRACE''' p[0] = MessageExtension(Name(LU.i(p, 2)), LU.i(p, 4)) self.lh.set_parse_object(p[0], p)
def p_option_rvalue2(self, p): '''option_rvalue : STRING_LITERAL''' p[0] = Literal(LU(p, 1))
def p_option_directive(self, p): '''option_directive : OPTION NAME EQ option_rvalue SEMI''' p[0] = OptionStatement(Name(LU.i(p, 2)), LU.i(p, 4)) self.lh.set_parse_object(p[0], p)
def p_rvalue3(self, p): '''rvalue : STRING_LITERAL''' p[0] = Name(LU.i(p, 1)) self.lh.set_parse_object(p[0], p) p[0].deriveLex()
def p_import_directive(self, p): '''import_directive : IMPORT STRING_LITERAL SEMI''' p[0] = ImportStatement(Literal(LU.i(p, 2))) self.lh.set_parse_object(p[0], p)
def p_field_definition(self, p): '''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)
def p_enum_field(self, p): '''enum_field : field_name EQ NUM SEMI''' p[0] = EnumFieldDefinition(LU.i(p, 1), LU.i(p, 3)) self.lh.set_parse_object(p[0], p)
def p_link_definition_with_reverse(self, p): '''link_definition_with_reverse : field_modifier link_type field_name policy_opt ARROW dotname slash_name colon_fieldname EQ field_id COLON reverse_id field_directives SEMI''' p[0] = LinkSpec( FieldDefinition(LU.i(p, 1), Name('int32'), LU.i(p, 3), LU.i(p, 4), LU.i(p, 10), [ FieldDirective(Name('type'), Name('link')), FieldDirective(Name('model'), LU.i(p, 6)) ] + srcPort(LU.i(p, 8)) + LU.i(p, 13)), LinkDefinition(LU.i(p, 2), LU.i(p, 3), LU.i(p, 6), LU.i(p, 7), LU.i(p, 8), reverse_id=LU.i(p, 12))) self.lh.set_parse_object(p[0], p)
def p_field_type2(self, p): '''field_type : dotname''' p[0] = DotName(LU.i(p, 1)) self.lh.set_parse_object(p[0], p) p[0].deriveLex()
def p_field_type(self, p): '''field_type : primitive_type''' p[0] = FieldType(LU.i(p, 1)) self.lh.set_parse_object(p[0], p)
def p_service_definition(self, p): '''service_definition : _SERVICE NAME LBRACE method_definition_opt RBRACE''' p[0] = ServiceDefinition(Name(LU.i(p, 2)), LU.i(p, 4)) self.lh.set_parse_object(p[0], p)
def p_rvalue(self, p): '''rvalue : NUM | TRUE | FALSE''' p[0] = LU.i(p, 1)
def p_package_directive(self, p): '''package_directive : PACKAGE dotname SEMI''' p[0] = PackageStatement(Name(LU.i(p, 2))) self.lh.set_parse_object(p[0], p)
def p_enum_definition(self, p): '''enum_definition : ENUM NAME LBRACE enum_body_opt RBRACE''' p[0] = EnumDefinition(Name(LU.i(p, 2)), LU.i(p, 4)) self.lh.set_parse_object(p[0], p)
def p_option_rvalue(self, p): '''option_rvalue : NUM | TRUE | FALSE''' p[0] = LU(p, 1)
def p_extensions_to2(self, p): '''extensions_to : NUM''' p[0] = LU.i(p, 1)
def p_option_rvalue3(self, p): '''option_rvalue : NAME''' p[0] = Name(LU.i(p, 1))
def p_extensions_definition(self, p): '''extensions_definition : EXTENSIONS NUM TO extensions_to SEMI''' p[0] = ExtensionsDirective(LU.i(p, 2), LU.i(p, 4)) self.lh.set_parse_object(p[0], p)
def p_protofile(self, p): '''protofile : statements''' p[0] = ProtoFile(LU.i(p, 1)) self.lh.set_parse_object(p[0], p)
def p_field_directive(self, p): '''field_directive : NAME EQ rvalue''' p[0] = FieldDirective(Name(LU.i(p, 1)), LU.i(p, 3)) self.lh.set_parse_object(p[0], p)