Skip to content
Levi Starrett edited this page Feb 1, 2020 · 5 revisions

Templating

Another design requirement for Ciera as a model compiler tool was to support RSL templates. RSL is a scripting/templating language that has been used for many years to build interpreted model compilers. pyrsl appeared several years ago as a modern interpreter for the language

The Ciera implementation of RSL templating parses the template files at build time and generates a "template registry" of Java methods that take a set of symbols as input and produce a string as output.

RSL template tool

Enabling the template tool

To enable the SQL tool, first add the TemplateDir mark with the path to your templates as the value. See Template directory for mark details. Next add the template tool as an execution step to the project pom.xml. You will need to define an ouptut location for the core code generator so the instances can be loaded by the template tool to generate the template registry. This file can be anything, but simply serves as an intermediate landing location between the two code generators:

<execution>
  <id>ciera-core</id>
  <goals>
    <goal>core</goal>
  </goals>
  <configuration>
    <output>${project.build.directory}/b.xtuml</output>
  </configuration>
</execution>
<execution>
  <id>ciera-template</id>
  <goals>
    <goal>template</goal>
  </goals>
  <configuration>
    <input>${project.build.directory}/b.xtuml</input>
  </configuration>
</execution>

The T external entity

To use templates, you must make calls to the T external entity. Set the output directory with

T::set_output_directory(dir:"folder");

Include a template with

T::include(file:"t.mytemplate.java");

More detailed documentation can be found in the API docs

Limitations

RSL support

The Ciera template implementation does not support all of RSL.

Ciera supports the following:

  • buffers

    • blobs of text

    • substitution variables

    • escaped characters (as defined in pyrsl)

  • format characters in substitution variables

  • if/elif/else statements

  • all expressions (conditional expressions for if statements)

  • literals

    • boolean

    • integer

    • real

    • string

  • substitution variables in string literals

Ciera does not support the following:

  • select statements

  • create/delete statements

  • relate statements

  • variables

  • for/while loops

  • fragments

  • etc, etc, etc…​

Ciera only supports the core templating constructs and not any of the query constructs.

Note
You can decide for yourself whether or not this is a limitation or a feature — it forces users to write true templates. There will be no future plan to implement the rest of the RSL specification in Ciera.

Templating marks

Template directory

The location of your template files must be declared through a mark. Any invocations to T::include in OAL will be relative paths to this directory. If this mark is not included, the build will fail. Configure the mark as follows:

*,TemplateDir,*,<location>
ex:
*,TemplateDir,*,templates

where <location> is the path to the directory where the templates are located.

Clone this wiki locally