[stringtemplate-interest] File based templates and maps.
John Snyders
jjsnyders at rcn.com
Thu Oct 19 23:53:57 PDT 2006
There are many characters that can't be used as a map key without enclosing
in ().
I don't think it matters if the map is declared in code or in the group
file.
It has to do with what is allowed after . in an attribute reference
atom DOT ID is allowed where atom is ID, STRING, INT, or ANONYMOUS_TEMPLATE.
So if your map key is "a:.b" or even "first" $map.a:.b$ and $map.first$
won't work.
The thing I thought to myself when I first noticed this (I had a key called
first) is why does ST need to know anything about integers? I don't recall
seeing anything like $5600$ shown in any example in the documentation (this
renders as 5600 btw). The only thing I could think of is that perhaps if
there were a specific render for integers then you could have literal
integers in the template get the desired formatting that matches the
integers that come from the code. I never did try to see if that would work.
If that is the reason then couldn't a case be made for literal floating
point numbers and date literals as well?
So I'm not sure this (integer keys) is a bug but I'm still confused as to
why ST needs to parse integers at all.
-John
> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org]On Behalf Of Terence
> Parr
> Sent: Thursday, October 19, 2006 7:14 PM
> To: Caleb Lyness
> Cc: StringTemplate; ANTLR Interest
> Subject: Re: [stringtemplate-interest] File based templates and maps.
>
>
> Wow! Interesting...seems a bug.
>
> added:
>
> http://www.antlr.org/wiki/display/ST/numbers+not+allowed+as+keys
>
> Ter
> On Oct 19, 2006, at 4:05 PM, Caleb Lyness wrote:
>
> > Terence Parr wrote:
> >> try now...a spammer created 100 spam users. :(
> > Sorted.
> > -----
> >
> > Here is another problem I ran into while playing with maps:
> >
> > If the map has a number in the key you can't reference it directly.
> >
> > E.g.
> >
> > The map is defined as:
> >
> > collectionFailure ::= [
> > "1": "Revoked",
> > "2": "Other",
> > "A": "Settled",
> > "B": "Frozen",
> > default: "Unknown"
> > ]
> >
> > If a tempate .st file refers to the map directly
> >
> > $collectionFailure.1$ - it fails (see below)
> > $collectionFailure.A$ - works
> >
> > but if I use $collectionFailure.(reasonCode)$
> > then Bobs your uncle it can be 1 or A...
> >
> > action parse error in group base templates line 0; template context
> > is [bodies/example1]
> > line 1:19: unexpected token: 1
> > at org.antlr.stringtemplate.language.ActionParser.primaryExpr
> > (ActionParser.java:703)
> > at org.antlr.stringtemplate.language.ActionParser.expr
> > (ActionParser.java:430)
> > at org.antlr.stringtemplate.language.ActionParser.templatesExpr
> > (ActionParser.java:212)
> > at org.antlr.stringtemplate.language.ActionParser.action
> > (ActionParser.java:126)
> >
> >> Ter
> >>
> >> On Oct 19, 2006, at 10:39 AM, Caleb Lyness wrote:
> >>
> >>>>> I think it would be nice for future newbies if there was an
> >>>>> example along side the file based template (.st) method in the
> >>>>> source. Would speed the learning curve up a bit. cf: src\org
> >>>>> \antlr\stringtemplate\test.
> >>>> Add a quick tutorial :) http://www.antlr.org/wiki/display/ST/
> >>>> Tutorials
> >>> Pitty, I cannot:
> >>> I don't have a login and I can't create one.
> >>>
> >>> The following error(s) occurred:
> >>> This installation of Confluence is not licensed to add any more
> >>> users. Please contact the site administrators for more information.
> >>>
> >>>
> >>
> >>
> >
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list