Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f816300f6 | |||
| 5f81eb0ea5 | |||
| ce75299e74 | |||
| 1d7ee69ab7 | |||
| ec0fc8e508 |
+21
-5
@@ -25,17 +25,29 @@ type Error struct {
|
||||
Column int
|
||||
|
||||
Content string
|
||||
Hint string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (err Error) prefix() string {
|
||||
switch {
|
||||
case err.Line > 0 || err.Column > 0:
|
||||
if err.Filename != "" {
|
||||
return fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v:%v", err.Line, err.Column)
|
||||
default:
|
||||
return err.Filename
|
||||
}
|
||||
}
|
||||
|
||||
func (err Error) Error() string {
|
||||
var s []string
|
||||
|
||||
switch {
|
||||
case err.Line > 0 || err.Column > 0:
|
||||
s = append(s, fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column))
|
||||
case err.Filename != "":
|
||||
s = append(s, err.Filename)
|
||||
prefix := err.prefix()
|
||||
if prefix != "" {
|
||||
s = append(s, prefix)
|
||||
}
|
||||
|
||||
if err.Err != nil {
|
||||
@@ -46,6 +58,10 @@ func (err Error) Error() string {
|
||||
s = append(s, fmt.Sprintf("%q", err.Content))
|
||||
}
|
||||
|
||||
if err.Hint != "" {
|
||||
s = append(s, err.Hint)
|
||||
}
|
||||
|
||||
return strings.Join(s, ": ")
|
||||
}
|
||||
|
||||
|
||||
@@ -64,3 +64,23 @@ func (p *Position) StepLine() {
|
||||
p.Line++
|
||||
p.Column = 1
|
||||
}
|
||||
|
||||
// Add adds a relative position considering
|
||||
// potential new lines
|
||||
func (p *Position) Add(rel Position) {
|
||||
if p.Line == 0 {
|
||||
p.Reset()
|
||||
}
|
||||
|
||||
switch {
|
||||
case rel.Line == 0:
|
||||
// nothing
|
||||
case rel.Line > 1:
|
||||
// includes new lines
|
||||
p.Line += rel.Line - 1
|
||||
p.Column = rel.Column
|
||||
default:
|
||||
// same line
|
||||
p.Column += rel.Column - 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user