public PseudoTest(string text, Type type, bool valid, ParseErrorType error) { SelectorText = text; ParseType = type; IsValid = valid; Error = error; }
internal ParseError(ParseErrorType errorType, ParseErrorLocation location, string customText) : this() { ErrorType = errorType; Location = location; Text = customText; }
private ParseErrorType HandleOperatorPrecedence(ParseContext context, IOperator currentOperator) { ParseErrorType errorType = ParseErrorType.None; IOperator lastOperator = _operators.Peek(); if (currentOperator.Precedence < lastOperator.Precedence || (currentOperator.Precedence == lastOperator.Precedence && currentOperator.Associativity == Associativity.Left)) { // New operator has lower or equal precedence. We need to make a tree from // the topmost operator and its operand(s). Example: a*b+c. + has lower priority // and a and b should be on the stack along with * on the operator stack. // Repeat until there are no more higher precendece operators on the stack. // If operator cas right associativity (exponent), it needs to be processed right away. // Consider the expression a~b~c. If the operator ~ has left associativity, this // expression is interpreted as (a~b)~c. If the operator has right associativity, // the expression is interpreted as a~(b~c). a^b^c = a^(b^c). // Left -associated indexer works like x[1][2] = (x[1])[2] errorType = this.ProcessHigherPrecendenceOperators(context, currentOperator); } if (errorType == ParseErrorType.None) { _operators.Push(currentOperator); } return(errorType); }
private ParseErrorType ProcessHigherPrecendenceOperators(ParseContext context, IOperator currentOperator) { Debug.Assert(_operators.Count > 1); ParseErrorType errorType = ParseErrorType.None; Association association = currentOperator.Association; // At least one operator above sentinel is on the stack. do { errorType = MakeNode(context); if (errorType == ParseErrorType.None) { IOperator nextOperatorNode = _operators.Peek(); if (association == Association.Left && nextOperatorNode.Precedence <= currentOperator.Precedence) { break; } if (association == Association.Right && nextOperatorNode.Precedence < currentOperator.Precedence) { break; } } } while (_operators.Count > 1 && errorType == ParseErrorType.None); return(errorType); }
// Returns true iff the script fails to compile and the first error is of the given type. public bool RunCompileFailTest(string script, ParseErrorType errorType, bool verbose = false) { if (verbose) { Log("-> " + script); } List <ParseErrorInst> errors = new List <ParseErrorInst>(); object res = _Parse(_GetScriptNameFromScript(script), script, ref errors, false, false); if (null != res && errors.Count == 0) { if (!verbose) { LogError("-> " + script); } LogError("ERROR: Expected 'error' script to fail to compile."); return(false); } if (errors.Count > 0 && ParseErrorType.Any != errorType && errors[0].type != errorType) { if (!verbose) { LogError("-> " + script); } LogError("ERROR: 'error' script returned error (" + errors[0].type + "), expected (" + errorType + ")."); return(false); } return(true); }
/// <summary></summary> /// <param name="type"></param> /// <param name="noThrow">Does the caller want exceptions to be thrown on errors?</param> /// <param name="input"></param> /// <param name="errorState"></param> /// <returns>True if no error handling was needed. Else, an exception is throw (if allowed)</returns> static bool ParseHandleError(ParseErrorType type, bool noThrow, string input , TextStreamReadErrorState errorState) { Exception detailsException = null; switch (type) { case ParseErrorType.NoInput: if (noThrow) { return(false); } detailsException = new ArgumentException ("Input null or empty", nameof(input)); break; case ParseErrorType.InvalidValue: detailsException = new ArgumentException(string.Format (Util.InvariantCultureInfo, "Couldn't parse \"{0}\"", input), nameof(input)); break; default: return(true); } if (noThrow == false) { errorState.ThrowReadExeception(detailsException); } errorState.LogReadExceptionWarning(detailsException); return(true); }
private OperationType HandleOperator(ParseContext context, out ParseErrorType errorType) { bool isUnary; errorType = this.HandleOperator(context, null, out isUnary); return(isUnary ? OperationType.UnaryOperator : OperationType.BinaryOperator); }
public ParseError(ParseErrorType type, int line, int index, string fileName) { Type = type; Index = index; Line = line; FileName = fileName; }
public ParseError(ParseErrorType type, Vector2Int pos, int pos1, char character) { this.type = type; this.pos = pos; pos1d = pos1; this.character = character; }
/// <summary> /// Create and Add Parse error to the current feed result. /// </summary> /// <param name="errorType">Type of parse error.</param> /// <param name="nodeInformation">Current node base information.</param> /// <param name="feed">Current feed result.</param> /// <param name="content">Current node content data. (Optonal)</param> /// <param name="message">Parse error message. (Optional)</param> protected void SetParseError(ParseErrorType errorType, NodeInformation nodeInformation, Feed feed, string?content = null, string?message = null) { //Create and Add Parse error to the current feed result var error = ParseError.Create(nodeInformation, ToString(), errorType, feed.CurrentParseType, content, message); (feed.ParseError ??= new List <ParseError>()).Add(error); Debug.WriteLine(error); }
static ParseErrorType ParseVerifyResult(ParseErrorType result, bool parseResult) { Util.MarkUnusedVariable(ref result); return(parseResult ? ParseErrorType.None : ParseErrorType.InvalidValue); }
private ParseError NewParseError(ParseErrorType error, SourceLineInstruction line, int argIndex) { return(new ParseError( error, line.LineIndex, line.Label.Length + 2 + line.Parameters.Take(argIndex).Sum(p => p.Length), line.FileName)); }
private OperationType HandleSquareBrackets(ParseContext context, out ParseErrorType errorType) { var indexer = new Indexer(); indexer.Parse(context, null); errorType = HandleOperatorPrecedence(context, indexer); return(OperationType.Function); }
internal void LogCompileError(ParseErrorType error, string msg) { ParseErrorInst inst = new ParseErrorInst(error, msg); _parseErrors.Add(inst); if (logCompileErrors) { LogError(inst.ToString()); } }
/// <summary> /// Initializes a new ParseError with error information. /// </summary> /// <param name="node">Current node information.</param> /// <param name="parser">Current parser.</param> /// <param name="errorType">Current error type.</param> /// <param name="parseType">Current parse type.</param> /// <param name="parseValue">Current parse value.</param> /// <param name="message">Error message.</param> public ParseError(NodeInformation node, string parser, ParseErrorType errorType, ParseType parseType, string?parseValue = null, string?message = null) { //Init Node = node; Parser = parser; ParseErrorType = errorType; ParseType = parseType; ParseValue = parseValue; Message = message; }
private OperationType HandleLambda(ParseContext context, out ParseErrorType errorType) { errorType = ParseErrorType.None; var lambda = new Lambda(); lambda.Parse(context, null); _operands.Push(lambda); return(OperationType.Operand); }
/// <summary> /// Creates a new instance of a parse error /// </summary> /// <param name="errorType">Error type of the parse error</param> /// <param name="itemName">Item name of the parse error</param> /// <param name="itemValue">Item value of the parse error</param> /// <param name="message">Optional. Message of the pare error</param> internal ParseError(ParseErrorType errorType, string itemName, string?itemValue, string?message = null) { if (String.IsNullOrWhiteSpace(itemName)) { throw new ArgumentException(Resources.MissingRequiredParameterValueErrorMessage, nameof(itemName)); } this.ErrorType = errorType; this.ItemName = itemName; this.ItemValue = itemValue; this.Message = message ?? String.Empty; }
public ParseError(ParseErrorType parseErrorType, int lineNum, int columnNum, Lex.Token errorInfo) : base(lineNum, columnNum) { if (errorInfo is Lex.Word) { Lex.Word word = errorInfo as Lex.Word; ErrorInfo = word.Lexeme; } else { ErrorInfo = errorInfo.TokenInfo; } ParseErrorType = parseErrorType; }
/// <summary> /// Adds an error at the current parse location - usually after the last /// child. When there are no children, the error goes before any future children. /// </summary> internal void AddParseError(ParseErrorType errorType) { if (Count > 0) { this[Count - 1].AddParseError(errorType, ParseErrorLocation.AfterItem); } else if (_parent != null) { _parent.AddParseError(errorType, ParseErrorLocation.BeforeItem); } else { Debug.Fail("Can't add this parse error anywhere"); } }
private static void AddError(IList <ParseError> errors, ParseErrorType type, string message, ErrorContext context) { // Extract line info var regexLine = new Regex(", line (\\d+), position \\d+\\.$"); var matchLine = regexLine.Match(context.Error.Message); var errorPosInfo = new ErrorPositionInfo(); if (matchLine.Success) { errorPosInfo.LineNumber = int.Parse(matchLine.Groups[1].Value); } errors.Add(new Parsers.ParseError(type, message, errorPosInfo)); }
private OperationType HandleOpenBrace(ParseContext context, out ParseErrorType errorType) { var tokens = context.Tokens; errorType = ParseErrorType.None; // Separate expression from function call. In case of // function call previous token is either closing indexer // brace or closing function brace. Identifier with brace // is handled up above. // Indentifier followed by a brace needs to be analyzed // so we can tell between previous expression that ended // with identifier and identifier that is a function name: // // a <- 2*b // (expression) // // in this case b is not a function name. Similarly, // // a <- 2*b[1] // (expression) // // is not a function call operator over b[1]. if (_operators.Count > 1 || _operands.Count > 0) { // We are not in the beginning of the expression if (tokens.PreviousToken.TokenType == RTokenType.CloseBrace || tokens.PreviousToken.TokenType == RTokenType.CloseSquareBracket || tokens.PreviousToken.TokenType == RTokenType.CloseDoubleSquareBracket || tokens.PreviousToken.IsVariableKind()) { var functionCall = new FunctionCall(); functionCall.Parse(context, null); errorType = HandleOperatorPrecedence(context, functionCall); return(OperationType.Function); } } var group = new Group(); group.Parse(context, null); _operands.Push(group); return(OperationType.Operand); }
private ParseErrorType HandleOperator(ParseContext context, IAstNode parent, out bool isUnary) { ParseErrorType errorType = ParseErrorType.None; // If operands stack is empty the operator is unary. // If operator is preceded by another operator, // it is interpreted as unary. TokenOperator currentOperator = new TokenOperator(_operands.Count == 0); currentOperator.Parse(context, null); isUnary = currentOperator.IsUnary; IOperator lastOperator = _operators.Peek(); if (isUnary && lastOperator != null && lastOperator.IsUnary) { // !!!x is treated as !(!(!x))) // Step back and re-parse as expression context.Tokens.Position -= 1; var exp = new Expression(inGroup: false); if (exp.Parse(context, null)) { _operands.Push(exp); return(ParseErrorType.None); } } if (currentOperator.Precedence <= lastOperator.Precedence && !(currentOperator.OperatorType == lastOperator.OperatorType && currentOperator.Association == Association.Right)) { // New operator has lower or equal precedence. We need to make a tree from // the topmost operator and its operand(s). Example: a*b+c. + has lower priority // and a and b should be on the stack along with * on the operator stack. // Repeat until there are no more higher precendece operators on the stack. errorType = this.ProcessHigherPrecendenceOperators(context, currentOperator); } if (errorType == ParseErrorType.None) { _operators.Push(currentOperator); } return(errorType); }
internal bool RemoveParseError(ParseErrorType type) { bool removed = false; if (_parseErrors != null) { for (int i = _parseErrors.Count - 1; i >= 0; i--) { if (_parseErrors[i].ErrorType == type) { _parseErrors.RemoveAt(i); removed = true; } } } return(removed); }
static bool HandleParseError(ParseErrorType errorType, bool noThrow, string s, int startIndex , Text.IHandleTextParseError handler = null) { Exception detailsException = null; switch (errorType) { case ParseErrorType.NoInput: if (noThrow) { return(false); } detailsException = new ArgumentException ("Input null or empty", nameof(s)); break; case ParseErrorType.InvalidValue: detailsException = new ArgumentException(string.Format (Util.InvariantCultureInfo, "Couldn't parse '{0}'", s), nameof(s)); break; case ParseErrorType.InvalidStartIndex: detailsException = new ArgumentOutOfRangeException(nameof(s), string.Format (Util.InvariantCultureInfo, "'{0}' is out of range of the input length of '{1}'", startIndex, s.Length)); break; default: return(true); } if (handler == null) { handler = Text.Util.DefaultTextParseErrorHandler; } if (noThrow == false) { handler.ThrowReadExeception(detailsException); } handler.LogReadExceptionWarning(detailsException); return(true); }
private OperationType HandleKeyword(ParseContext context, out ParseErrorType errorType) { errorType = ParseErrorType.None; var keyword = context.TextProvider.GetText(context.Tokens.CurrentToken); if (IsTerminatingKeyword(keyword)) { return(OperationType.EndOfExpression); } errorType = HandleKeyword(context, keyword); if (errorType == ParseErrorType.None) { return(OperationType.Operand); } return(_previousOperationType); }
private ParseErrorType ProcessHigherPrecendenceOperators(ParseContext context, IOperator currentOperator) { Debug.Assert(_operators.Count > 1); ParseErrorType errorType = ParseErrorType.None; Associativity associativity = currentOperator.Associativity; IOperator nextOperatorNode = _operators.Peek(); // At least one operator above sentinel is on the stack. do { // If associativity is right, we stop if the next operator // on the stack has lower or equal precedence than the current one. // Example: in 'a^b^c' before pushing last ^ on the stack // only b^c is processed since a^b^c = a^(b^c). if (associativity == Associativity.Right && nextOperatorNode.Precedence <= currentOperator.Precedence) { break; } errorType = MakeNode(context); if (errorType == ParseErrorType.None) { nextOperatorNode = _operators.Peek(); // If associativity is left, we stop if the next operator // on the stack has lower precedence than the current one. // Example: in 'a+b*c*d+e' before pushing last + on the stack // we need to make subtree out of b*c*d. if (associativity == Associativity.Left && nextOperatorNode.Precedence < currentOperator.Precedence) { break; } } } while (_operators.Count > 1 && errorType == ParseErrorType.None); return(errorType); }
internal bool AddParseError(ParseErrorType type, ParseErrorLocation location, string customText) { if (_parseErrors == null) { _parseErrors = new List <ParseError>(); } else { // Check if it was already added for (int i = 0; i < _parseErrors.Count; i++) { if (_parseErrors[i].ErrorType == type && _parseErrors[i].Location == location) { return(false); } } } _parseErrors.Add(new ParseError(type, location, customText)); return(true); }
private ParseErrorType HandleKeyword(ParseContext context, string keyword) { ParseErrorType errorType = ParseErrorType.None; if (keyword.Equals("function", StringComparison.Ordinal)) { // Special case 'exp <- function(...) { } FunctionDefinition funcDef = new FunctionDefinition(); funcDef.Parse(context, null); // Add to the stack even if it has errors in order // to avoid extra errors _operands.Push(funcDef); } else if (keyword.Equals("if", StringComparison.Ordinal)) { // If needs to know parent expression since // it must figure out how to handle 'else' // when if is without { }. context.Expressions.Push(this); InlineIf inlineIf = new InlineIf(); inlineIf.Parse(context, null); context.Expressions.Pop(); // Add to the stack even if it has errors in order // to avoid extra errors _operands.Push(inlineIf); } else { errorType = ParseErrorType.UnexpectedToken; } return(errorType); }
public ParseError(ParseErrorType type, string message, ErrorPositionInfo position) { Type = type; Message = message; Position = position; }
private OperationType HandleOperator(ParseContext context, out ParseErrorType errorType) { bool isUnary; errorType = this.HandleOperator(context, null, out isUnary); return isUnary ? OperationType.UnaryOperator : OperationType.BinaryOperator; }
private OperationType HandleOpenBrace(ParseContext context, out ParseErrorType errorType) { TokenStream<RToken> tokens = context.Tokens; errorType = ParseErrorType.None; // Separate expression from function call. In case of // function call previous token is either closing indexer // brace or closing function brace. Identifier with brace // is handled up above. // Indentifier followed by a brace needs to be analyzed // so we can tell between previous expression that ended // with identifier and identifier that is a function name: // // a <- 2*b // (expression) // // in this case b is not a function name. Similarly, // // a <- 2*b[1] // (expression) // // is not a function call operator over b[1]. if (_operators.Count > 1 || _operands.Count > 0) { // We are not in the beginning of the expression if (tokens.PreviousToken.TokenType == RTokenType.CloseBrace || tokens.PreviousToken.TokenType == RTokenType.CloseSquareBracket || tokens.PreviousToken.TokenType == RTokenType.CloseDoubleSquareBracket || tokens.PreviousToken.IsVariableKind()) { FunctionCall functionCall = new FunctionCall(); functionCall.Parse(context, null); errorType = HandleFunctionOrIndexer(functionCall); return OperationType.Function; } } Group group = new Group(); group.Parse(context, null); _operands.Push(group); return OperationType.Operand; }
private void ErrorRecord(ParseErrorType parseErrorType) { ErrorBase.ErrorManager.AddParseError(new ParseError(parseErrorType, currentToken.LineNumber , currentToken.ColumnNumber, currentToken)); }
public override void SyntaxError(Antlr4.Runtime.IRecognizer recognizer, Antlr4.Runtime.IToken offendingSymbol, int line, int charPositionInLine, string msg, Antlr4.Runtime.RecognitionException e) { errorType = ParseErrorType.SyntaxError; }
private OperationType HandleLambda(ParseContext context, out ParseErrorType errorType) { errorType = ParseErrorType.None; Lambda lambda = new Lambda(); lambda.Parse(context, null); _operands.Push(lambda); return OperationType.Operand; }
public static string GetText(ParseErrorType errorType) { switch (errorType) { default: return Resources.ParseError_General; case ParseErrorType.UnexpectedToken: return Resources.ParseError_UnexpectedToken; case ParseErrorType.IndentifierExpected: return Resources.ParseError_IndentifierExpected; case ParseErrorType.NumberExpected: return Resources.ParseError_NumberExpected; case ParseErrorType.LogicalExpected: return Resources.ParseError_LogicalExpected; case ParseErrorType.StringExpected: return Resources.ParseError_StringExpected; case ParseErrorType.ExpressionExpected: return Resources.ParseError_ExpressionExpected; case ParseErrorType.LeftOperandExpected: return Resources.ParseError_LeftOperandExpected; case ParseErrorType.RightOperandExpected: return Resources.ParseError_RightOperandExpected; case ParseErrorType.OpenCurlyBraceExpected: return Resources.ParseError_OpenCurlyBraceExpected; case ParseErrorType.CloseCurlyBraceExpected: return Resources.ParseError_CloseCurlyBraceExpected; case ParseErrorType.OpenBraceExpected: return Resources.ParseError_OpenBraceExpected; case ParseErrorType.CloseBraceExpected: return Resources.ParseError_CloseBraceExpected; case ParseErrorType.OpenSquareBracketExpected: return Resources.ParseError_OpenSquareBracketExpected; case ParseErrorType.CloseSquareBracketExpected: return Resources.ParseError_CloseSquareBracketExpected; case ParseErrorType.OperatorExpected: return Resources.ParseError_OperatorExpected; case ParseErrorType.FunctionExpected: return Resources.ParseError_FunctionExpected; case ParseErrorType.InKeywordExpected: return Resources.ParseError_InKeywordExpected; case ParseErrorType.UnexpectedEndOfFile: return Resources.ParseError_UnexpectedEndOfFile; case ParseErrorType.FunctionBodyExpected: return Resources.ParseError_FunctionBodyExpected; } }
private OperationType HandleSquareBrackets(ParseContext context, out ParseErrorType errorType) { Indexer indexer = new Indexer(); indexer.Parse(context, null); errorType = HandleFunctionOrIndexer(indexer); return OperationType.Function; }
public ParseError(ParseErrorType errorType, ErrorLocation location, ITextRange range) : base(range) { this.ErrorType = errorType; this.Location = location; }
private OperationType HandleKeyword(ParseContext context, out ParseErrorType errorType) { errorType = ParseErrorType.None; string keyword = context.TextProvider.GetText(context.Tokens.CurrentToken); if (IsTerminatingKeyword(keyword)) { return OperationType.EndOfExpression; } errorType = HandleKeyword(context, keyword); if (errorType == ParseErrorType.None) { return OperationType.Operand; } return _previousOperationType; }
public MissingItemParseError(ParseErrorType errorType, RToken token) : base(errorType, ErrorLocation.AfterToken, token) { }
public override void ReportAmbiguity(Antlr4.Runtime.Parser recognizer, Antlr4.Runtime.Dfa.DFA dfa, int startIndex, int stopIndex, bool exact, Antlr4.Runtime.Sharpen.BitSet ambigAlts, Antlr4.Runtime.Atn.ATNConfigSet configs) { errorType = ParseErrorType.ReportAmbiguity; }