Modo, Easy Modeling Language

Documentation

Selectors

Selectors provide control over elements. Selectors can define the scope of the declaration.

This chapter gives information about the uses of selectors over elements.

Selector syntax

There are two types of selectors:

  • Left-hand side selectors
  • Right-hand side selectors

Following is the Extended BNF notation of left-hand and right-hand side selectors:


lhs selector = (

            {blank},

            universal selector | selector operand,

            {blank},

            {

                selector operator,

                {blank},

                selector operand

            }

        ),

        {

            {blank},

            comma symbol,

            {blank},

            lhs selector

        };

Left-hand side selectors have more complex structure than right-hand side selectors. The Extended BNF notation above shows that lhs selector consists of a selector operand or a universal selector, and a selector operator. Additionally, it is possible to specify more than one lhs selector by separating with comma symbol ",".


rhs selector = {blank},

        [unary selector operator],

        identifier,

        {rhs selector};

The Extended BNF notation above shows that rhs selector consists of optional unary selector operator and an identifier. In addition to that, it is possible to specify more than one rhs selector.

Universal Selector

In Modo selector syntax, "*" symbol plays an important role. This symbol is called universal selector and used to match any single element. As specified in Appendix A. Grammar, universal selector can only be used in left-hand side selectors. The main reason for this convention is, right-hand side selectors are not allowed to address more than one element.

Grouping

Modo syntax provides grouping for left-hand side selectors. Left-hand side selectors may specify more than one element at a time. This is useful for declaring identical elements.

Warning: Grouping can only be used on left-hand side selectors. Right-hand side selectors have no grouping support.

Following example shows the use of grouping:

Developer, Designer = Worker {
    FirstName = String;
    LastName = String;
}
                

The example above shows the use of grouping. Both Developer and Designer elements are of type the Worker element. These elements are separated with comma symbol.

Selector Operators

There are two types of selector operators:

  • Unary selector operators
  • Binary selector operators

This section gives information about the use of these selector operators.

Unary selector operators

Unary selector operators are the selector operators that take one selector operand.

Following is the Extended BNF notation of the unary selector operators:


unary selector operator = "$", ".", "#", "?", " ";

Following examples shows the use of unary selector operators:

.Developer { }
#Developer { }
?Developer { }
Developer $Name = "";
                

Warning: The meaning and the use of these selector operators may be interpreted differently by different Modo generators/compilers/interpreters.

Binary selector operators

Binary selector operators are the selector operators that take two selector operands.

Following is the Extended BNF notation of the binary selector operators:

selector operator = ">", "<", "+", "-", "~", "^", ":",

        "::", "%", "&", "|", "\", "/";

Following examples shows the use of binary selector operators:

Developer > $Name = "";
Developer < $Name = "";
Developer + Designer { }
Developer - Designer { }
Developer ~ Designer { }
Developer ^ Designer { }
Developer % Designer { }
Developer & Designer { }
Developer | Designer { }
Developer / Designer { }
                

Warning: The meaning and the use of these selector operators may be interpreted differently by different Modo generators/compilers/interpreters.

Selector operands

Selector operands are the components of the selection operation affected by binary and unary selector operators.

Following is the Extended BNF notation of selector operand in Modo syntax:


selector operand = {blank},

        [

            [unary selector operator],

            lhs identifier

        ],

        {blank},

        [

            (

                start group symbol,

                [

                    selector expression,

                    {

                        {blank},

                        comma symbol,

                        {blank},

                        selector expression

                    }

                ],

                {blank},

                end group symbol

            )

            |

            (

                start attribute selector symbol,

                selector expression,

                {

                    {blank},

                    comma symbol,

                    {blank},

                    selector expression

                },

                {blank},

                end attribute selector symbol

            )

        ],

        {selector operand};

The notation above shows that selector operands start with optional unary selector operator and lhs identifier. It is possible to specify a selector start with either start group symbol "(" or start attribute selector symbol "[". If a selector starts with start group symbol, it must end with end group symbol. Similarly, if a selector starts with start attribute selector symbol, it must end with end attribute selector symbol.

Selector expressions

By the help of the selector operand expressions, not only the elements but also its member elements, member element values and member methods can be used in the left-hand side selectors.

Following is the Extended BNF notation of selector expression in Modo syntax:


selector expression = {blank},

        {start group symbol},

        {blank},

        operand | expression,

        {

            {blank},

            selector expression operator,

            {blank},

            {start group symbol},

            {blank},

            operand | expression,

            {blank},

            {end group symbol},

        },

        {blank},

        {end group symbol};

The selector expression notation above shows that selector expression and expression notation have several tokens in common except the selector expression operator.

Following is the Extended BNF notation of selector expression operator:


selector expression operator = "*" | "/" | "%" | "+" | "-"

        | "<<" | ">>" | "<" | ">" | "=" | "&" | "^" | "|"

        | "<=" | ">=" | "==" | "!=" | "*=" | "/=" | "%="

        | "+=" | "-=" | "&=" | "^=" | "|=" | "$=" | "~="

        | ".=" | "#=" | "?=" | ":=" | "&&" | "||";