wcomp-logo WebComp



  home  print

The Scripting Language

In scripts we define (1) a set of attributes and (2) a list of menu items. In addition it is possible to inherit attributes from other scripts.

Attributes/expressions

An attribute is an assignment of an expression to a name. Attributes are available to the components through a dictionary where components can look up the value from names. An attibute definition is in the form:

name = expression; 

Where the expression may either be

  • An integer number.
  • A text string (in single quotes).
  • A reference to an attribute defined elsewhere, prefixed with '$'.
  • A function.
  • A list of expressions, using square brackets: [e1, e2 ...].
  • A composite/sum, using the '+' operator to indicate that strings, numbers, lists or web-functions is to be concatenated or numbers to be added
  • A boolean expression, i.e. boolean values (true or false), boolean functions, references to boolean values or function, combined using the AND, OR and NOT operator.
  • null, i.e. an undefined object.

Note: Text in double quotes denotes web-functions (with static text). It may be somewhat confusing to have two different types types for static text strings. Therefore we consider to offer only one type and do automatic conversion to web-function when necessary.

Forced evaluation of expressions

If using the normal assignment operator '=' to assign an expression to a name, the expression is not evaluated immediately. It is evaluated when the result value is needed, and then in the context where it is actually used. This is a kind of lazy evaluation. However, sometimes we may need to be sure that the expression is evaluated at the time of assigning it, and in the context of the script where the assignment is defined. If we use the '<=' operator to assign, this means that the whole expression is evaluated eagerly. This also means that any later references to the name would share the resulting object.
name <= expression; 

Conditional expressions

Conditional expressions may have one or more if tests which means that the expression evaluates to one of the sub-expressions depending on which boolean expression evaluates to true, the general form is:

if bool-expr1, expr1; if bool-expr2, expr2; ... else, expr-n; 

If for instance bool-expr1 evaluates to true, the whole expression evaluates to expr1. The if expressions are evaluated in the order they are listed and the test which first evaluates to true is selected. If none of the if expressions evaluates to true, the expression after the else keyword is used (which is required) is used. An example: Here $browser refers to a boolean tester function which returns true if the browser identification string of the request matches a regular expression given as an argument.

oldbrowser = $browser | 'Mozilla[1234].*''; 
message = if $oldbrowser, "You have an old browser, please upgrade"; 
          else,           "Your browser is up-to-date";

Note: It is important to note that if expressions are used as arguments to functions (using the '|' operator) the argument-expressions are evaluated at the time of activating the function, which is when it is first used, and not re-evaluated later. This may be a severe limitation when using conditionals, and will be addressed in later versions of WebComp

Typechecking

WebComp supports typechecking in the sense that (1) redefinition of attribute values are limited to values of a compatible type, and (2) that arguments to functions must be of a type compatible with expected argument types. This can for instance be useful if a function is defined in one script and the actual value of its arguments are redefined in inherited scripts.

Menu items

Scripts may define a list of item-mappings, i.e. mappings from names to text expressions. Each mapping also has a title which can be used to generate menus. A mapping can have a sub-list of items. Generally the syntax for mapping definititons is as follows:

[name ':'] '"' title '"' -> text-expression, 
     [ , flags]  [ '{' sub-list '}' ]; 

Flags may be either 'HIDDEN', 'EXTERNAL' or both (separated by comma). The HIDDEN flag is a hint that the item should not be displayed in a menu as long as the item is not selected. The EXTERNAL flag indicates that the component is from another web-site and should not be integrated into the generated pages. An item can also be a section, which has a title but no component associated. Sections will usually have a sub-list and a name is not necessary here. It has the form:

SECTION  '"' title '"'  [ '{' sub-list '}' ];

The item-mapping list is available to components, both as an ordered sequence of item records and as a dictionary where components can look up a item-record from a name.

Conditional visibility

Instead of using the hidden flag, the visibility of the item can be defined as a boolean expression after the keyword if. This means that the item is hidden whenever the expression evaluates to false. The keyword HIDDEN is thus equivalent to the statement if false. In the following example the item one is always visible, the item two is always hidden, and the item three is hidden when $test1 or $test1 is true.

one  : "Item one"   -> one.html; 
two  : "Item two"   -> two.html, HIDDEN; 
three: "Item three" -> three.html, if $test1 or $test2;