Keywords

  • Keywords are special names (e.g., var, public, class, where) that can be specified in property IReadOnlyList<ILanguageKeywordInfo> Keywords { get; } in interface UniversalExpressionParser.IExpressionLanguageProvider, as shown in example below.

Note

Keywords are supported only if the value of property SupportsKeywords in UniversalExpressionParser.IExpressionLanguageProvider is true.

 1public class DemoExpressionLanguageProvider : IExpressionLanguageProvider
 2{
 3    ...
 4    public override IReadOnlyList<ILanguageKeywordInfo> Keywords { get; } = new []
 5    {
 6        new UniversalExpressionParser.UniversalExpressionParser(1, "where"),
 7        new UniversalExpressionParser.UniversalExpressionParser(2, "var"),
 8        ...
 9    };
10}
  • Keywords are parsed to expression items of type UniversalExpressionParser.ExpressionItems.IKeywordExpressionItem.

  • Keywords have the following two applications.

  1. One or more keywords can be placed in front of any literal (e.g., variable name), round or square braces expression, function or matrix expression, a code block. In this type of usage of keywords the parser parses the keywords and adds the list of parsed keyword expression items (i.e., list of UniversalExpressionParser.ExpressionItems.IKeywordExpressionItem objects) to list in property IReadOnlyList&lt;IKeywordExpressionItem&gt; AppliedKeywords { get; } in UniversalExpressionParser.ExpressionItems.IComplexExpressionItem for the expression item that follows the list of keywords.

  2. Custom expression parser evaluates the list of parsed keywords to determine if the expression that follows the keywords should be parsed to a custom expression item. See section Custom Expression Item Parsers for more details on custom expression parsers.

Examples of keywords

 1// Keywords "public" and "class" will be added to list in property "AppliedKeywords" in class
 2// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the parsed expression "Dog".
 3public class Dog;
 4
 5// Keywords "public" and "static will be added to list in property "AppliedKeywords" in class
 6// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the parsed expression "F1()".
 7public static F1();
 8
 9// Keywords "public" and "static" will be added to list in property "AppliedKeywords" in class
10// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the parsed expression "F1()".
11public static F1() {return 1; }
12
13// Keyword "::codeMarker" will be added to list in property "AppliedKeywords" in class
14// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the parsed expression "(x1, x2)".
15::codeMarker (x1, x2);
16
17// Keyword "::codeMarker" will be added to list in property "AppliedKeywords" in class
18// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the parsed expression "m1[2, x1]".
19::codeMarker m1[2, x1];
20
21// Keyword "::codeMarker" will be added to list in property "AppliedKeywords" in class
22// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the parsed expression "[x1, x2]".
23::codeMarker[x1, x2];
24
25// Keyword "static" will be added to list in property "AppliedKeywords" in class
26// "UniversalExpressionParser.ExpressionItems.Custom.IComplexExpressionItem" for the code block parsed expression "{}".
27static
28{
29    var x;
30}
31
32// Keyword "::pragma" will be used by custom expression parser "UniversalExpressionParser.DemoExpressionLanguageProviders.CustomExpressions.PragmaCustomExpressionItemParser" to
33// parse expressions "::pragma x2" and "::pragma x3" to custom expression items of type
34// "UniversalExpressionParser.DemoExpressionLanguageProviders.CustomExpressions.PragmaCustomExpressionItem".
35var y = x1 +::pragma x2+3*::pragma x3 +y;

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult