public virtual IErrorNode AddErrorNode(IToken badToken) { ErrorNodeImpl t = new ErrorNodeImpl(badToken); AddChild(t); t.parent = this; return(t); }
public IEnumerable <Workspaces.Range> GetErrors(Workspaces.Range range, Document doc) { ParsingResults pd = ParsingResultsFactory.Create(doc); var workspace = doc.Workspace; if (pd.ParseTree == null) { Compile(workspace); } List <Range> result = new List <Workspaces.Range>(); foreach (IParseTree p in pd.Errors) { ErrorNodeImpl q = p as Antlr4.Runtime.Tree.ErrorNodeImpl; if (q == null) { continue; } if (q.Payload == null) { continue; } int y = q.Payload.StartIndex; int z = q.Payload.StopIndex; if (y < 0) { y = 0; } if (z < 0) { z = 0; } int a = y; int b = z + 1; int start_token_start = a; int end_token_end = b; if (start_token_start > range.End.Value) { continue; } if (end_token_end < range.Start.Value) { continue; } Range r = new Workspaces.Range(new Workspaces.Index(a), new Workspaces.Index(b)); result.Add(r); } return(result); }
private bool CheckForErrorToken(string plain_ole_command, calculatorParser parser, IParseTree tree, IParseTree[] all_nodes) { IEnumerable <IParseTree> eni_nodes_iterator = all_nodes.Where((IParseTree n) => { ErrorNodeImpl nn = n as ErrorNodeImpl; return(nn != null); }); IParseTree[] all_eni_nodes_iterator = eni_nodes_iterator.ToArray(); if (!all_eni_nodes_iterator.Any()) { return(false); } // For now, report nothing if there isn't an equal. foreach (var en in all_eni_nodes_iterator) { ErrorNodeImpl eni = en as ErrorNodeImpl; if (eni != null) { if (eni.GetText() == "<missing '='>") { return(false); } } } var enn = all_eni_nodes_iterator.First() as ErrorNodeImpl; if (enn == null) { return(false); } int ErrorPos = enn.Payload.StartIndex; if (ErrorPos < 0) { ErrorPos = 0; } string result = "Extraneous input."; Results[Results.Count - 1].result.Text = BuildFormattedCommandAndResult(plain_ole_command, ErrorPos, result); NotifyPropertyChanged("Results"); return(true); }
/// <summary> /// Selects the source source text corresponding to the provided error node. /// </summary> /// <param name="codeEditor">The code editor.</param> /// <param name="node">The error node.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="codeEditor"/> is <see langword="null"/></exception> public static void SelectSource([NotNull] this FastColoredTextBox codeEditor, ErrorNodeImpl node) { if (codeEditor is null) { throw new ArgumentNullException(nameof(codeEditor)); } if (node == null) { return; } var startingPlace = new Place(node.Symbol.Column, node.Symbol.Line - 1); Place stoppingPlace; if (node.Symbol.StartIndex != -1) { var spot = node.Symbol.GetEndPlace(); stoppingPlace = new Place(spot.Position + 1, spot.Line - 1); } else { stoppingPlace = startingPlace; } codeEditor.Selection = new Range(codeEditor, startingPlace, stoppingPlace); codeEditor.DoCaretVisible(); }