Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » B3 » b3 templates
b3 templates [message #633003] Fri, 15 October 2010 01:55
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Don't know if you all subscribe to the b3 bugzilla....

I just finished basic support for templates in b3. It turned out to be
much easier than expected - I planned to do just some exploratory work,
but ended up with a complete implementation.

Anyway, this is what I posted in the bug

«This is a template without any variability»

«This is a template with «{"hello "+"templates}» inserted}»

var a = 1;
«Prints and increments a «{a,a++}», and prints incremented a «{a}» and

var a = 1;
«Increments a «{,a++}» without printing, and then prints incremented a
«{a}» and ends»

- An IB3Printer is responsible for performing a print of a Template.
- A default printer prints to System.out and performs basic formatting
of all objects, collections, iterables, iterators, and Maps. Map entries
are printed as key="value" with a space separating entries. (Useful for
html output).
- A system function print, was also introduced with flexible signature.
print(Object, Stream)
print(IB3Printer, Object)
print(IB3Printer, Object, PrintStream)
print(Object, IB3Printer)
print(Object, IB3Printer, PrintStream)

If IB3Printer is missing the default printer is used. If stream is
missing, the default stream provided by a IB3Printer is used.

- A Template is a LiteralExpression (i.e. it evaluatess to itself, but
binds the evaluation in a closure (i.e. it has access to the context
where it is defined).
- Nested expressions are evaluated in the order they are stated, the
printed part of «{printed, notPrinted}» is evaluated first, then the
notPrinted, and the printed part is returned. The printer prints the
returned result.

It should be trivial to construct new special purposed IB3Printers
overriding either the default printer, or the abstract declarative
printer. (e.g. a printer suitable for Servlet streams and HTML).

The print(...) functions (and the IB3Printer.doPrint(...)) returns
IStatus.OK or IStatus.ERROR for Exception. Hard Errors are thrown.

--- (end text from bug) ---
Naturally, it is possible to combine system functions like collect,
inject, etc. to produce nested templates, insert templates produced by
functions etc. resulting in a very powerful and flexible template mechanism.

«<p>A paragraph of html text
(0..3).collect(x| «<li>bullet #«{x}»</li>

One improvement I was thinking about is that the default printer should
be picked from the enclosing context (if already printing). This would
allow imperative style (i.e. call print instead of returning what the
printer in effect should print) to use the same printer that was used to
print the outermost template.

- henrik
Previous Topic:Hudson Support
Next Topic:missing zipped instruction after mirror of b3 mirror update-site
Goto Forum:

Current Time: Wed Jul 24 09:44:38 GMT 2024

Powered by FUDForum. Page generated in 0.03549 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top