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 static void Display(this IInteractivity interactivity, ParseError error) { var message = error.Code.GetMessage(); var hint = String.Format("Line {1}, Column {2}: {0}", message, error.Start.Row, error.Start.Column); interactivity.Error(hint); }
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); } }
public String GetContent(String fileName) { var content = String.Empty; if (!File.Exists(fileName)) { _interactivity.Error(String.Format("The file {0} does not exist.", fileName)); Environment.Exit(1); } try { content = File.ReadAllText(fileName); } catch { _interactivity.Error(String.Format("Error while reading the file {0}.", fileName)); Environment.Exit(1); } return(content); }
private void Evaluate(String content, Boolean showOutput) { try { var result = _engine.Interpret(content); if (showOutput) { _interactivity.Info(result); _engine.Scope["ans"] = result; } } catch (ParseException ex) { Display(ex.Error, content); } catch (Exception ex) { _interactivity.Error(ex.Message); } _interactivity.Write(Environment.NewLine); }