public SyntaxError(Source source, int position, String description) { Source = source; Position = position; Description = description; Location = new SourceLocation(source, position); }
/// <summary> /// Highlights the source at location. /// </summary> /// <param name="source">The source.</param> /// <param name="location">The location.</param> /// <returns></returns> public static String HighlightSourceAtLocation(Source source, SourceLocation location) { var line = location.Line; var prevLineNum = (line - 1).ToString(); var lineNum = line.ToString(); var nextLineNum = (line + 1).ToString(); var padLen = nextLineNum.Length; var lines = SourceLocation.LineRegexp.Split(source.Body); var res = (line >= 2 ? prevLineNum.PadLeft(padLen) + ": " + lines[line - 2] + "\n" : "") + lineNum.PadLeft(padLen) + ": " + lines[line - 1] + "\n" + "".PadLeft(2 + padLen + location.Column - 1) + "^\n" + (line < lines.Length ? nextLineNum.PadLeft(padLen) + ": " + lines[line] + "\n" : ""); return res; }