What is terp™?

terp improves ANT builds terp is a templating engine
  • a host reflection system that provides information about the build host and installed software.
  • a <> task that supports complex expressions and conditions.
  • a <terp.foreach> task that supports iterating over the elements of a collection, for example all C++ compilers that are installed on a system.
  • a <terp.cpp> task that supports the discovery of compilers and platform-, processor architecture-, and compiler-portable compilation of C/C++ code.
  • a <terp.echo> task that supports the full feature set of the terp expresison language and template expansions.
  • a full-features expression language.
  • rich type system to support types like host, version, os, and many tools.
  • rich set of built-in text formatters that modify the textual representation of objects.
  • rich set of built-in transformers that convert an object to a desired value.
  • rich set of selectors to apply actions only to a sub-range of a collection.
  • ability to call arbitrary Java methods on objects.
  • ability to extend and replace terp features.
  • pre-populated variables for host-related information (hostname, operating system, environment, installed software, etc.)

terp improves ANT builds

Here is a little snippet of an ANT script that uses terp to build a C++ shared library. It uses g++ 3.4, but it would be easy to use a different compiler by simply changing the property definition. You could even put the compiler task into a <terp.foreach> loop and build with several different compilers.

<target name="compile-cpp" description="Build the shared library">
    < name="cpp.comp" expression="^gcc(3.4)" />

    <terp.cpp compiler="cpp.comp"
        <target name="funcs" type="shared" version="1.0.5" />
        <relocatable />
        <multithreaded />
        <rtti value="false" />
        <sources dir="${basedir}" includes="*.cpp" />


terp is a templating engine

The "Hello world!" example in terp looks like this:

Hello ${name}!

You can expand this template, for example by using the terp command line utility:

C:\terp\bin>terp -Dname=world -t "Hello ${name}!${eol}"
Hello world!

You can deduce the basic template syntax from the above example. Text is simply text; embedded statements start with a ${, end with a }, and surround the terp statement or expression.

We added the pre-defined end-of-line constant eol to the text to make the output look nicer, but this is still a very simple template example that does not require a lot of explanations.

There are many other templating engines, but terp has a number of nice features to distinguish itself from others:

  • host reflection for a wide range of pre-defined variables.
  • custom executors (active components with specialized knowledge of the application or tool they are invoking).
  • tight ANT integration.
  • very easily expandable.

terp is a software engineer's template engine. Use it to

So, what is terp?

terp stands for "modular template interpreter." terp is a templating engine with a separate ANT module that takes advantage of the engine. Think of a modular template interpreter as server pages outside of a webserver or as a report generator on steroids. Combine the text generation functionality with powerful host-system experts that understand development tools, including C++ compilers, and the ability to invoke arbitrary Java methods, and you have a very powerful tool. It is modular because you can extend the functionality with your own types. You can even overload the built-in operators for your own types.

Is that all it is?

No, of course not. For some people, the ANT tasks that come with terp will be all they want. A portable C++ compiler task and an iterator task can solve many build problems all by themselves. But maybe you're not interested in that aspect of terp.

If terp statements were limited to simple variable names or mathematical expressions, terp would not be a very exciting tool. You could probably hack up something like that yourself with a couple of days of work. Fortunately, terp is much more powerful.

The following list highlights just a few of terp's basic capabilities:

  • support for dynamic file and template inclusion,
    for example ${import("nested.tpl")}.
  • support for advanced text formatting,
    for example ${#center}CENTERED TEXT${end}.
  • support for conditional template expansion,
    for example ${if(x>4)}conditional${end}.
  • support for object enumeration,
    for example ${foreach(i:aList)}${i}${end}.
  • support for Java object fields and methods,
    for example ${}.
  • built-in variables for system reflection,
    for example ${}.
  • built-in datatypes,
    for example for versions ${^gcc().version.major}.

Copyright 2006-2016 by Codemesh, Inc., ALL RIGHTS RESERVED

home home expressions templates ant about us contact us download