Chapter 9 Generation Reference Guide (GTL)
You can pass in, out or in/out parameters to a template through local variables by taking advantage of nested translation scopes. You can access parameters with the %@<number>% variable.
Class templates:
<show> template <<< Class "%Code%" attributes : // Public %publicAttributes% // Protected %protectedAttributes% // Private %privateAttributes% >>>
<publicAttributes> template <<< .foreach_item(Attributes) .if (%Visibility% == +) %DataType %Code% .endif .next(\n) >>>
<protectedAttributes> template <<< .foreach_item(Attributes) .if (%Visibility% == #) %DataType %Code% .endif .next(\n) >>>
<privateAttributes> template <<< .foreach_item(Attributes) .if (%Visibility% == -) %DataType %Code% .endif .next(\n) >>>
To give you more readability and to enhance code reusability, these four templates can be written in just two templates by using parameters:
<show> template <<< Class "%Code%" attributes : // Public %attributes(+)% // Protected %attributes(#)% // Private %attributes(-)% >>>
<attributes> template <<< .foreach_item(Attributes) .if (%Visibility% == %@1%) %DataType %Code% .endif .next(\n) >>>
The first parameter in this example %attributes(+, or #, or -)% can be accessed using the variable %@1%, the second parameter when it exists, is accessed using the %@2% variable, etc ...
Copyright (C) 2005. Sybase Inc. All rights reserved. |