Example #1
0
// distance returns the column difference between from and to if both
// are on the same line; if they are on different lines (or unknown)
// the result is infinity.
func (p *printer) distance(from0 token.Pos, to token.Position) int {
	from := p.fset.Position(from0)
	if from.IsValid() && to.IsValid() && from.Line == to.Line {
		return to.Column - from.Column
	}
	return infinity
}
Example #2
0
/*
Formats an error message nicely, giving the relish source file location of the error if possible.
*/
func FmtErr(pos token.Position, message string) string {
	if pos.Filename != "" || pos.IsValid() {
		// don't print "<unknown position>"
		// TODO(gri) reconsider the semantics of Position.IsValid

		fileNamePosString := pos.String()
		srcPos := strings.LastIndex(fileNamePosString, "/src/")
		artifactDir := fileNamePosString[:srcPos+5]
		packageFilePos := fileNamePosString[srcPos+5:]

		return "\n" + packageFilePos + ":\n\n" + message + "\n\nError in software artifact\n" + artifactDir + "\n"
	}
	return message
}