Jim,
I tried that a couple of times and once it didn't give the error message.
However, I opened the output file GroupLexer.m and I discovered that regardless
of the syntax error message, it is actually generating the code and with or
without a single escape ('%c' or '\%c') I get the correct output '%c'. It is
just that it is generating an error message that caused me to think it wasn't
generating the code.
Alan
---
Alan Condit
1085 Tierra Ct.
Woodburn, OR 97071
Email -- [email protected]
Home-Office (503) 982-0906
On Feb 3, 2012, at 8:59 AM, Jim Idle wrote:
> You probably have to double escape it:
>
> \\\%
>
> Jim
>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]]
>> On Behalf Of Alan Condit
>> Sent: Friday, February 03, 2012 8:23 AM
>> To: Terence Parr
>> Cc: ANTLR-dev Dev
>> Subject: Re: [antlr-dev] ANTLR barfs on %c in format string in ObjC
>>
>> I tried changing the character after the escaped \% to d, f, s, x, @,
>> all valid ObjC format options (in fact all but @ are valid for 'C' as
>> well. They all generated the same syntax error message (except for the
>> format character).
>>
>> This error is not occurring in "a group file" but the "group.g" grammar
>> for ST4. Still as Ter says, it appears to be an error in an ANTLR
>> grammar not passing the escaped % but rather seeing it as the start of
>> a string template.
>>
>> Now this is really wierd, I opened the file in ANTLRWorks and just
>> tried generating the code after changing the character after the
>> escape. I tried about four times on the fourth try it accepted \%d.
>> Then I exited out of ANTLRWorks and reloaded the file with the \%d in
>> it and it failed, so I cycled through a bunch more changing trying to
>> generate the code after each change. On about the fourth change it
>> accepted \%c.
>>
>> Then I tried the same thing again and couldn't get anything but the
>> syntax error after repeated trys.
>>
>> Alan
>> ---
>>
>> Alan Condit
>> 1085 Tierra Ct.
>> Woodburn, OR 97071
>>
>> Email -- [email protected]
>> Home-Office (503) 982-0906
>>
>> On Feb 2, 2012, at 10:58 AM, Terence Parr wrote:
>>
>>> "@lexer::methods {" tells me that it is an action within an antlr
>>> grammar not group file. still, \% should work! :( Ter On Feb 2, 2012,
>>> at 10:47 AM, Alan Condit wrote:
>>>
>>>> Ter,
>>>>
>>>> It is the group.g file from ST4 with option {language=ObjC}; I have
>> tried it with the escape and without and still get the same error
>> message. I have inserted the portion of the file below.
>>>>
>>>> Alan
>>>>
>>>> @lexer::methods {
>>>> @synthesize group;
>>>>
>>>> - (void) reportError:(RecognitionException *)e {
>>>> NSString *msg = nil;
>>>> if ( [e isKindOfClass:[NoViableAltException class]] ) { #pragma
>>>> error fix formatting
>>>> msg = [NSString stringWithFormat:@"invalid character '\%c'",
>> [input LA:1]];
>>>> }
>>>> else if ( [e isKindOfClass:[MismatchedTokenException class]] &&
>> ((MismatchedTokenException *)e).expecting=='"' ) {
>>>> msg = @"unterminated string";
>>>> }
>>>> else {
>>>> msg = [self getErrorMessage:e TokenNames:[self
>> getTokenNames]];
>>>> }
>>>> [group.errMgr groupSyntaxError:SYNTAX_ERROR srcName:[self
>>>> getSourceName] e:e msg:msg]; }
>>>>
>>>> - (NSString *) getSourceName
>>>> {
>>>> return [super getSourceName];
>>>> }
>>>>
>>>> }
>>>>
>>>> ---
>>>>
>>>> Alan Condit
>>>> 1085 Tierra Ct.
>>>> Woodburn, OR 97071
>>>>
>>>> Email -- [email protected]
>>>> Home-Office (503) 982-0906
>>>>
>>>> On Feb 2, 2012, at 9:42 AM, Terence Parr wrote:
>>>>
>>>>> that error message sounds like it is coming from ANTLR not ST. Are
>> you sure you are not using an action with % in it within an ANTLR
>> grammar or something? Hmm.% by itself should be no problem without an
>> escape in a group file.
>>>>>
>>>>> does this happen at load time when you run ANTLR with an ObjC
>> targeted grammar?
>>>>> T
>>>>> On Feb 2, 2012, at 8:58 AM, Alan Condit wrote:
>>>>>
>>>>>> In trying to build the error message string in group.g I use:
>>>>>> msg = [NSString stringWithFormat:@"invalid character '\%c'",
>>>>>> [input LA:1]]; but I get invalid StringTemplate % shorthand syntax
>> '%c'.
>>>>>>
>>>>>> This is a valid format string. What is going on?
>>>>>>
>>>>>> Alan
>>>>>> ---
>>>>>>
>>>>>> Alan Condit
>>>>>> 1085 Tierra Ct.
>>>>>> Woodburn, OR 97071
>>>>>>
>>>>>> Email -- [email protected]
>>>>>> Home-Office (503) 982-0906
>>>>>>
>>>>>> _______________________________________________
>>>>>> antlr-dev mailing list
>>>>>> [email protected]
>>>>>> http://www.antlr.org/mailman/listinfo/antlr-dev
>>>>>
>>>>
>>>
>>
>> _______________________________________________
>> antlr-dev mailing list
>> [email protected]
>> http://www.antlr.org/mailman/listinfo/antlr-dev
> _______________________________________________
> antlr-dev mailing list
> [email protected]
> http://www.antlr.org/mailman/listinfo/antlr-dev
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev