go-dirty.git

ref: master

./errors.go


 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package dirty

import (
	"fmt"
)

type SyntaxError struct {
	found    token
	expected []token
}

func NewSyntaxError(found token, expected []token) SyntaxError {
	return SyntaxError{found: found, expected: expected}
}
func (se SyntaxError) Error() string {
	return fmt.Sprintf("expected %v; got %v\n", se.expected, se.found)
}

type UnterminatedError struct {
	ttype string
	t     string
}

func NewUnterminatedError(ttype string, t string) UnterminatedError {
	return UnterminatedError{ttype: ttype, t: t}
}
func (e UnterminatedError) Error() string {
	return fmt.Sprintf("unterminated %s ‘%s’\n", e.ttype, e.t)
}

type InvalidCharError struct {
	r rune
}

func NewInvalidCharError(r rune) InvalidCharError {
	return InvalidCharError{r: r}
}
func (e InvalidCharError) Error() string {
	return fmt.Sprintf("invalid character ‘%d’\n", e.r)
}

type CommaError struct {
	s string
}

func NewCommaError(s string) CommaError {
	return CommaError{s: s}
}
func (e CommaError) Error() string {
	return fmt.Sprintf("comma in wrong place in ‘%s’\n", e.s)
}

type InvalidCodepointError struct {
	c string
}

func NewInvalidCodepointError(c string) InvalidCodepointError {
	return InvalidCodepointError{c: c}
}
func (e InvalidCodepointError) Error() string {
	return fmt.Sprintf("invalid codepoint ‘%s’\n", e.c)
}

type ConstError struct {
	t string
}

func NewConstError(t string) ConstError {
	return ConstError{t: t}
}
func (e ConstError) Error() string {
	return fmt.Sprintf("malformed const ‘%s’\n", e.t)
}

type EscapeError struct {
	char rune
}

func NewEscapeError(char rune) EscapeError {
	return EscapeError{char: char}
}
func (e EscapeError) Error() string {
	return fmt.Sprintf("invalid escape sequence \\%v\n", e.char)
}

type RawStringError struct {
	s string
}

func NewRawStringError(s string) RawStringError {
	return RawStringError{s: s}
}
func (e RawStringError) Error() string {
	return e.s
}