[antlr-interest] sql keyword issue
Graham Wideman
gwlist at grahamwideman.com
Sun Sep 27 00:57:03 PDT 2009
Hi Min,
I'm a little puzzled at your example, but I'll take a crack at it.
1. "we have a statement CREATE USER, where USER is not a keyword,"
... except that you have made a separate USER token. So likely the error results from this: where the parser is looking for an Identifier in rule userItem, instead the next token returned by the lexer is a USER token.
There are solutions to the problem of keyword-as-identifier here:
http://www.antlr.org/wiki/pages/viewpage.action?pageId=1741
2. That said, I'm not clear on how uppercase 'USER' is matching your input which includes lower case 'user'. Perhaps you are using some case-insensitive strategy here (not shown)?
-- Graham
At 9/27/2009 01:14 PM, Min Zhou wrote:
Hi all,
I am a newbie, using antlr to parse sql language. we have a statement CREATE USER, where USER is not a keyword, so that
CREATE TABLE TBL(USER int) is acceptable. But my parser came across a problem:
mydb> create table tbl(user int);
FAILED: Parse Error: line 1:17 mismatched input 'user' expecting Identifier in column specification
here is grammar snippets
createUserStatement
@init { msgs.push("create user statement"); }
@after { msgs.pop(); }
: KW_CREATE USER userItem (COMMA userItem)*
-> ^(TOK_CREATEUSER userItem+)
;
userItem
@init { msgs.push("user item"); }
@after { msgs.pop(); }
: (Identifier (KW_IDENTIFIED KW_BY StringLiteral)?)
-> ^(TOK_USER Identifier StringLiteral?)
;
USER: 'USER'
Identifier
:
(Letter | Digit) (Letter | Digit | '_')*
| '`' RegexComponent+ '`'
;
anyone help me on this?
Thanks in advance!
More information about the antlr-interest
mailing list