blob: bdcd9df3f619049212a972ecaa7bed0457e48e5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package mardown
import "fmt"
type ParseError struct {
internal error
lxs lexers
}
func (e *ParseError) Error() string {
return e.internal.Error()
}
func (e *ParseError) Pretty() string {
lxs := e.lxs
if lxs.lexers == nil {
return e.internal.Error()
}
current := lxs.current - 1
for lxs.Before() && lxs.Current().Type != lexerBreak {
}
current -= lxs.current
contxt := ""
ind := ""
for lxs.Next() && lxs.Current().Type != lexerBreak {
contxt += lxs.Current().Value
ln := len(lxs.Current().Value)
if lxs.current == current-1 {
ln--
ind += "^"
}
for range ln {
ind += "~"
}
}
return fmt.Sprintf("%v\n\n%s\n%s", e, contxt, ind)
}
|