public override void ReportError(RecognitionException e) { if (currentScope.EnclosingScope != null) { currentScope = currentScope.EnclosingScope; currentScope = currentScope.EnclosingScope; } ParserException syntaxError = ThrowHelper.SyntaxError(SourceName, e.Line, e.CharPositionInLine, input.ToString(), GetErrorMessage(e, tokenNames), e); if (e.Token != null && e.Token.Type == EOF) { PartialStatement error = new PartialStatement(syntaxError); ErrorList.Add(error); if (StopOnError) { throw error; } return; } base.ReportError(e); ErrorList.Add(syntaxError); if (StopOnError) { throw syntaxError; } }
// Throw an exception private void ThrowError(Token token, string messageFormat, params object[] arguments) { ParserException exception; string msg = System.String.Format(messageFormat, arguments); if (token.LineNumber.HasValue) { exception = new ParserException("Line " + token.LineNumber + ": " + msg) { Index = token.Range[0], LineNumber = token.LineNumber.Value, Column = token.Range[0] - _lineStart + 1 }; } else { exception = new ParserException("Line " + _lineNumber + ": " + msg) { Index = _index, LineNumber = _lineNumber, Column = _index - _lineStart + 1 }; } exception.Description = msg; throw exception; }
public static ParserException CreateParserException03() { Error errorCode = Error.ErrorDoubleFormat; int pos = int.MinValue; ParserException parserException = new ParserException(errorCode, pos); return(parserException); }
public static ParserException CreateParserException02() { Error errorCode = Error.NoParenBefore; int pos = 1; ParserException parserException = new ParserException(errorCode, pos); return(parserException); }
public static ParserException CreateParserException01() { Error errorCode = Error.UnrecogniseChar; int pos = 0; ParserException parserException = new ParserException(errorCode, pos); return(parserException); }
private ParserException GenerateParserException() { ParserException pe = new ParserException("Fout tijdens het verwerken van de gegevens."); pe.Data["TrafficPage"] = trafficPage; return(pe); }
public GherkinParserException(ParserException PE) { ErrorType = eErrorType.Error; this.mParserException = PE; Line = mParserException.Location.Line; Column = mParserException.Location.Column; Error = mParserException.Message; }
public void TestBuildException02() { Parser parser = new Parser(); Accessor parserAccesor = ReflectionAccessor.Wrap(parser); //Test Procedure Call ParserException parExcept = (ParserException)parserAccesor.Call("BuildException", Error.CharNotEnd, new Context()); //Post Condition Check }
private void StartSendTalkback(ParserException pe) { if ((SendTalkbackThread == null) || (SendTalkbackThread.ThreadState != System.Threading.ThreadState.Running)) { SendTalkbackThread = new Thread(SendTalkback); UpdateThreadCount(1); SendTalkbackThread.Start(pe); } }
public void TestParseErrorResponse() { string rawResponse = "{\n\"Message\": \"An error has occurred.\"\n}"; TestDelegate action = () => ScItemsParser.Parse(rawResponse, "web", CancellationToken.None); ParserException exception = Assert.Throws <ParserException>(action, "ParserException should be here"); Assert.AreEqual("[Sitecore Mobile SDK] Data from the internet has unexpected format{\n \"Message\": \"An error has occurred.\"\n}", exception.Message); }
private static void DoWriteError(ParserException e) { Console.Error.WriteLine(e.Message); if (e.Context != null) { Console.Error.WriteLine(e.Context); Console.Error.WriteLine("{0}^", new string(' ', e.Col - 1)); } }
private static void DoWriteError(ParserException e) { Console.Error.WriteLine(e.Message); if (e.Context != null) { Console.Error.WriteLine(e.Context); Console.Error.WriteLine("{0}^", new string(' ', e.Col - 1)); } }
private void WriteRuleObject(TransportRule transportRule) { JournalingRule journalingRule = null; ParserException ex = null; try { journalingRule = (JournalingRule)JournalingRuleParser.Instance.GetRule(transportRule.Xml); } catch (ParserException ex2) { ex = ex2; } Exception ex3 = null; if (journalingRule != null && journalingRule.GccRuleType != GccType.None && !this.LawfulInterception) { return; } if (journalingRule != null && journalingRule.GccRuleType == GccType.None && this.LawfulInterception) { return; } JournalRuleObject journalRuleObject; if (journalingRule == null) { journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CorruptRule(transportRule.Name, ex.Message)); } else if (journalingRule.IsTooAdvancedToParse) { journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CannotParseRuleDueToVersion(transportRule.Name)); } else { journalRuleObject = new JournalRuleObject(); try { journalRuleObject.Deserialize(journalingRule); } catch (RecipientInvalidException ex4) { ex3 = ex4; } catch (JournalRuleCorruptException ex5) { ex3 = ex5; } } if (ex3 != null) { journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CorruptRule(transportRule.Name, ex3.Message)); } journalRuleObject.SetTransportRule(transportRule); this.WriteResult(journalRuleObject); }
private static void WarnError(ParserException E) { Console.Clear(); //COLORZ Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(E.Message); Console.ForegroundColor = ConsoleColor.White; }
public void Print(ParserException e) { for (int i = 0; i < e.Messages.Count; i++) { PrintError(e.Lines[i], e.Letters[i], e.Messages[i], GetLine(e.Lines[i] - 1)); } }
public void Tolerate(ParserException error) { if (Tolerant) { RecordError(error); } else { throw CreateException(error.Index, error.Message); } }
public void Tolerate(ParserException error) { if (Tolerant) { RecordError(error); } else { throw error; } }
public static ParserException[] GetParserExceptions(this ParserException parserException) { var composite = parserException as CompositeParserException; if (composite != null) { return(composite.Errors.ToArray()); } return(new[] { parserException }); }
private static void PardonOrDeath(ParserException e, bool forgive) { if (forgive) { Debug.WriteLine("Warning: Finishing Acf file parsing because an error was encountered."); } e.LogErrorString(); if (!forgive) { throw e; } }
public void JumpToErrorLocation() { if (!Enabled || m_ExpressionTextBox == null || m_PrevFinishedJob == null || m_PrevFinishedJob.Error == null || m_PrevFinishedJob.UserData != (IntPtr)m_MostRecentUndoEntryId) { return; } ParserException pex = m_PrevFinishedJob.Error as ParserException; m_ExpressionTextBox.Select(Math.Min(m_ExpressionTextBox.TextLength, pex.ErrorPos), 0); }
/* * Handles a ParserException. * Sets error indicator to true, * prints the error message and * skips to the beginning of the next statement. */ void Error(ParserException e) { errored = true; if (e.lexeme == null) { io.WriteLine("Parser error at <end of file>: {0}, got no token", e.Message); } else { io.WriteLine("Parser error at {0}: {1}, got token: {2}", e.lexeme.position, e.Message, e.lexeme.ToString()); } SkipToNextStatement(); }
protected void OnParserException(ParserException pEx) { //Change color of text : http://stackoverflow.com/questions/29008274/how-to-change-text-color-at-icsharpcode-avalonedit-texteditor this.HighlightedLine.ErrorLines.Add(pEx.ParserErrorLine + 1); this.Dispatcher.Invoke(new Action(() => { this.InternTextEdit.TextArea.Caret.Line = pEx.ParserErrorLine + 1; this.InternTextEdit.TextArea.TextView.Redraw(); })); MessageBox.Show(pEx.Message); }
private void RaiseParserExceptionEvent(Exception exception) { if (ParserException == null) { return; } ParserExceptionEventArgs e = new ParserExceptionEventArgs(exception); foreach (EventHandler <ParserExceptionEventArgs> del in ParserException.GetInvocationList()) { del.BeginInvoke(this, e, AsyncCallBackRaiseParserExceptionEvent, del); } }
public void TestInternalError01() { ParserException parserException = ParserException.InternalError(); #region Record State ValueRecorder recorder = new ValueRecorder(); recorder.Record <string>(delegate { return((string)parserException.HelpLink); }); recorder.Record <string>(delegate { return((string)parserException.Message); }); recorder.Record <string>(delegate { return((string)parserException.Source); }); recorder.Record <string>(delegate { return((string)parserException.StackTrace); }); recorder.FinishRecording(); #endregion }
public override void ReportError(RecognitionException e) { ParserException syntaxError = ThrowHelper.SyntaxError(SourceName, e.Line, e.CharPositionInLine, input.ToString(), "Invalid syntax", e); if (e.UnexpectedType == EOF) { throw new PartialStatement(syntaxError); } base.ReportError(e); //Console.WriteLine("Error in lexer at line " + e.Line + ":" + e.CharPositionInLine); throw syntaxError; }
/// <summary>Create the parser to read grammar definition</summary> /// <exclude/> private static void CreateMetaParser() { if (_instance != null) { return; } int step = 1; TextBuffer buffer = new FlatBuffer(MetaParser.SoftMetaGrammarAndSettings); CodeDocument metaGrammarDoc = null; try { // Hard coded parser Parser hardcodeParser = GetHardCodeParser(buffer.Status); if (buffer.Status.Error == null) { step = 2; // Use hard coded grammar to read meta grammar. metaGrammarDoc = hardcodeParser.ParseString(buffer); string gg = metaGrammarDoc.ToMarkup(); step = 3; } if (buffer.Status.Error == null) { _instance = new Parser() { Level = 2 }; ParserBuilder.BuildRules(_instance, metaGrammarDoc, buffer.Status); } } catch (Exception e) { // if an exception occurs under parsing MetaGrammar it is an HardGrammar error var e2 = new ParserException((step <= 2 ? HardGrammar_ : MetaGrammar_) + " " + e.Message); if (e is ParserException) { e2.AllErrors = ((ParserException)e).AllErrors; } throw e2; } if (buffer.Status.Error != null) { // if an proces-error occurs under parsing MetaGrammar it is an MetaGrammar error var e2 = new ParserException((step == 1 ? HardGrammar_ : MetaGrammar_) + " " + buffer.Status.Error.Message); e2.AllErrors = buffer.Status.AllErrors; throw e2; } }
// Throw an exception private void ThrowError(Token token, string messageFormat, params object[] arguments) { string msg = System.String.Format(messageFormat, arguments); int lineNumber = token.LineNumber ?? _lineNumber; var error = new ParseError( description: msg, source: _source, index: token.Range[0], position: new Position(token.LineNumber ?? _lineNumber, token.Range[0] - _lineStart + 1)); var exception = new ParserException("Line " + lineNumber + ": " + msg, error); throw exception; }
public static ParserException CreateError(this IErrorHandler handler, int index, int line, int col, string description) { var msg = $"Line {line}': {description}"; var error = new ParserException(msg) { Index = index, Column = col, LineNumber = line, Description = description, Source = handler.Source }; return(error); }
public void TestParenNotMatch01() { char paren = char.MinValue; ParserException parserException = ParserException.ParenNotMatch(paren); #region Record State ValueRecorder recorder = new ValueRecorder(); recorder.Record <string>(delegate { return((string)parserException.HelpLink); }); recorder.Record <string>(delegate { return((string)parserException.Message); }); recorder.Record <string>(delegate { return((string)parserException.Source); }); recorder.Record <string>(delegate { return((string)parserException.StackTrace); }); recorder.FinishRecording(); #endregion }
public void TestNoParenBefore01() { string paren = string.Empty; ParserException parserException = ParserException.NoParenBefore(paren); #region Record State ValueRecorder recorder = new ValueRecorder(); recorder.Record <string>(delegate { return((string)parserException.HelpLink); }); recorder.Record <string>(delegate { return((string)parserException.Message); }); recorder.Record <string>(delegate { return((string)parserException.Source); }); recorder.Record <string>(delegate { return((string)parserException.StackTrace); }); recorder.FinishRecording(); #endregion }
public void TestParserExceptionConstructor01() { string msg = string.Empty; ParserException parserException = new ParserException(msg); #region Record State ValueRecorder recorder = new ValueRecorder(); recorder.Record((string)parserException.HelpLink); recorder.Record((string)parserException.Message); recorder.Record((string)parserException.Source); recorder.Record((string)parserException.StackTrace); recorder.FinishRecording(); #endregion }
// Unfortunately, due to a debugger "bug", the exception has to be caught and transferred into a cancelled event // this cancel event type is AsyncParserResultType. It is passed to AsyncParser_RunWorkerCompleted(). void AsyncParser_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { AsyncParserResultType Result = new AsyncParserResultType(); //make sure that double typed numbers are converted with decimal point (not comma!) to string System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); try { AsyncParserJob job = e.Argument as AsyncParserJob; Tikz_ParseTree tp = TikzParser.Parse(job.code); Result.ParseTree = tp; Result.DocumentID = job.DocumentID; //include any styles from include files via \input cmd string inputfile = ""; try { //find input files using Regex Regex InputsRegex = new Regex(@"(^[^%]*|\n[^\n%]*?)\\input{(?<file>.*)}", RegexOptions.Compiled); MatchCollection files = InputsRegex.Matches(job.code); foreach (Match file in files) { //open, read, parse, and close each included file. inputfile = file.Groups["file"].ToString(); if (File.Exists(inputfile)) { StreamReader sr = new StreamReader(inputfile); string inputcode = sr.ReadToEnd(); sr.Close(); Tikz_ParseTree tp2 = TikzParser.ParseInputFile(inputcode); //if tp2 == null there probably was nothing useful included. if (tp2 != null) { //every style that was found in included file, add it to parse tree of main file. foreach (KeyValuePair<string, Tikz_Option> style in tp2.styles) { if(! Result.ParseTree.styles.ContainsKey(style.Key)) { Result.ParseTree.styles.Add(style.Key, style.Value); } else { ParserException pe = new ParserException(""); TexOutputParser.TexError te = new TexOutputParser.TexError(); te.Message = "Style [" + style.Key + "] is defined multiple times. Check position " + style.Value.StartPosition() + " in " + inputfile + " and this definition."; te.pos = Result.ParseTree.styles[style.Key].StartPosition(); te.severity = Severity.WARNING; pe.e = te; throw pe; } } } } } } catch (Exception ex) { Result.Warning = ex; Result.WarningSource = inputfile; } } catch (Exception ex) { //never set e.Cancel = true; //if you do, you cannot access e.Result from AsyncParser_RunWorkerCompleted. Result.Error = ex; Result.WarningSource = CurFile; } finally { e.Result = Result; } }