-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
112 lines (85 loc) · 3.18 KB
/
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package goabnf
import (
"errors"
"fmt"
)
var (
// ErrNoSolutionFound is an error returned when parsing an ABNF
// grammar and no solution has been found.
ErrNoSolutionFound = errors.New("no solution found, input ABNF grammar may be invalid")
// ErrHandlingProseVal is an error returned when an operation tried
// to produce something on a prose-val, but it can't be handled properly.
ErrHandlingProseVal = errors.New("can't handle prose-val descriptions")
)
// ErrMultipleSolutionsFound is an error returned when a parser found
// multiple paths/solutions when none or one were expected.
type ErrMultipleSolutionsFound struct {
Paths []*Path
}
var _ error = (*ErrMultipleSolutionsFound)(nil)
func (err ErrMultipleSolutionsFound) Error() string {
return "multiple solutions found, this should not happen. Please open an issue. This could eventually need an Erratum from IETF tracking"
}
// ErrRuleNotFound is an error returned when the rule was not found
// as part of the grammar.
type ErrRuleNotFound struct {
Rulename string
}
var _ error = (*ErrRuleNotFound)(nil)
func (err ErrRuleNotFound) Error() string {
return fmt.Sprintf("rule %s was not found in grammar", err.Rulename)
}
// ErrCoreRuleModify is an error returned when an incremental alternative
// for a core rule.
type ErrCoreRuleModify struct {
CoreRulename string
}
var _ error = (*ErrCoreRuleModify)(nil)
func (err ErrCoreRuleModify) Error() string {
return fmt.Sprintf("core rule %s can't be modified", err.CoreRulename)
}
// ErrDependencyNotFound is an error returned during ABNF grammar
// semantic vaildation, if a rule depends on an unexisting rule.
type ErrDependencyNotFound struct {
Rulename string
}
var _ error = (*ErrDependencyNotFound)(nil)
func (err ErrDependencyNotFound) Error() string {
return fmt.Sprintf("unsatisfied dependency (rule) %s", err.Rulename)
}
// ErrSemanticRepetition is an error returned during ABNF grammar
// semantic validation, if a repetition has min < max.
type ErrSemanticRepetition struct {
Repetition Repetition
}
var _ error = (*ErrSemanticRepetition)(nil)
func (err ErrSemanticRepetition) Error() string {
return fmt.Sprintf("invalid semantic of input ABNF grammar for repetition %s", err.Repetition)
}
// ErrTooLargeNumeral is an error returned when the numeral value
// provided to parse cannot be handled as a 7-bit US-ASCII valid value.
type ErrTooLargeNumeral struct {
Base, Value string
}
var _ error = (*ErrTooLargeNumeral)(nil)
func (err ErrTooLargeNumeral) Error() string {
return fmt.Sprintf("too large numeral value %s for base %s", err.Value, err.Base)
}
// ErrDuplicatedRule is an error returned when the rule already
// exist as part of the grammar.
type ErrDuplicatedRule struct {
Rulename string
}
var _ error = (*ErrDuplicatedRule)(nil)
func (err ErrDuplicatedRule) Error() string {
return fmt.Sprintf("rule %s was already defined in grammar", err.Rulename)
}
// ErrCyclicRule is an error returned when can't work due to an
// unavoidable cyclic rule.
type ErrCyclicRule struct {
Rulename string
}
var _ error = (*ErrCyclicRule)(nil)
func (err ErrCyclicRule) Error() string {
return fmt.Sprintf("can't generate a content as the rule %s involves an unavoidable cycle", err.Rulename)
}