Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » B3 » b3 templates
b3 templates [message #633003] Fri, 15 October 2010 01:55
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
Hi,
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
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327797

«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
ends»

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)
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
<ul>«{
(0..3).collect(x| «<li>bullet #«{x}»</li>
»)}»
</ul>
</p>»;

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.

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


Current Time: Fri Nov 28 19:40:17 GMT 2014

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

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