Error ReportingΒΆ

Parse error data is stored in property UniversalExpressionParser.IParseErrorData ParseErrorData { get; }. The class UniversalExpressionParser.IParseErrorData has a property IReadOnlyList<UniversalExpressionParser.IParseErrorItem> AllParseErrorItems { get; } that stores data on all parse errors.

Click here to see the definition of UniversalExpressionParser.IParseErrorItem

The extensions class UniversalExpressionParser.ParseExpressionResultExtensionMethods has number of helper methods, among which is string GetErrorTextWithContextualInformation(this IParsedExpressionResult parsedExpressionResult, int parsedTextStartPosition, int parsedTextEnd, int maxNumberOfCharactersToShowBeforeOrAfterErrorPosition = 50) for returning a string with error details and contextual data (i.e., text before and after the position where error happened, along with arrow pointing to the error).

Click here to see the definition of UniversalExpressionParser.ParseExpressionResultExtensionMethods

  • Below is an expression which has several errors:

 1var x = y /*operator is missing here*/x;
 2
 3{ // This code block is not closed
 4    f1(x, y, /*function parameter is missing here*/)
 5    {
 6
 7        var z = ++x + y + /*' +' is not a postfix and operand is missing */;
 8        return + /*' +' is not a postfix and operand is missing */ z + y;
 9    }
10// Closing curly brace is missing here

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult

Click to see the the error text generated by using the helper extension method UniversalExpressionParser.ParseExpressionResultExtensionMethods.GetErrorTextWithContextualInformation(...) for the errors reported by the parser for the expression above