Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 327797 - Support templates
Summary: Support templates
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: b3 (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-14 12:24 EDT by Henrik Lindberg CLA
Modified: 2017-09-13 11:52 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Lindberg CLA 2010-10-14 12:24:59 EDT
Templates are useful in many ways when building, publishing files etc.

«This is template text «{=echoedExpression}» and «{expression product is not echoed}» etc...»

Consider reversing the logic, so that echo is the default for expressions (this is probably the most common), and instead have a 'no echo' operator - say , as in «{,a++}». It would then perhaps be of value to be able to use «{echoedExpr,notEchoedExpr}» (the ',' then makes a lot more sense).
Comment 1 Henrik Lindberg CLA 2010-10-14 21:19:54 EDT
Implemented in revision 1351.

«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 spaces 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).
Comment 2 Henrik Lindberg CLA 2010-10-14 21:28:38 EDT
See testTemplates.b3 for some examples.
Comment 3 Henrik Lindberg CLA 2010-10-14 21:42:54 EDT
The print(...) functions (and the IB3Printer.doPrint(...)) returns IStatus.OK or IStatus.ERROR for Exception. Hard Errors are thrown.