@@ -211,7 +211,7 @@ func (l *ParseTreeListener) parseCompleteType(ctx *Type_defContext, t *Type) {
211211 }
212212 } else if f .Common_type_field () != nil {
213213 // Regular field
214- typeField .FieldType = parseCommonFieldType (f .Common_type_field ().Common_field_type ())
214+ typeField .FieldType = l . parseCommonFieldType (f .Common_type_field ().Common_field_type ())
215215 typeField .Name = f .Common_type_field ().IDENTIFIER ().GetText ()
216216
217217 // Default value
@@ -243,6 +243,7 @@ func (l *ParseTreeListener) parseCompleteType(ctx *Type_defContext, t *Type) {
243243 }
244244}
245245
246+ // parseRedefinedType handles redefined types, including generic types.
246247func (l * ParseTreeListener ) parseRedefinedType (ctx * Type_defContext , t * Type ) {
247248 t .Redefined = & RedefinedType {
248249 Name : ctx .IDENTIFIER (1 ).GetText (),
@@ -263,13 +264,13 @@ func (l *ParseTreeListener) parseRedefinedType(ctx *Type_defContext, t *Type) {
263264 if g .Container_type () != nil {
264265 if g .Container_type ().Map_type () != nil {
265266 kt := g .Container_type ().Map_type ().Key_type ().GetText ()
266- vt := parseValueType (g .Container_type ().Map_type ().Value_type ())
267+ vt := l . parseValueType (g .Container_type ().Map_type ().Value_type ())
267268 t .Redefined .GenericType = MapType {
268269 Key : kt ,
269270 Value : vt ,
270271 }
271272 } else if g .Container_type ().List_type () != nil {
272- vt := parseValueType (g .Container_type ().List_type ().Value_type ())
273+ vt := l . parseValueType (g .Container_type ().List_type ().Value_type ())
273274 t .Redefined .GenericType = ListType {
274275 Item : vt ,
275276 }
@@ -283,7 +284,7 @@ func (l *ParseTreeListener) parseRedefinedType(ctx *Type_defContext, t *Type) {
283284
284285// parseCommonFieldType resolves type definitions inside type fields.
285286// It distinguishes between built-in types, user-defined types, and containers.
286- func parseCommonFieldType (ctx ICommon_field_typeContext ) TypeDefinition {
287+ func ( l * ParseTreeListener ) parseCommonFieldType (ctx ICommon_field_typeContext ) TypeDefinition {
287288 if ctx .TYPE_ANY () != nil {
288289 return AnyType {}
289290 }
@@ -305,13 +306,13 @@ func parseCommonFieldType(ctx ICommon_field_typeContext) TypeDefinition {
305306 if ctx .Container_type () != nil {
306307 if ctx .Container_type ().Map_type () != nil {
307308 kt := ctx .Container_type ().Map_type ().Key_type ().GetText ()
308- vt := parseValueType (ctx .Container_type ().Map_type ().Value_type ())
309+ vt := l . parseValueType (ctx .Container_type ().Map_type ().Value_type ())
309310 return MapType {
310311 Key : kt ,
311312 Value : vt ,
312313 }
313314 } else if ctx .Container_type ().List_type () != nil {
314- vt := parseValueType (ctx .Container_type ().List_type ().Value_type ())
315+ vt := l . parseValueType (ctx .Container_type ().List_type ().Value_type ())
315316 return ListType {
316317 Item : vt ,
317318 }
@@ -321,7 +322,7 @@ func parseCommonFieldType(ctx ICommon_field_typeContext) TypeDefinition {
321322}
322323
323324// parseValueType resolves value types inside container types.
324- func parseValueType (ctx IValue_typeContext ) TypeDefinition {
325+ func ( l * ParseTreeListener ) parseValueType (ctx IValue_typeContext ) TypeDefinition {
325326 if ctx .Base_type () != nil {
326327 return BaseType {
327328 Name : strings .TrimRight (ctx .Base_type ().GetText (), "?" ),
@@ -337,13 +338,13 @@ func parseValueType(ctx IValue_typeContext) TypeDefinition {
337338 if ctx .Container_type () != nil {
338339 if ctx .Container_type ().Map_type () != nil {
339340 kt := ctx .Container_type ().Map_type ().Key_type ().GetText ()
340- vt := parseValueType (ctx .Container_type ().Map_type ().Value_type ())
341+ vt := l . parseValueType (ctx .Container_type ().Map_type ().Value_type ())
341342 return MapType {
342343 Key : kt ,
343344 Value : vt ,
344345 }
345346 } else if ctx .Container_type ().List_type () != nil {
346- vt := parseValueType (ctx .Container_type ().List_type ().Value_type ())
347+ vt := l . parseValueType (ctx .Container_type ().List_type ().Value_type ())
347348 return ListType {
348349 Item : vt ,
349350 }
@@ -352,6 +353,71 @@ func parseValueType(ctx IValue_typeContext) TypeDefinition {
352353 panic (fmt .Errorf ("unknown type: %s" , ctx .GetText ()))
353354}
354355
356+ func (l * ParseTreeListener ) ExitOneof_def (ctx * Oneof_defContext ) {
357+ o := OneOf {
358+ Name : ctx .IDENTIFIER ().GetText (),
359+ Position : Position {
360+ Start : ctx .GetStart ().GetLine (),
361+ Stop : ctx .GetStop ().GetLine (),
362+ },
363+ Comments : Comments {
364+ Top : l .topComment (ctx .GetStart ()),
365+ },
366+ }
367+
368+ l .parseOneOfType (ctx , & o )
369+
370+ l .Document .OneOfs = append (l .Document .OneOfs , o )
371+ }
372+
373+ // parseOneOfType handles oneof types, including fields and annotations.
374+ func (l * ParseTreeListener ) parseOneOfType (ctx * Oneof_defContext , o * OneOf ) {
375+
376+ // Process all oneof fields
377+ for _ , f := range ctx .AllOneof_field () {
378+ typeField := TypeField {
379+ Position : Position {
380+ Start : f .GetStart ().GetLine (),
381+ Stop : f .GetStop ().GetLine (),
382+ },
383+ Comments : Comments {
384+ Top : l .topComment (f .GetStart ()),
385+ Right : l .rightComment (f .GetStop ()),
386+ },
387+ }
388+
389+ // Regular field
390+ typeField .FieldType = l .parseCommonFieldType (f .Common_type_field ().Common_field_type ())
391+ typeField .Name = f .Common_type_field ().IDENTIFIER ().GetText ()
392+
393+ // Default value
394+ if f .Common_type_field ().Const_value () != nil {
395+ s := f .Common_type_field ().Const_value ().GetText ()
396+ typeField .Default = & s
397+ }
398+
399+ // Annotations
400+ if f .Common_type_field ().Type_annotations () != nil {
401+ for _ , aCtx := range f .Common_type_field ().Type_annotations ().AllAnnotation () {
402+ a := Annotation {
403+ Key : aCtx .IDENTIFIER ().GetText (),
404+ Position : Position {
405+ Start : aCtx .GetStart ().GetLine (),
406+ Stop : aCtx .GetStop ().GetLine (),
407+ },
408+ }
409+ if aCtx .Const_value () != nil {
410+ s := aCtx .Const_value ().GetText ()
411+ a .Value = & s
412+ }
413+ typeField .Annotations = append (typeField .Annotations , a )
414+ }
415+ }
416+
417+ o .Fields = append (o .Fields , typeField )
418+ }
419+ }
420+
355421// ExitRpc_def handles RPC definitions, including request/response
356422// types and annotations.
357423func (l * ParseTreeListener ) ExitRpc_def (ctx * Rpc_defContext ) {
0 commit comments