[antlr-interest] how to match any char between two string?
陈凯成
bestgembler at hotmail.com
Sat May 16 08:39:46 PDT 2009
Hi!
I hava to intercept a expression between two string, and then send to another application.
like a Java regex, for example:
// -------------------------------------------------------------------------
// Java Code Begin
// -------------------------------------------------------------------------
String regex = "select\\s+((.)+)\\s+from";
Pattern p = Pattern.complie(regex);
Matcher m = p.matcher("select stu.id as 'Student ID', stu.name as 'Student Name' from");
String select = null;
if(m.find()){
select = m.group(1);
}
System.out.println(select);// print [stu.id as 'Student ID', stu.name as 'Student Name']
send(select);// send to another application.
// -------------------------------------------------------------------------
// Java Code End
// -------------------------------------------------------------------------
I try to write a sample grammar file, but it dosen't works.
// -------------------------------------------------------------------------
// Grammar File Begin
// -------------------------------------------------------------------------
start : 'select' WS SELECT WS 'from';
SELECT : (.)+ {
System.out.println(getText());
send(getText());
};
WS : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+;
// -------------------------------------------------------------------------
// Grammar File End
// -------------------------------------------------------------------------
I get a error message as follow when I generate code:
// -------------------------------------------------------------------------
// Error Message Begin
// -------------------------------------------------------------------------
[23:31:49] error(208): Sql.g:28:1: The following token definitions can never be matched because prior tokens match the same input: WS
// -------------------------------------------------------------------------
// Message Begin
// -------------------------------------------------------------------------
Thanks a lot!
---------------------------------
THE
POWER
OF
JAVA
_________________________________________________________________
上MClub和Messenger好友一起都市寻宝!
http://club.msn.cn/?from=1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090516/79bbce88/attachment.html
More information about the antlr-interest
mailing list