[antlr-interest] Bug when using multi-parameter generics as return values?

Niemeijer, R.A. r.a.niemeijer at tue.nl
Thu Jul 31 05:07:52 PDT 2008


I switched to AntlrWorks 1.2b5 and Antlr 3.1b2.
Unfortunately this causes two problems.

The generated code for both the lexer and parser contains a group of
code that looks like this (the real version is longer):

const string DFA3_eotS =
        "\1\uffff\1\17\31\uffff";
    const string DFA3_eofS =
        "\33\uffff";
    const string DFA3_minS =
 
"\1\52\1\105\10\uffff\1\125\2\uffff\1\106\2\uffff\1\116\2\uffff"+
        "\1\103\1\61\2\105\4\uffff";

This causes compile errors. These can be overcome by putting @'s in
front of the strings, but that is not something you want to do after
every code generation.

Also, the code

var input = sequence.Select(p => p.ParserText).Flatten();
var lexer = new PuzzleLexer(new ANTLRStringStream(input));

now throws a TypeInitializationException with an InnerException of
"Index was outside the bounds of the array."

I have the suspicion that both of these have to do with encoding, but
I'm not sure. Does anyone happen to know the solution to these problems?

Thanks.

-----Original Message-----
From: Johannes Luber [mailto:jaluber at gmx.de] 
Sent: donderdag 31 juli 2008 12:24
To: Niemeijer, R.A.
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Bug when using multi-parameter generics as
return values?

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