Literals

  • Literals are names that can be used either alone (say in operators) or can be part of more complex expressions. For example literals can precede opening square or round braces (e.g., f1 in f1(x), or m1 in m1[1, 2]), or code blocks (e.g., Dog in expression public class Dog {}).

  • Literals are parsed into expression items of type UniversalExpressionParser.ExpressionItems.ILiteralExpressionItem objects.

  • If literal precedes round or square braces, it will be stored in value of property ILiteralExpressionItem Name { get; } of UniversalExpressionParser.ExpressionItems.IBracesExpressionItem.

  • If literal precedes a code block staring marker (e.g., Dog in expression public class Dog {}), then the code block is added to the list UniversalExpressionParser.ExpressionItems.IComplexExpressionItem.Postfixes in expression item for the literal (see section Postfixes for more details on postfixes).

  • Literals are texts that cannot have space and can only contain characters validated by method UniversalExpressionParser.IExpressionLanguageProvider.IsValidLiteralCharacter(char character, int positionInLiteral, ITextSymbolsParserState textSymbolsParserState) in interface UniversalExpressionParser.IExpressionLanguageProvider. In other words, a literal can contain any character (including numeric or operator characters, a dot ‘.’, ‘_’, etc.), that is considered a valid literal character by method IExpressionLanguageProvider.IsValidLiteralCharacter(…).

Examples of literals

 1// In example below _x, f$, x1, x2, m1, and x3, Dog, Color, string, println, and Dog.Color are literals.
 2var _x = f$(x1, x2) + m1[1, x3];
 3
 4public class Dog
 5{
 6    public Color : string => "brown";
 7}
 8
 9// println is a literal and it is part of "println(Dog.Color)" braces expression item. In this example,
10// println will be parsed to an expression item UniversalExpressionParser.ExpressionItems.INamedComplexExpressionItem
11// and will be the value of property NamedExpressionItem in UniversalExpressionParser.ExpressionItems.IBracesExpressionItem
12println(Dog.Color);

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult