User-defined operators

Sometimes it will seem to you that Parser lacks some operators. Parser allows you to define your own operators which could be later used along with system operators.

Operators in parser are methods of class MAIN, By adding new methods into this class you extend built-in set of operators.

Important notice: while defining an operator you may use not only local variables, but also global ones. By doing so, you will assign and refer to fields of class MAIN.

User-defined operators may be defined in separate files without header
@CLASS and be linked to relevant sections of a site. If you define an operator (e.g. @include[]) in such a file, every call ^include[] will be addressed to the user-defined operator.

CAUTION: If the name of the operator you define is same as a system operator's, user-defined operator will be called. Using of system operator will then be impossible. We advise you to use as few user-defined operators as possible. Consider using static methods of user-defined classes instead.

Creating classes and using their methods is far more comfortable than employing user-defined operators for the same purpose. For example: there are several sections of the site and each one needs a help section. By creating several files defining different classes, we can get methods of different classes bearing the same name. While calling these methods as static ones, we can clearly see the relation between methods and sections:

^news:help[]
^forum:help[]
^search:help[]


Examples
Place the code…
@default[a;b]
^if(
def $a){$a}{$b}

…into file
operators.p in root directory of your website.

After you have done it, you can link this module whenever you need additional operators. For example, write such a construction in your root
auto.p:

@USE
/operators.p

…and you will be able to use construction of type
^default[$form:name;Anonymous] not only on any page, but also in any user-defined class.

Details can be found in section Defining methods and user operators.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 01.04.2004