Context-Sensitive Tokenization With CongoCC

If you want to interpret a programming language or a DSL, there’s no way around using a parser generator. At the heart of FreshMarker is a template parser generated by the CongoCC parser generator. I can’t praise this JavaCC successor from Jon Revusky highly enough. Many new features and completely revised parts make the parser generator much more usable than its seemingly dead predecessor. CongoCC also helps wonderfully with a small current problem.

Quo Vadis, Lambda?

To implement a new built-in for sequences, lambdas were added as a new language component of the FreshMarker Expression Language. The lambda expression made it much easier to map the semantics of the new count built-in in an easily readable syntax. Now that lambda expressions are available, what else can they be used for and what still needs to be implemented?

Select Operator for FreshMarker (2)

In the first article on the Select Operator, the implementation was provisionally terminated with a few weaknesses. In this article, two of the weaknesses are eliminated.

Comparison operators for Strings

FreshMarker allows you to overload a wide variety of operators for your own model types. These operators are multiplication, addition, negation and comparison operators. For strings, the addition operator + has so far been overloaded to realize a string concatenation. In this blog post, we want to implement comparison operators for strings.

New Operators

For the next version of FreshMarker, a number of new options will be created for the template engine. These new possibilities include the Spaceship Operator and a new String Concatenation Operator.

Optimize Switch for Constants

The FreshMarker Switch Directive is an unusual representative of its kind. Since it has been implemented according to the possibilities of its syntax description in the CongoCC example source code, it is capable of quite unusual working methods. Some special cases could be processed faster with an optimized version. Therefore, the Switch Directive is optimized for constants in this article.

FreshMarker – compile it! (3)

In the second article on the FreshMarker Compiler, we looked at the implementation of a pretty printer for Template instances. This implementation serves as the basis for the FreshMarker Compiler, which generates Java code from a Template instance. Before we tackle the Compiler, we need to look at a few more hurdles and details.

FreshMarker – compile it! (2)

In the first article on static FreshMarker templates, some basic thoughts were put on paper. This article is intended to set a first milestone on the way to supporting much faster templates than before. As a nice side effect of this initial work, a pretty printer for FreshMarker templates will be created.

FreshMarker Switch On Directive

Nothing is so good that it can’t be reworked. The switch directive in FreshMarker differed from the FreeMarker variant quite early on. FreshMarker’s switch directive does not have a fall-through mechanism. This mechanism is a legacy of the C language family, whose switch statements with break also found their way into the template syntax. Since the end of 2024, FreeMarker now also has a new switch directive. How can this be incorporated into FreshMarker?

FreshMarker Bricks

In a Reddit forum, a suggestion was made to support template fragments in FreshMarker. Template fragments are parts of a template that can be used individually. The question that naturally arises is why would you want to use parts of a template individually? After all, many template engines offer the option of construct a template from different sources using include instructions. Such an include can then also be used individually.