velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai Yoshida <shinobu.ka...@gmail.com>
Subject Re: how to pass a Map to a method
Date Sat, 15 Jan 2005 00:28:49 GMT
Hi Randal,

> There have been no changes to the grammar in over a year (anywhere in
> the runtime/parser directory, anyway).  Apparently, shoring up the
> language implementation hasn't been a priority for a while, unless the
> developers aren't committing language changes to the repository.  I've
> noticed some other "curiosities" in the language, as well, so maybe
> I'll dig deeper into it myself when I get a chance.  I'll submit a
> patch if I come up with anything useful.

I found the problem, but not knowing much about JavaCC, I don't know
how to fix it.

In Parser.jjt, there are two definitions for "{", LCURLY (in a
reference) and LEFT_CURLEY (in a map).  Parameter() allows Map() and
Reference(), both have a definition starting with "{", but in method
invocation, the state is in "REFMOD2", hence the LEFT_CURLEY is not
matched.  I think the solution is something using LOOKAHEAD, but don't
have enough time right now to fiddle around with JavaCC.

Parser.jjt excerpts:

Lines 510-515:
<DIRECTIVE>
TOKEN :
{
   <LEFT_CURLEY : "{" >
 | <RIGHT_CURLEY : "}" >
}

Lines 978-1011:
<REFERENCE,REFMODIFIER,REFMOD2>
TOKEN :
{
   <#ALPHA_CHAR: ["a"-"z", "A"-"Z"] >
|   <#ALPHANUM_CHAR: [ "a"-"z", "A"-"Z", "0"-"9" ] >
|   <#IDENTIFIER_CHAR: [ "a"-"z", "A"-"Z", "0"-"9", "-", "_" ] >
|   <IDENTIFIER:  ( <ALPHA_CHAR> | ["_"]) (<IDENTIFIER_CHAR>)* >
|   <DOT: "." <ALPHA_CHAR>>
   {
       /*
        * push the alpha char back into the stream so the following identifier
        * is complete
        */

       input_stream.backup(1);

       /*
        * and munge the <DOT> so we just get a . when we have normal text that
        * looks like a ref.ident
        */

       matchedToken.image = ".";

       if ( debugPrint )
           System.out.print("DOT : switching to " + REFMODIFIER);
       SwitchTo(REFMODIFIER);

   }
|   <LCURLY: "{">
|   <RCURLY: "}">
   {
       stateStackPop();
   }
}

Lines 1406-1415:
void Map() : {}
{
   <LEFT_CURLEY>
   (
     LOOKAHEAD(2) Parameter() <COLON> Parameter() (<COMMA> Parameter()
<COLON> Parameter() )*
     |
     [ <WHITESPACE> ]
    )
    <RIGHT_CURLEY>
}

Lines 1468-1485:
void Reference() : {}
{
   /*
    *  A reference is either ${<FOO>} or  $<FOO>
    */

     (
        <IDENTIFIER>
        (LOOKAHEAD(2) <DOT> (LOOKAHEAD(3) Method() | Identifier() ))*
     )
     |
     (
        <LCURLY>
        <IDENTIFIER>
        (LOOKAHEAD(2) <DOT> (LOOKAHEAD(3) Method() | Identifier() ))*
        <RCURLY>
     )
}

Lines 1442-1456:
void Parameter() #void: {}
{
   [<WHITESPACE>]
   (
       StringLiteral()
       | LOOKAHEAD(  <LBRACKET> [<WHITESPACE>]    ( Reference() |
NumberLiteral())     [<WHITESPACE>] <DOUBLEDOT> ) IntegerRange()
       | Map()
       | ObjectArray()
       | True()
       | False()
       | Reference()
       | NumberLiteral()
       )
   [ <WHITESPACE>]
}

Best regards,
-- Shinobu

--
Shinobu "Kawai" Yoshida <shinobu.kawai@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message