Hi,

Now when we are adding EJBQL support is there a "easy" (read not to hacky) way
of e.g. letting the parser complain if a user is actually using HQL only syntax ?


I'm just thinking that from a user point of view it would be nice to run in a "ejb3 only" mode
and be told if he crosses the line into the other side ;)


/max

On Wed, 15 Dec 2004 23:16:45 -0500, Joshua Davis <[EMAIL PROTECTED]> wrote:

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:


Ok, 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-----
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


keywords to ql

Aha... So you've introduced a new keyword, and

also a new
clause in the the select expression with the new

keyword
being the token that allows the parser to

distinguish between
the two branches.

I've got some ideas about what the problem is, but

I'll have
to test some things out to make sure.  I should be

able to do
that 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

the

corresponding AST node to be the root of the

sub-tree.

                (DISTINCT)? ( selectedPropertiesList |

newExpression |

selectObject)
        ;

selectObject
  : OBJECT^ OPEN! identifier CLOSE!
  ;

If I comment out selectObject in selectClause,

the test passes.

Thanks.


-----Original Message-----
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

keywords to ql

Actually, the HQL parser is capable of using

keywords as

identifiers in some contexts.   I'm not sure what you're

saying

here, have

you modified
the grammar and this caused HqlParserTest to

fail?

 If that

is the case
then there may be something wrong with the

modified grammar that is

preventing the 'keyword as identifier' from

working. 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

are

not

supported yet. I

will need to add some new keywords that might

cause some

existing tests

to fail. E.g. adding "object" causes the

following test to fail

input: ->from org.hibernate.test.Bar bar

where

bar.object.id = ? and

bar.object.class = ?<-

msg=HQL syntax error : unexpected token: .

near

line 1, column 42

There was 1 failure:
1)

testUnitTestHql(org.hibernate.test.hql.HqlParserTest)junit.fr

amework.As

s
ertionFailedError: At least one error

occurred

during parsing!

expected:<0> but was:<2>
        at

org.hibernate.test.hql.HqlParserTest.doParse(HqlParserTest.java:990)

        at

org.hibernate.test.hql.HqlParserTest.parse(HqlParserTest.java:966)

        at

org.hibernate.test.hql.HqlParserTest.testUnitTestHql(HqlParse

rTest.java:

663)
        at

sun.reflect.NativeMethodAccessorImpl.invoke0(Native

Method)

        at

sun.reflect.NativeMethodAccessorImpl.invoke(Unknown

Source)

        at

sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown

Source)
        at

org.hibernate.test.AllTests.main(AllTests.java:120)

Am I missing something or there is really no

way

to fix this

except for

disallowing the use of 'object' even in

paths?

Thanks.



-------------------------------------------------------

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]


=== 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



-- Max Rydahl Andersen callto://max.rydahl.andersen

Hibernate
[EMAIL PROTECTED]
http://hibernate.org

JBoss Inc
[EMAIL PROTECTED]
http://jboss.com


-------------------------------------------------------
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

Reply via email to