Harbinger Template

Introduction

Harbinger template is a quirky, efficient, flexible, fun* and concise templating language. The primary design goal is to write as much human readable data as possible using as few keystrokes as possible given a large volume of input text. Everything else, including legibility, is of secondary concern.

Basic Usage

Everything in Harbinger Template is about lines, and their parsing as defined by previous #define blocks. So the first thing you want to do when working on a Harbinger template is defining your line types. You can then later use those line types to feed inputs to your previous code.

So a simple Harbinger Template might look like this:

Input:

#define a
res += `Some really long text that includes ${line} in the middle.\n`
#end
a this
a that
a foo

Output:

Some really long text that includes this in the middle.
Some really long text that includes that in the middle.
Some really long text that includes foo in the middle.

In this code the #define block defines what to do whenever the command a is encountered at the start of the line. The variable res is the result of the program, each time the a line type is encountered, we add a new line to it. We use the line variable to read the value of the line after the line type indicator a.

It is also possible to pre- and post-process res so as to use different types of values using #exec blocks.

For example if we want to use an integer to sum numbers we might do it like so

Input:

#exec
res = 0
#end
#define sum
res += +line
#end
sum 1
sum 2
sum 3
#exec
res = `The total is ${res}`
#end

Output:

The total is 6

Here, we initialize the res variable with the number 0. Then we parse each sum line to the res variable. Finally we set the res variable to be equal The total is ${res}, which templates the value of the total into res.

Sometimes we do not want to store transient state in our result, and some languages may not allow for changing the type of the variable. So a cleaner solution for this would be the use of the tmp variable.

Using that the above program can be written as follows:

Input:

#exec
tmp = 0
#end
#define sum
tmp += +line
#end
sum 1
sum 2
sum 3
#exec
res = `The total is ${tmp}`
#end

Output:

The total is 6