[antlr-interest] Empty Quoted String Literal

Bart Kiers bkiers at gmail.com
Wed Jul 27 14:27:39 PDT 2011


A quick test with Mono confirmed it, @"""" is just a single quote:

    Console.WriteLine(@"""");

prints 1 quote! That's the problem.

Bart.


On Wed, Jul 27, 2011 at 11:25 PM, Bart Kiers <bkiers at gmail.com> wrote:

> Richard,
>
> Note that I am a C# illiterate, but, isn't the C# literal:
>
> @""""
>
>
> only just a single quote? If so, then it is no wonder you're getting
> errors. Parsing:
>
> WhitespaceInSymbolsLexer lexer = new WhitespaceInSymbolsLexer(new
> ANTLRStringStream("\""));
>
>
> will also produce the error 'line 1:1 mismatched character '<EOF>'
> expecting '"'' with me (of course) since a single quote is no valid token.
>
> Regards,
>
> Bart.
>
>
>
> On Wed, Jul 27, 2011 at 11:14 PM, G. Richard Bellamy <
> rbellamy at pteradigm.com> wrote:
>
>> Bart,
>>
>> When I escape the quotes things work on my end as well - you'll note
>> that I'm passing a set of non-escaped quotes... (C# Verbatim String), so
>> you'll not be able to test this on your end (since Java doesn't have an
>> equivalent to the Verbatim String).
>>
>> Thanks again.
>>
>> -rb
>>
>> On 7/27/2011 2:10 PM, Bart Kiers wrote:
>> > Hi Richard,
>> >
>> > Both ANTLRWorks' debugger, and my Java test rig:
>> >
>> >     import org.antlr.runtime.*;
>> >
>> >     public class Main {
>> >       public static void main(String[] args) throws Exception {
>> >         WhitespaceInSymbolsLexer lexer = new
>> >     WhitespaceInSymbolsLexer(new ANTLRStringStream("\"\""));
>> >         WhitespaceInSymbolsParser parser = new
>> >     WhitespaceInSymbolsParser(new CommonTokenStream(lexer));
>> >         parser.compileUnit();
>> >       }
>> >     }
>> >
>> >
>> > produce no errors when parsing "" (2 double quotes) as input:
>> >
>> >     bart at hades:~/Programming/ANTLR/Demos/WhitespaceInSymbols$ java -cp
>> >     antlr-3.3.jar org.antlr.Tool WhitespaceInSymbols.g
>> >     bart at hades:~/Programming/ANTLR/Demos/WhitespaceInSymbols$ javac
>> >     -cp antlr-3.3.jar *.java
>> >     bart at hades:~/Programming/ANTLR/Demos/WhitespaceInSymbols$ java -cp
>> >     .:antlr-3.3.jar Main
>> >     bart at hades:~/Programming/ANTLR/Demos/WhitespaceInSymbols$
>> >
>> >
>> > Then there must be something going differently in the CSharp3 target
>> > than in the Java target (note that I am not able to test the CSharp3
>> > target here...).
>> >
>> > Regards,
>> >
>> > Bart.
>> >
>> >
>> > On Wed, Jul 27, 2011 at 11:01 PM, G. Richard Bellamy
>> > <rbellamy at pteradigm.com <mailto:rbellamy at pteradigm.com>> wrote:
>> >
>> >     Sam, Bart & Jim, I really appreciate your help on this.
>> >
>> >     Here's a more complete example, without the greedy confusion. I'm
>> >     including the combined grammar and a test rig.
>> >
>> >     I get: CombinedLexer:line 1:2 mismatched character '<EOF>'
>> >     expecting '"'
>> >     just before a NullReferenceException.
>> >
>> >     GRAMMAR:
>> >     ----------------------------
>> >     grammar Combined;
>> >
>> >     options {
>> >     language=CSharp3;
>> >     TokenLabelType=CommonToken;
>> >     output=AST;
>> >     ASTLabelType=CommonTree;
>> >     }
>> >
>> >     @lexer::namespace{StringLiteralLexerTest}
>> >     @parser::namespace{StringLiteralLexerTest}
>> >
>> >     /*
>> >     * Parser Rules
>> >     */
>> >
>> >     public
>> >     compileUnit
>> >     : STRING
>> >     ;
>> >
>> >     /*
>> >     * Lexer Rules
>> >     */
>> >     STRING : '"' ('""' | ~'"')* '"';
>> >
>> >     TEST RIG:
>> >     ------------------------------
>> >     static void Main()
>> >     {
>> >     CombinedLexer lexer = new CombinedLexer(new
>> ANTLRStringStream(@""""));
>> >     //lexer.TraceDestination = new
>> >     ConsoleTextWriter(typeof(CombinedLexer));
>> >
>> >     CommonTokenStream tokenStream = new CommonTokenStream(lexer);
>> >
>> >     CombinedParser parser = new CombinedParser(tokenStream);
>> >     //parser.TraceDestination = new
>> >     ConsoleTextWriter(typeof(CombinedParser));
>> >
>> >     CommonTree parseTree = parser.compileUnit().Tree;
>> >     Console.WriteLine(parseTree.ToStringTree());
>> >     }
>> >
>> >     List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> >     Unsubscribe:
>> >
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>> >
>> >
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>


More information about the antlr-interest mailing list