wiki:Doc/panc/statements

Statements

include

The include statement acts as if the contents of the named template were included literally at the point the include statement is executed. Two variants of the include statement are permitted:

include template-name;
include {dml};

The first variant includes the named template; the template is written as a token without quotes. The second variant executes the given DML block. The block must evaluate to a string, undef, or null. If the result is undef or null, the include statement does nothing; if the result is a string, the named template is loaded and executed. Any other type will generate an error. The braces in the second variant are required.

Ordinary templates may be included multiple times, but loops are not permitted. Templates marked as 'declaration' or 'unique' templates will be only included once where first encountered.

There are some restrictions on what types of templates can be included. Object templates cannot be included. Structure templates can only include and be included by other structure templates. Declaration templates can only include other declaration templates. All other situations are allowed.

assignment

Assignment statements are used to modify a part of the configuration tree by replacing the subtree identified by its path by the result of the execution a DML block. This result can be a single property or a resource holding any number of elements. There are conditional and unconditional assignments:

[ final ] path ?= dml;
[ final ] path = dml;

where the path is represented by a string literal. Single-quoted strings are slightly more efficient, but double-quoted strings work as well. The conditional form (?=) will only execute the DML block and assign a value if the named path does not exist or contains the undef value.

The assignment will create parents of the value that do not already exist.

If a value already exists, the pan compiler will verify that the new value has a compatible type. If not, it will terminate the processing with an error.

If the 'final' modifier is used, then the path and any children of that path may not be subsequently modified. Attempts to do so will result in a fatal error.

delete (deprecated)

This statement will delete the named path.

delete path;

where the path is a string literal.

Note that this statement is deprecated. The assignment statement

path = null;

provides the same functionality. This statement will disappear in a future release of the pan compiler.

type

Type definitions are critical for the validation of the generated machine profiles. Types can be built up from the primitive pan types and arbitrary validation functions. New types can be defined with

type identifier = type-spec;

Types referenced in the type-spec must already be defined. See the Type section for more details on the syntax of the type specification.

Note that the compiler keeps the distinct function and type namespaces. One can define a function and type with the same names.

function

Functions can be defined by the user. These are arbitrary DML blocks bound to an identifier. Once defined, functions can be called from any subsequent DML block. The function definition syntax is:

function identifier = dml;

See the Function section for more information on user-defined functions and a list of built-in functions.

Note that the compiler keeps the distinct function and type namespaces. One can define a function and type with the same names.

variable

Global variables can be defined. These may be referenced from any DML block after being defined. They may not be modified from a DML block; they can only be modified from a variable statement. Like the assignment statement there are conditional and unconditional forms:

[ final ] variable identifier ?= dml;
[ final ] variable identifier = dml;

For the conditional form, the DML block will only be evaluated and the assignment done if the variable does not exist or has the undef value.

If the 'final' modifier is used, then the variable may not be subsequently modified. Attempts to do so will result in a fatal error.

Pan provides several automatic global variables: OBJECT, SELF, and LOADPATH (and their deprecated lowercase equivalents). OBJECT contains the name of the object template being evaluated; it is a final variable. SELF is the current value of a path referred to in an assignment or variable statement. The SELF reference cannot be modified, but children of SELF may be. LOADPATH can be used to modify the load path used to locate template for the include statement.

Any valid identifier may be used to name a global variable. To avoid conflicts with local variables, however, global variables are usually named in all uppercase; local variables in all lowercase.

bind

The bind statement binds a type definition to a path. Multiple types may be bound to a single path. During the validation phase, the value corresponding to the named path will be checked against the bound types. There are two variants:

bind path = type-spec;
type path = type-spec;

See the Type section for a complete description of the type-spec syntax. Note that the second form is deprecated and will disappear in a future release.

valid

The valid statement binds a validation DML block to a path. It has the form:

valid path = DML;

This is a convenience statement and has exactly the same effect as the statement:

bind path = element with DML;

The pan compiler internally implements this statement as the bind statement above.

Last modified 17 years ago Last modified on Jul 2, 2007, 2:29:41 PM