Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Statement type

Syntax

Comment

group

 

Place at beginning of string template group file to name the group, and also indicate inheritance or implements

 

Code Block

group gname;

Simple case. Conventionally, gname should match the name of the template group file (minus .stg extension).  The actual StringTemplateGroup object's Name field adopts the name provided by this group statement, even if different from the filename. If other templates refer to this one (as in inheritance) then it's this gname that's valid.

 

Code Block

group gname: supergroupname;

Group gname inherits from supergroupname

 

Code Block

group gname implements intfname;

Group gname implements the interface specified in intfname. Implements can also be placed after supergroupname.

template
definition

Code Block

tmpname() ::= "template text"

Basic form of template specification

 

Code Block

tempname() := <<
template text
>>

Basic form of template specification using <<...>> to enclose multiple lines of template text

 

Code Block

tmpname(arg1, arg2) ::= "..."

Declare formal arguments inside the parens.
(<<...>> can be used instead of "...")

 

Code Block

tmpname(arg1="blah") ::= "..."

Optionally provide a default value for an argument
(<<...>> can be used instead of "...")

 

Code Block

newname::=oldname

Make newname an alternative name for the template oldname.  Might also work for maps?

Inheritance

Override an inherited template

In the sub group file, just create a new definition of the template using the syntax above.

Region override

Code Block

@tmpname.rgnname() ::= "sometext"

Override a region just like overriding a template, except use the qualified name of the region in place of the template name. Although there are parens, there will never be formal arguments.  (<<...>> can be used instead of "...")

map

Code Block

mapname ::= [
"name1":"val1",
"name2":"val2",
default:"err"
]

-- The last row can use default as the name (no quotes) to specify what to return when an expression invokes the map with a key that is not in the map.
-- You can use the word key (no quotes) as a value to indicate that the map should just return the same value as was supplied. This is most useful in combination with the default name.

 


 

...

Statement type

Syntax

Comment

interface

 

Place at beginning of string-template group interface file to name the interface

 

Code Block

group gname;

Simple case. Conventionally, gname should match the name of the template group file (minus .stg extension).  The actual StringTemplateGroup object's Name field adopts the name provided by this group statement, even if different from the filename. If other templates refer to this one (as in inheritance) then it's this gname that's valid.

 

Code Block

tmpname(arg1, arg2);

Specify a template that is required to be implemented. (Note the semicolon at the end.)

 

Code Block

optional tmpname(arg1, arg2);

This form (with the keyword "optional") is used specify a template that can be implemented but is not required.

Next: ST condensed -- API annotated