private static ParseTree Parse(string input, bool allowPartial) { ParseTree parseTree = null; IronyParser.Context.Mode = allowPartial ? ParseMode.CommandLine : ParseMode.File; try { parseTree = IronyParser.Parse(input); } catch (Exception) { var msg = "The parser internally crashed and gets reinitialized." + Environment.NewLine + "Although this shouldn't happen, it's likely that it happened because of invalid syntax."; IronyParser = new IronyParser(Grammar); throw new ParseException(msg); } if (parseTree.HasErrors()) // ParseTreeStatus is Error { var logMessage = parseTree.ParserMessages.First(); throw new ParseException(logMessage.Message, logMessage.Location.Line, logMessage.Location.Column, parseTree.SourceText); } return(parseTree); }
private void ReParse(ITextSnapshot newSnapshot, Irony.Parsing.ParseTree tree) { int previousCount = errorTokens.Count; errorTokens.Clear(); var newErrors = new List <Irony.Parsing.Token>(); foreach (var token in tree.Tokens) { if (token.IsError()) { errorTokens.Add(token); } } if (tree.HasErrors()) { var tok = tree.Tokens.Last(); errorTokens.Add(tok); //if (tok.Length != 0) // errorTokens.Add(tok); //else //it is EOF error so before the end(use -2) // errorTokens.Add(tree.Tokens[tree.Tokens.Count - 2]); msgParse = tree.ParserMessages[0].ToString(); } else { msgParse = ""; } if (previousCount != 0 || errorTokens.Count != 0) { if (this.TagsChanged != null) { this.TagsChanged(this, new SnapshotSpanEventArgs( new SnapshotSpan(newSnapshot, 0, newSnapshot.Length))); } } }