mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Simplify unrecognized token byte error message.
This commit is contained in:
1 parent
3072f64368
commit
0cfb27db56
1 file changed
+1
-30
+1
-30
@@ -94,31 +94,6 @@ func hasPrefix(a []byte, s string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func containingLine(src []byte, i int) []byte {
|
|
||||||
j := i
|
|
||||||
for ; j < len(src) && src[j] != '\n'; j++ {
|
|
||||||
}
|
|
||||||
for ; i > 0 && src[i-1] != '\n'; i-- {
|
|
||||||
}
|
|
||||||
return src[i:j]
|
|
||||||
}
|
|
||||||
|
|
||||||
func trim(b []byte) []byte {
|
|
||||||
// Trim the back.
|
|
||||||
i := len(b)
|
|
||||||
for ; i > 0 && b[i-1] <= ' '; i-- {
|
|
||||||
}
|
|
||||||
b = b[:i]
|
|
||||||
|
|
||||||
// Trim the front.
|
|
||||||
i = 0
|
|
||||||
for ; i < len(b) && b[i] <= ' '; i++ {
|
|
||||||
}
|
|
||||||
b = b[i:]
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
func Tokenize(src []byte, m *IDMap, filename string) (tokens []Token, retErr error) {
|
func Tokenize(src []byte, m *IDMap, filename string) (tokens []Token, retErr error) {
|
||||||
line := int32(1)
|
line := int32(1)
|
||||||
loop:
|
loop:
|
||||||
@@ -197,11 +172,7 @@ loop:
|
|||||||
} else {
|
} else {
|
||||||
msg = fmt.Sprintf("non-ASCII byte '\\x%02X'", c)
|
msg = fmt.Sprintf("non-ASCII byte '\\x%02X'", c)
|
||||||
}
|
}
|
||||||
if filename == "" {
|
return nil, fmt.Errorf("token: unrecognized %s at %s:%d", msg, filename, line)
|
||||||
filename = "line"
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("token: unrecognized %s at %s:%d. line contents: %q",
|
|
||||||
msg, filename, line, trim(containingLine(src, i)))
|
|
||||||
}
|
}
|
||||||
return tokens, nil
|
return tokens, nil
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user