DiscoverLearnDocumentationGet OpenPLXSearch Contact

Model syntax

A model in OpenPLX acts as a template for variables and methods. It is similar to a class in object oriented programming and can extend from other models. They are defined by declaring a name as an unindented identifier in a document.

Model:
    foo is Real: 0.0

A model can extend other models using the is keyword.

Parent:
    foo is Real: 0.0

Child is Parent:
    foo: 1.1

Empty models

Sometimes it is useful to define models without members, in that case the : is omitted.

EmptyModelWithoutParent
Parent:
    foo is Real: 0.0

EmptyModelWithParent is Parent

Const models

It is possible to prefix a model with the const keyword indicating that it cannot be initialized multiple times and that its attributes are readonly. Const models act similar to singletons. Const models can be accessed globally without refering to an instance using their model name.

const Global:
    prop is Real: 3.0

Model:
    x is Real: Global.prop + 1.0

It is also possible to declare instances of const models however they will simply be assigned the global instance acting more like an alias.

const Global:
    prop is Real: 3.0

Model:
    global is Global
    x is Real: global.prop + 1.0

Grammar

model → "const"? IDENTIFIER
model → "const"? IDENTIFIER "is" (IDENTIFIER ".")* IDENTIFIER
model → "const"? IDENTIFIER ":" NEWLINE (INDENT (variable | assignment | method))*
model → "const"? IDENTIFIER "is" (IDENTIFIER ".")* IDENTIFIER ":" NEWLINE (INDENT (variable | assignment | method))*