You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Randal Walser <ra...@comcast.net> on 2005/01/14 14:18:42 UTC
how to pass a Map to a method
Is it possible to use VTL map notation to pass a map to a method? I
can set a variable to a map and then pass the variable to a method,
but I get a ParseErrorException when the argument is expressed in
notational form:
#set( $map = {"a" : "b", "c" : "d"} ) ## This works,
$foo.takeMap( $map ) ## and so does this,
$foo.takeMap( {"a" : "b", "c" : "d"} ) ## but this fails.
Since an ArrayList can be passed like this
$foo.takeArrayList( ["a", "b", "c", "d"] )
shouldn't it be possible to pass a Map in similar fashion?
Thanks,
Randal
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Randal Walser <ra...@comcast.net>.
At 09:28 AM 1/15/2005 +0900, you wrote:
>I found the problem, but not knowing much about JavaCC, I don't know
>how to fix it.
Hey, way to go. That sure looks like the problem alright. I'll point
out your observation in my bugzilla report for Will Glass-Husain.
Thanks again for jumping on this.
Randal
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Randal Walser <ra...@comcast.net>.
At 04:11 PM 1/14/2005 -0800, you wrote:
>There's some significant grammar changes coming, stay tuned. Most notably a
>patch to allow decimal numbers. Put this into a bugzilla entry and I'll
>look into it.
I'll do that. Thanks. I'm looking forward to your patch.
Randal
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Will Glass-Husain <wg...@forio.com>.
There's some significant grammar changes coming, stay tuned. Most notably a
patch to allow decimal numbers. Put this into a bugzilla entry and I'll
look into it.
Thanks,
WILL
----- Original Message -----
From: "Randal Walser" <ra...@comcast.net>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, January 14, 2005 3:50 PM
Subject: Re: how to pass a Map to a method
> At 10:46 PM 1/14/2005 +0900, you wrote:
>>I'd say it should. Maps are features of the upcoming 1.5, which is
>>still under development. Maybe it's a bug, maybe it's simply not
>>implemented yet. You could file a bugzilla issue so the developers
>>get reminded. Better yet, you can submit a patch to give the
>>suggested behaviour! ;)
>
> 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.
>
> Thanks,
>
> Randal
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Will Glass-Husain <wg...@forio.com>.
If you end up submitting a patch, please be sure to include a unit test for
the formerly broken functionality.
Thanks,
WILL
----- Original Message -----
From: "Shinobu Kawai Yoshida" <sh...@gmail.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>; "Velocity
Developers List" <ve...@jakarta.apache.org>
Sent: Friday, January 14, 2005 4:28 PM
Subject: Re: how to pass a Map to a method
> 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 <sh...@gmail.com>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
> Here's the original posting:
> http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=velocity-user@jakarta.apache.org&msgNo=14677
>
> ## I'll file an issue in Bugzilla tonight (JST) if nobody else does.
> Gotta go to work now. :(
And here it is:
http://issues.apache.org/bugzilla/show_bug.cgi?id=33113
Best regards,
-- Shinobu
--
Shinobu "Kawai" Yoshida <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
Hi guys,
Here's the original posting:
http://mail-archives.apache.org/eyebrowse/ReadMsg?listName=velocity-user@jakarta.apache.org&msgNo=14677
## I'll file an issue in Bugzilla tonight (JST) if nobody else does.
Gotta go to work now. :(
Best regards,
-- Shinobu
--
Shinobu "Kawai" Yoshida <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
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 <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
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 <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Randal Walser <ra...@comcast.net>.
At 10:46 PM 1/14/2005 +0900, you wrote:
>I'd say it should. Maps are features of the upcoming 1.5, which is
>still under development. Maybe it's a bug, maybe it's simply not
>implemented yet. You could file a bugzilla issue so the developers
>get reminded. Better yet, you can submit a patch to give the
>suggested behaviour! ;)
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.
Thanks,
Randal
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: how to pass a Map to a method
Posted by Shinobu Kawai Yoshida <sh...@gmail.com>.
Hi Randal,
> Is it possible to use VTL map notation to pass a map to a method? I
> can set a variable to a map and then pass the variable to a method,
> but I get a ParseErrorException when the argument is expressed in
> notational form:
>
> #set( $map = {"a" : "b", "c" : "d"} ) ## This works,
> $foo.takeMap( $map ) ## and so does this,
> $foo.takeMap( {"a" : "b", "c" : "d"} ) ## but this fails.
>
> Since an ArrayList can be passed like this
>
> $foo.takeArrayList( ["a", "b", "c", "d"] )
>
> shouldn't it be possible to pass a Map in similar fashion?
I'd say it should. Maps are features of the upcoming 1.5, which is
still under development. Maybe it's a bug, maybe it's simply not
implemented yet. You could file a bugzilla issue so the developers
get reminded. Better yet, you can submit a patch to give the
suggested behaviour! ;)
Best regards,
-- Shinobu
--
Shinobu "Kawai" Yoshida <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org