Compare commits
2 Commits
v0.3.8
...
f95859021f
| Author | SHA1 | Date | |
|---|---|---|---|
| f95859021f | |||
| eb2e4ef83c |
+16
-2
@@ -25,17 +25,27 @@ type Error struct {
|
|||||||
Column int
|
Column int
|
||||||
|
|
||||||
Content string
|
Content string
|
||||||
|
Hint string
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err Error) Error() string {
|
func (err Error) Error() string {
|
||||||
var s []string
|
var s []string
|
||||||
|
var prefix string
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case err.Line > 0 || err.Column > 0:
|
case err.Line > 0 || err.Column > 0:
|
||||||
s = append(s, fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column))
|
if err.Filename != "" {
|
||||||
|
prefix = fmt.Sprintf("%s:%v:%v", err.Filename, err.Line, err.Column)
|
||||||
|
} else {
|
||||||
|
prefix = fmt.Sprintf("%v:%v", err.Line, err.Column)
|
||||||
|
}
|
||||||
case err.Filename != "":
|
case err.Filename != "":
|
||||||
s = append(s, err.Filename)
|
prefix = err.Filename
|
||||||
|
}
|
||||||
|
|
||||||
|
if prefix != "" {
|
||||||
|
s = append(s, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err.Err != nil {
|
if err.Err != nil {
|
||||||
@@ -46,6 +56,10 @@ func (err Error) Error() string {
|
|||||||
s = append(s, fmt.Sprintf("%q", err.Content))
|
s = append(s, fmt.Sprintf("%q", err.Content))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err.Hint != "" {
|
||||||
|
s = append(s, err.Hint)
|
||||||
|
}
|
||||||
|
|
||||||
return strings.Join(s, ": ")
|
return strings.Join(s, ": ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,3 +64,29 @@ func (p *Position) StepLine() {
|
|||||||
p.Line++
|
p.Line++
|
||||||
p.Column = 1
|
p.Column = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next returns a new Position one rune forward
|
||||||
|
// on the line
|
||||||
|
func (p Position) Next() Position {
|
||||||
|
if p.Line == 0 {
|
||||||
|
p.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Position{
|
||||||
|
Line: p.Line,
|
||||||
|
Column: p.Column + 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NextLine returns a new Position at the begining of the next
|
||||||
|
// line.
|
||||||
|
func (p Position) NextLine() Position {
|
||||||
|
if p.Line == 0 {
|
||||||
|
p.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
return Position{
|
||||||
|
Line: p.Line + 1,
|
||||||
|
Column: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user