[antlr-interest] Bug when using multi-parameter generics as return values?
Johannes Luber
jaluber at gmx.de
Thu Jul 31 03:23:33 PDT 2008
Niemeijer, R.A. schrieb:
> Hello everyone,
>
> I have a question about using generics as return values (with C# as the
> target language). When the generic has only one parameter everything
> works correctly, e.g.
>
> elements[Scene scene] returns [IEnumerable<BuildingElement> elems]
>
> : ELEMS p=piece { $elems =
> (IEnumerable<BuildingElement>)p.piece.Eval(scene); }
> ;
>
> However, when I want to return a generic with more than one parameter,
> e.g. a Func<BuildingElement, int>, the code generation screws up: it
> splits the type at the comma, giving one line with Func<BuildingElement
> and one with int>, which obviously results in a compile error.
>
> It is possible to get around this problem with using-statements, such as
>
> using FBI = System.Func<BuildingElement, int>;
>
> and then saying returns [FBI func]. However, this is far from elegant,
> especially when you have a lot of different types. Is there a correct
> way to do this or if not, has this bug been fixed since Antlr 3.0.1?
>
> Thanks in advance.
Try the newest beta. I believe some bugs regarding the handling of
generics have been fiyed. Possibly you may need to escape <, >, [ and ]
with a \.
Johannes
More information about the antlr-interest
mailing list