[stringtemplate-interest] accept simple expression language
Terence Parr
parrt at cs.usfca.edu
Tue May 12 11:47:39 PDT 2009
Hi,
Well,My experience is that you don't really mean low-level operation
like add. that is what computers understand. humans use low-level
operations because it implements things like price including tax or
give discount things like that. Are you sure you mean add? don't you
mean some higher-level operation that really belongs in a model? why
can't you ask the model to give you the result of some high-level
operation and then implement it using addition in your model? the
antlr tool code generator with all of its multiple targets is
extremely complex and there is not a single need to do what you ask. I
be surprised if we couldn't come up with a way to think about the
problem that did not require you to violate the principles.
Ter
On May 11, 2009, at 8:06 PM, DVD wrote:
> Hi, Terence,
> Customization might not be the correct wording.
> I understand ST enforces the separation. But I wonder if an option
> could be provided when really needed for scenarios that
> the authors either do not know Java or do not have easy means
> to add property to model. In my example, the visitor would be allowed
> to create their own template for their own web page and they would be
> presented properties available from the model (a and be here).
> if the user requires a value of c = a+b to be display in the web
> page, then
> there would not be easy way to do this.
>
> Perhaps some mechanism and built-in (and localled developed)
> expression handler
> could be provided so that authors could use somethinf like
> $handler_add(O.a+O.b)$ where "handler" would be a special label
> indicating to the ST engine that this is a expression processor to
> call the provided expression handler.
>
> This is not a frequently used feature but I feel this would prevent
> any showstopper when
> needed. Otherwise, I would have to use another template system just
> for this purpose.
>
> I know this could "pollute" the clean design of ST but I feel it
> would be worth it to make it
> all-around player with a slight compromise. Remember it took Sun so
> many years to
> give up the marketing of safe String class to provide the
> StringBuilder class :-)
>
> Regards
>
>
>
>
> Terence Parr wrote:
>> Hi. Addition or other computation on model values is forbidden in
>> the view to avoid entangling model/view. You really need to
>> compute in the model and pass in some how. Adding numbers isn't
>> "customization" though as you ask about...it's an entanglement to
>> be avoided :)
>>
>> Ter
>> On May 10, 2009, at 12:58 PM, DVD wrote:
>>
>>> Hello:
>>>
>>> I experimented with ST and really like use it for all my projects
>>> replacing freemarker.
>>> The only thing I feel uncertain is that ST does not provide an
>>> option
>>> to allow using a simple expression langauge for template author for
>>> customization without
>>> requiring model developer to provide the needed data. For example,
>>> if originally the template is like
>>>
>>> $O.a$$O.b$
>>>
>>> but a user wants to have only value c = summing a and b,
>>> something like
>>> $O.a+O.b$
>>>
>>> I guess in order to get this, model dev has to add property "c"
>>> in O in
>>> order for author
>>> to get. This is a big problem if an application expects authors to
>>> import their own templates,
>>> since the authors would have no way to customize it, even for some
>>> simple operation.
>>> Renderer might not help so I am not sure if there is any solution
>>> for
>>> this scenario. I went through
>>> the doc but did not have an example.
>>>
>>> Thanks
>>>
>>> _______________________________________________
>>> stringtemplate-interest mailing list
>>> stringtemplate-interest at antlr.org
>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>
>
More information about the stringtemplate-interest
mailing list