public static void Display(this IInteractivity interactivity, ParseError error, String source) { var start = error.Start.Index - 1; var end = error.End.Index - 1; var lines = source.Split(new[] { Environment.NewLine }, StringSplitOptions.None); source = String.Join(" ", lines).Replace('\t', ' '); if (end == start) { end++; } var range = 48; var middle = (end + start) / 2; var ss = Math.Min(source.Length, Math.Max(middle - range / 2, 0)); var se = Math.Min(Math.Max(0, middle + range / 2), source.Length); var snippet = source.Substring(ss, se - ss); interactivity.Error(snippet); interactivity.Error(Environment.NewLine); interactivity.Error(new String(' ', Math.Max(0, start - ss))); interactivity.Error(new String('^', Math.Max(0, end - start))); interactivity.Error(Environment.NewLine); interactivity.Display(error); }
public void Run(String file) { var import = _engine.Globals["import"] as Function; try { import.Invoke(new[] { file }); } catch (ParseException ex) { var content = File.ReadAllText(file); _interactivity.Display(ex.Error, content); } catch (Exception ex) { _interactivity.Error(ex.Message); } }