Alexey,
I've spent a little time getting your example grammar modification to work. In the tokens section, I added:
// --- EJBQL keywords --- OBJECT="object";
In the rules, I added:
selectClause
: SELECT^ // NOTE: The '^' after a token causes the corresponding AST node to be the root of the sub-tree.
(DISTINCT)? ( selectedPropertiesList | newExpression | selectObject )
;
selectObject : OBJECT^ OPEN! identifier CLOSE! ;
Just as you had experienced, my changes made the HqlParserTest fail. Welcome to parser land!
The identPrimary rule fails because the new keyword is recognized in *three* tokens of lookahead in this context. Since the parser needs the lookahead to resolve the optional DOT^ "class" clause in primaryExpression, the weakKeywords() method would not work properly no matter where you put it. So, I changed identPrimary to allow the new keyword after the DOT and then placed a semantic action there to mutate the OBJECT node into an IDENT node if it sees it.
// identifier, followed by member refs (dot ident), or method calls.
identPrimary
: identifier
( options { greedy=true; } : DOT^ ( identifier | ELEMENTS | o:OBJECT { #o.setType(IDENT); } ) )*
( options { greedy=true; } : ( op:OPEN^ { #op.setType(METHOD_CALL);} exprList CLOSE! ) )?
// Also allow special 'aggregate functions' such as count(), avg(), etc.
| aggregate
;
In general, we need to be very careful when adding keywords to the language, as there can be many seemingly strange side effects.
Joshua Davis wrote:
You are correct, this would affect 'java.lang.Object' because the OBJECT token is being used to branch into the new rule.
I was going to look into modifying 'path' to force the token after the dot to be an identifier, no matter what it is, which is similar to what weakKeywords() does.
--- Alexey Loubyansky <[EMAIL PROTECTED]> wrote:
sun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownOk, thanks. I also see you have some workarounds using weakKeywords and handleIdentifierError but haven't yet figured it out how to fix this. Note, this also affects java.lang.Object.
-----Original Message-----keywords to ql
From: Joshua Davis [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 15, 2004 4:02 PM
To: Alexey Loubyansky
Cc: [EMAIL PROTECTED]
Subject: RE: [Hibernate] introductions of new
Aha... So you've introduced a new keyword, andalso a new
clause in the the select expression with the newkeyword
being the token that allows the parser todistinguish between
I'll havethe two branches.
I've got some ideas about what the problem is, but
to test some things out to make sure. I should beable to do
thethat tonight.
--- Alexey Loubyansky <[EMAIL PROTECTED]> wrote:
I did modify hql.g. I.e. added OBJECT token and
selectClause
: SELECT^ // NOTE: The '^' after a token causes
sub-tree.corresponding AST node to be the root of the
newExpression |(DISTINCT)? ( selectedPropertiesList |
the test passes.selectObject) ;
selectObject : OBJECT^ OPEN! identifier CLOSE! ;
If I comment out selectObject in selectClause,
sayingThanks.
-----Original Message-----keywords to ql
From: Joshua Davis [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 15, 2004 2:13 PM
To: Alexey Loubyansky
Cc: [EMAIL PROTECTED]
Subject: Re: [Hibernate] introductions of new
Actually, the HQL parser is capable of usingkeywords as
identifiers in some contexts. I'm not sure what you're
fail?here, have
you modified
the grammar and this caused HqlParserTest to
areIf that
is the casemodified grammar that is
then there may be something wrong with the
preventing the 'keyword as identifier' fromworking. If
not, then I'm not really sure what the problem is.
Alexey Loubyansky wrote:
Hi Joshua & Steve,
I started working on the EJBQL syntaxes that
wherenot
supported yet. Icause some
will need to add some new keywords that might
existing testsfollowing test to fail
to fail. E.g. adding "object" causes the
input: ->from org.hibernate.test.Bar bar
nearbar.object.id = ? and
bar.object.class = ?<-
msg=HQL syntax error : unexpected token: .
testUnitTestHql(org.hibernate.test.hql.HqlParserTest)junit.frline 1, column 42
There was 1 failure:
1)
occurredamework.As
s
ertionFailedError: At least one error
org.hibernate.test.hql.HqlParserTest.doParse(HqlParserTest.java:990)during parsing!
expected:<0> but was:<2>
at
org.hibernate.test.hql.HqlParserTest.parse(HqlParserTest.java:966)at
org.hibernate.test.hql.HqlParserTest.testUnitTestHql(HqlParseat
sun.reflect.NativeMethodAccessorImpl.invoke0(NativerTest.java:
663)
at
sun.reflect.NativeMethodAccessorImpl.invoke(UnknownMethod)
at
Source)
at
-------------------------------------------------------org.hibernate.test.AllTests.main(AllTests.java:120)Source)
at
wayAm I missing something or there is really no
paths?to fix this
except for
disallowing the use of 'object' even in
-------------------------------------------------------Thanks.
GuideSF email is sponsored by - The IT Product
https://lists.sourceforge.net/lists/listinfo/hibernate-develRead honest & candid_______________________________________________
users.reviews on hundreds of IT Products from real
hype. StartDiscover which products truly live up to the
reading now.
http://productguide.itmanagersjournal.com/
hibernate-devel mailing list
[EMAIL PROTECTED]
Read honestSF email is sponsored by - The IT Product Guide
& candidusers.
reviews on hundreds of IT Products from real
hype.Discover which products truly live up to the
Start reading now. http://productguide.itmanagersjournal.com/ _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED]
=== message truncated ===
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel