Chapter 3. Tags and Syntax

KET provides four types of tags.

3.1. Comments

KET templates may contain comments. Comments are defined between the characters <%-- and --%>. Comments have no impact on the execution of the template, except that they may influence whitespace stripping rules. KET comments are copied to the generated kermeta class as Kermeta comments. KET templates accept two special tags in the first non-blank line of a comment. The tag @header will cause the comment to be emitted as the file header comment for the generated Kermeta class. This is generally useful to insert copyright notices into the generated Kermeta code. The tag @class will cause the comment to be emitted as the class Kermeta doc comment for the generated Kermeta class.

3.1.1. Valid comments

Comments may span several lines, and may contain any text.

<%-- @header
This comment will appear as the file header comment in the generated kermeta code
--%>
<%-- @class
This comment will appear as the kermeta class doc comment in the generated kermeta code --%>
<%-- This comment will not appear in the template output --%>
<%-- This directive is not used <%= attr.name%> --%>

3.1.2. Invalid comments

Comments may not appear within other KET elements.

<%= attr.name <%-- illegal comment --%> %>
			

3.1.3. Escaping comments characters

To emit the characters <%-- in a template output, enter <\%--. To emit --%>, enter --%\>.

<\%-- this will show in the template 
			output --%\>

3.2. Kermeta expressions

KET templates may emit the result of a Kermeta expression by enclosing the Kermeta expression between the characters <%= and %>. One scenario is to compute some data in Kermeta and include the result into your template .

The name of the class executing is: 
        <%= aClass.name %>
This is the <%= 5th %> execution of the generator: it says<%= "hello" %>.
	

3.2.1. Valid expressions

Expressions contain valid Kermeta expressions. Expressions may access any Kermeta element in scope, including generator parameters or field and methods declared in Kermeta scriptlets. The emitted Kermeta code for the template will evaluate the Kermeta expression and convert the result to a String (if necessary). Expressions may be constants but it looks weird.

<%= 3 + 4; %> <%-- semicolon not allowed in 
			Kermeta expressions --%>

3.2.2. Invalid expressions

Expressions are not statically checked to any error in the Kermeta expression will only be detected in the emitted Kermeta code. Errors are not correlate back to the KET template.

3.2.3. Escaping expressions characters

To emit the characters <%= in a template output, enter <\%=. To emit %>, enter %\>.

3.3. Kermeta scriplets

KET templates may contain sections that contain Kermeta statements by enclosing the Kermeta expressions between the characters <% and %>.

3.3.1. Valid scriptlets

Scripts may contain one more more valid Kermeta statements or blocks. A scriptlet may also include a partial Kermeta block, so long as a subsequent scriptlet completes it. Scriplets may reference any Kermeta elements in scope, including variables declared in other scriptlets, and methods and fields declared in Kermeta declarations. The emitted Kermeta code from the template will contain the Kermeta statements in the generation method.

<% var x : Integer init 2 %>
<% var y : Integer init x*5 %>
<% if y >= 10 then %>
   Y is >= 10
<% end %>

3.3.2. Invalid scriptlets

Expressions are not statically checked to any error in the Kermeta expression will only be detected in the emitted Kermeta code. Errors are not correlate back to the KET template.

3.3.3. Escaping scriptlets characters

To emit the characters <% in a templates output, enter <\%. To emit %>, enter %\>.