static string pretty_string(string msg, LocationBase e) { StringBuilder sb = new StringBuilder(); sb.Append(msg); if (e != null) { FileInfo fi; if (e.fname == null || ((fi = new FileInfo(e.fname)).Exists == false)) { sb.Append(Environment.NewLine + " at line " + e.sline + ", column " + e.scol); } else { var f = new StreamReader(fi.OpenRead()); int cline = 0; string cl = null; while (cline < e.sline) { cline++; cl = f.ReadLine(); } cl = cl.Insert(e.ecol, "^").Insert(e.scol, "^"); f.Close(); sb.Append(Environment.NewLine + " at line " + e.sline + ", column " + e.scol + " in " + fi.FullName + ":"); sb.Append(Environment.NewLine + " " + cl); } } return(sb.ToString()); }
public SyntaxException(string msg, LocationBase e) : base(pretty_string(msg, e)) { expr = e; }