Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Antlr newbie question: Ignoring tokens, or a better way to do this:

Thread view: 
Daniel Pitts - 27 Sep 2007 22:38 GMT
Basically,  my input is something like:

something{

value: >>>

This is the text

<<<

}

I want a rule that can give me as a value "This is the text".

I've tried:

LQS: LQSS *options {greedy=false;} : .)* LQSE;

LQSS : '>>>\n';

LQSE: '\n<<<';

and I've tried using channel=HIDDEN on LQSS and LQSE, but then I get
errors while parsing other parts of my source.

I have a work around, but its ugly.  I have a rule

lstring returns [String value]: LQS {value=
$LQS.getText().replaceFirst(">>>\n","").replaceFirst("\n<<<$", "");};

but that seems like an awful big hack.  Any suggestions?

Thanks,
Daniel.
P.S. I've also sent this message to the antlr-interest mailing list.
Roedy Green - 27 Sep 2007 22:47 GMT
If you can't crack this, try JavaCC. There are a ton of examples out
there plus a textbook.

see http://mindprod.com/jgloss/javacc.html

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Daniel Pitts - 28 Sep 2007 02:02 GMT
On Sep 27, 2:47 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> If you can't crack this, try JavaCC. There are a ton of examples out
> there plus a textbook.
[quoted text clipped - 4 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

I have found a "better" way, but I hope its still not the "right" way.

LQS:  LQSS {tokenStartCharIndex=getCharIndex();}(options
{greedy=false;} : . )*{text = getText();}LQSE;
LQSS: ('>>>' SPACE* CRLF);
LQSE: CRLF SPACE*  '<<<';

That this does: Sets the token start index to the "current" index
after it matches LQSS, and sets the text permanently to what it is
before matching the LQSE.

Not exactly what I call elegant.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.