Russ, before I respond, check out the next message about an alternate use of formatters on sections. I think you'll like this, since you may find it useful specifically for generating technical docs.
This came to me just now, thinking about the problem below, and a problem another coworker pointed out. Andy On Thu, Jun 18, 2009 at 11:33 PM, Russ Cox<[email protected]> wrote: > >> Predicates are functions from JSON nodes -> booleans. It was pointed >> out that if you define *truth* on JSON nodes, which we've already >> done, then formatters can serve as predicates. > > I admit it; it was me. > >> But it doesn't work, because in the "false" case you may still need >> substitutions: > > I disagree. > >> {.section group|plural?} >> There are {num} people in group {name}. >> {.or} >> There is one person in group {name}. >> {.end} > > {.section group} > {.section @|plural?} > There are {num} people in group {name}. > {.or} > There is one person in group {name}. > {.end} > {.end} > >> {.section group|plural?} >> {@|fancy-formatter-for-plural-groups} >> {.or} >> There is one person in group {name}. {# No fancy formatter} >> {.end} > > {.section group|plural?} > {@|fancy-formatter-for-plural-groups} > {.or} > There is one person in group {group.name}. {# No fancy formatter} > {.end} > >> Also, predicates and formatters do different things, so we shouldn't >> make them the same concept. Formatters are concerned with >> substitution of values, and apply only to substitutions. Predicates >> are concerned with *whether* to show a section. > > This is like saying that calls to an int(*)(void) > and calls to a char(*)(void) do different things, so > we can't refer to them both as function calls. > The | syntax does the same thing in both cases: it takes > the data, pipes it through the function, and uses the > resulting value. > > The beauty of JSON Template is that it has four basic > operator: .section, .repeated section, substitute, and pipe. > Allowing pipe in .section and .repeated section would > address the perceived need for predicates by removing > a restriction (no pipes in section expressions); it adds > no new operators. > > Adding predicates as a distinct operator grows the > operator set by 25%, adds another restriction > (no predicates in substitute expressions), and makes the > arguments to the | operator context dependent. > > Russ > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
