@@ -169,20 +169,25 @@ def __repr__(self):
169169
170170class BabelTagRef (_Element ):
171171
172- def __init__ (self , path , lineno , lexpos , tag , union_name = None ):
172+ def __init__ (self , path , lineno , lexpos , tag , union_name = None , ns = None ):
173173 """
174174 Args:
175175 tag (str): Name of the referenced type.
176- union_name (str): The name of the union the tag belongs to.
176+ union_name (Optional[str]): The name of the union the tag belongs
177+ to.
178+ ns (Optional[str]): Namespace that referred type is a member of.
179+ If none, then refers to the current namespace.
177180 """
178181 super (BabelTagRef , self ).__init__ (path , lineno , lexpos )
179182 self .tag = tag
180183 self .union_name = union_name
184+ self .ns = ns
181185
182186 def __repr__ (self ):
183- return 'BabelTagRef({!r}, {!r})' .format (
187+ return 'BabelTagRef({!r}, {!r}, {!r} )' .format (
184188 self .tag ,
185189 self .union_name ,
190+ self .ns ,
186191 )
187192
188193class BabelField (_Element ):
@@ -526,14 +531,6 @@ def p_foreign_type_ref(self, p):
526531 ns = p [1 ],
527532 )
528533
529- def p_tag_ref (self , p ):
530- """tag_ref : ID DOT ID
531- | ID"""
532- if len (p ) > 2 :
533- p [0 ] = BabelTagRef (self .path , p .lineno (1 ), p .lexpos (1 ), p [3 ], p [1 ])
534- else :
535- p [0 ] = BabelTagRef (self .path , p .lineno (1 ), p .lexpos (1 ), p [1 ])
536-
537534 # --------------------------------------------------------------
538535 # Structs
539536 #
@@ -635,7 +632,7 @@ def p_field_deprecation(self, p):
635632
636633 def p_default_option (self , p ):
637634 """default_option : EQ primitive
638- | EQ tag_ref
635+ | EQ short_tag_ref
639636 | empty"""
640637 if p [1 ]:
641638 if isinstance (p [2 ], BabelTagRef ):
@@ -657,6 +654,10 @@ def p_field(self, p):
657654 if has_docstring :
658655 p [0 ].set_doc (p [7 ])
659656
657+ def p_short_tag_ref (self , p ):
658+ 'short_tag_ref : ID'
659+ p [0 ] = BabelTagRef (self .path , p .lineno (1 ), p .lexpos (1 ), p [1 ])
660+
660661 # --------------------------------------------------------------
661662 # Unions
662663 #
@@ -763,12 +764,21 @@ def p_attr_fields_add(self, p):
763764 p [0 ].append (p [2 ])
764765
765766 def p_attr_field (self , p ):
766- 'attr_field : ID EQ primitive NEWLINE'
767+ """attr_field : ID EQ primitive NEWLINE
768+ | ID EQ tag_ref NEWLINE"""
767769 if p [3 ] is BabelNull :
768770 p [0 ] = (p [1 ], None )
769771 else :
770772 p [0 ] = (p [1 ], p [3 ])
771773
774+ def p_tag_ref (self , p ):
775+ """tag_ref : ID DOT ID DOT ID
776+ | ID DOT ID"""
777+ if len (p ) > 4 :
778+ p [0 ] = BabelTagRef (self .path , p .lineno (1 ), p .lexpos (1 ), p [5 ], p [3 ], p [1 ])
779+ else :
780+ p [0 ] = BabelTagRef (self .path , p .lineno (1 ), p .lexpos (1 ), p [3 ], p [1 ])
781+
772782 # --------------------------------------------------------------
773783 # Doc sections
774784 #
0 commit comments