[antlr-interest] Line continuation character problem

Anthony Youngman Anthony.Youngman at ECA-International.com
Thu Jun 10 03:08:42 PDT 2004


Okay. First things first - you NEED to look up that ESC example in the
manual I gave you. But now let's try to rewrite your rule.
 
STRING_LITERAL
// string literals - the only token that can be split with an '&'.
options {paraphrase = "a string";}
 : '"'! (AMP{token.setlen(token.getlen()-3);}|{greedy=false;}.)* '"'!
 ;
 
What this is doing is first it finds your " to start the string. Then it
looks for either an AMP, or anything that doesn't match your final "
(that's the point of the "greedy = false" - the . won't eat any token
that matches the following token-match). And when it finds an AMP, the
setlen/getlen deletes it from the STRING_LITERAL that it's building.
 
This probably won't compile straight off - I've almost certainly got my
cases wrong, and there's probably other minor faults. But I hope I've
explained clearly what it's doing, and you should be able easily to
clean it up.
 
Cheers,
Wol
 
________________________________

From: Craig Barker [mailto:cb at phoebussoftware.com] 
Sent: 10 June 2004 10:49
To: antlr-interest at yahoogroups.com
Subject: RE: [antlr-interest] Line continuation character problem


Hi Anthony,
 
Thanks for your input to this, it's been doing my head in!
 
Indeed, I've got the following worked out so far:

options {
 exportVocab=PVocab;
 k=3;
filter=AMP;
}
 
protected
AMP
//an & and line break.
 :  '&' '\r' '\n' {System.out.println("& HIT!");newline();}
 ; 
 
STRING_LITERAL
// string literals - the only token that can be split with an '&'.
options {paraphrase = "a string";}
 : '"'! (~('"'))* '"'!
 ;
 
This solves the first problem very well but the second point is that I
still want the STRING_LITERAL token to be passed as one token, even when
it's been split over 2 or more lines.
 
ie:
 
getrec(tag,"select * from acct,x__ir &
where acct001 = x__ir001 and &
x__ir006 = 'V'")
 
Effectively I need the 3 lines of strings to be treated as 1 single
STRING_LITERAL token, eg:
 
getrec(tag,"select * from acct,x__ir where acct001 = x__ir001 and
x_ir006 = 'V'")
 
and unfortuately shaving the last 3 characters wouldn't always work.
 
Again many thanks for your help,
 
Cheers
 
Craig


****************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 8272 5300, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

****************************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20040610/49590658/attachment.html


More information about the antlr-interest mailing list