On Sun, Oct 11, 2009 at 1:36 PM, Steven Roussey <[email protected]> wrote:
>
> I was looking at what we have, where we have diverged, etc., and
> thought that it might be good to refer to some psuedo language
> examples. I think our main difference on predicates is what lens we
> are looking through. I believe that I am looking at IF type statements
> and you are looking at SWITCH type statements.
I don't think you're up to date on the latest changes. It was spread
out over 4 or 5 commits, but even if you don't read Python, you can
tell what the syntax is from the latest tests.
The syntax is:
{.if <predicate1>}
{.or <predicate2>}
{.or <predicate3>}
{.end}
In addition, anything that starts with . and ends with ? is treated
like an ".if" --
{.Debug?} == {.if Debug?}
The predicate strings are interpreted by the user. So you can parse
arguments, and *interpret* any argument as a name to lookup in
ScopedContext. This is done with the FunctionRegistry API.
So for example, you can implement operators with "is" expressions
(color is "blue"), but it's not in the core language. It is
implementable just like the Pluralize formatter.
So I think I've already implemented everything you want, except in a
more abstract fashion, which allows the user more control. The
predicates feature subsumes both if/else and switch/case statements.
Can you try to implement the FunctionRegistry API in JS/PHP? Your
implementation is still hard-coding a lot of things (the use of
_CALL_RE demonstrates this; that should go away). FunctionRegistry
sublasses/ChainedRegistry is the "Composite" and "Chain of
Responsibility" design pattern if you are that kind of person.
I think that will clear things up. Most of this mail misunderstands
what is already there.
> One last thing, in my clone I'm going to remove the ? from predicates.
> Since there is always a {.if} or {.case} in front, there isn't much
> point in keeping it. I'm not even sure if the 'is' predicate above
> should work like this:
If you want to never use ?, that's already possible with my scheme.
You just use ".if". {.if foo} is perfectly legal -- {.if color is
"green"} is also legal, where the predicate is 'color is "green"'.
The entire predicate is parsed by the user at *compile time* via
FunctionRegistry and applied by the template engine *at runtime*.
(The default predicate Debug? ends with ?, but you can name your
predicates whatever you want, and rename Debug? in your app if you
don't like it)
Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON
Template" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---