KET provides four types of tags.
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.
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%> --%>
Comments may not appear within other KET elements.
<%= attr.name <%-- illegal comment --%> %>
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" %>.
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 --%>
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.
KET templates may contain sections that contain Kermeta statements by enclosing the Kermeta expressions between the characters <% and %>.
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 %>
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.