Postfixes

Postfixes are one or more expression items that are placed after some other expression item, and are added to the list in property Postfixes in interface UniversalExpressionParser.ExpressionItems.IComplexExpressionItem for the expression item that the postfixes are placed after.

Currently Universal Expression Parser supports two types of postfixes:

1) Code block expression items

Code block expression items that are parsed to UniversalExpressionParser.ExpressionItems.ICodeBlockExpressionItem that succeed another expression item are added as postfixes to the expression item they succeed.

Note

The following are expression types that can have postfixes: Literals, such a x1 or Dog, braces expression items, such as f(x1), (y), m1[x1], [x2], or custom expression items for which property CustomExpressionItemCategory in interface UniversalExpressionParser.ExpressionItems.Custom.ICustomExpressionItem is equal to UniversalExpressionParser.ExpressionItems.Custom.CustomExpressionItemCategory.Regular.

  • In the example below the code block expression item of type UniversalExpressionParser.ExpressionItems.ICodeBlockExpressionItem parsed from expression that starts with ‘{’ and ends with ‘}’” will be added to the list Postfixes in UniversalExpressionParser.ExpressionItems.IComplexExpressionItem for the literal expression item parsed from expression Dog.

1public class Dog
2{
3   // This code block will be added as a postfix to literal expression item parsed from "Dog"
4}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult

2) Custom postfix expression items

Custom expression items of type UniversalExpressionParser.ExpressionItems.Custom.ICustomExpressionItem with property CustomExpressionItemCategory equal to UniversalExpressionParser.ExpressionItems.Custom.CustomExpressionItemCategory.Postfix that succeed another expression item are added as postfixes to the expression item they succeed.

  • In the example below the two custom expression items of type UniversalExpressionParser.DemoExpressionLanguageProviders.CustomExpressions.IWhereCustomExpressionItem parsed from expressions that start with “where” and end with “whereend”” as well as the code block will be added as postfixes to literal expression item parsed from “Dog”.

Note

For more details on custom expression items see section Custom Expression Item Parsers.

1::types[T1,T2, T3] F1(x:T1, y:T2, z: T3)
2// The where below will be added as a postfix to expression item parsed from "F1(x:T1, y:T2, z: T3)
3where T1:int where T2:double whereend
4// The where below will be added as a postfix to expression item parsed from "F1(x:T1, y:T2, z: T3)
5where T3:T1  whereend
6{
7    // This code block will be added as a postfix to expression item parsed from "F1(x:T1, y:T2, z: T3).
8}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult

Note

The list of postfixes can include both types of postfixes at the same time (i.e., custom expression items as well as a code block postfix).

  • Example of a code block postfix used to model function body:

 1// More complicated cases
 2// In the example below the parser will apply operator ':' to 'f2(x1:int, x2:int)' and 'int'
 3// and will add the code block after 'int' as a postfix to 'int'.
 4// The evaluator that processes the parsed expression can do farther transformation so that the code block is assigned to
 5// some new property in some wrapper for an expression for 'f2(x1:int, x2:int)', so that the code block belongs to the function, rather than
 6// to the returned type 'int' of function f2.
 7f2(x1:int, x2:int) : int
 8{
 9   f3() : int
10   {
11       var result = x1+x2;
12           println("result='"+result+"'");
13           return result;
14   }
15
16   return f3();
17}
18
19var myFunc = f2(x1:int, x2:int) =>
20{
21    println(exp ^ (x1 + x2));
22}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult

  • Example of code block postfix used to model class definition:

 1// In the example below the parser will apply operator ':' to literal 'Dog' (with keywords public and class) and
 2// braces '(Anymal, IDog)' and will add the code block after '(Anymal, IDog)' as a postfix to '(Anymal, IDog)'.
 3// The evaluator that processes the parsed expression can do farther transformation so that the code block is assigned to
 4// some new property in some wrapper for an expression for 'Dog', so that the code block belongs to the 'Dog' class, rather than
 5// to the braces for public classes in '(Anymal, IDog)'.
 6public class Dog : (Anymal, IDog)
 7{
 8    public Bark() : void
 9    {
10        println("Bark.");
11    }
12}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult

  • Below are some more examples of postfixes with different expression items:

 1f1(x1)
 2{
 3    // Code block added to postfixes list for braces expression "f1(x1)"
 4    return x2*y1;
 5}
 6
 7m1[x2]
 8{
 9    // Code block added to postfixes list for braces expression "m1[x2]"
10    x:2*3
11}
12
13(x3)
14{
15    // Code block added to postfixes list for braces expression "(x3)"
16    return x3*2;
17}
18
19[x4]
20{
21    // Code block added to postfixes list for braces expression "[x4]"
22    x4:2*3
23}
24
25class Dog
26{
27    // Code block added to postfixes list for literal expression "Dog"
28}
29
30::pragma x
31{
32    // Code block added to custom expression item IPragmaCustomExpressionItem parsed from "::pragma x"
33}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult