10 none = numberFormat(iota)
20 // numberHelper is used to dictate what format a number is in
21 // and what to do for negative values. Since -1e-4 is a valid
22 // number, we cannot just simply check for duplicate negatives.
23 type numberHelper struct {
24 numberFormat numberFormat
30 func (b numberHelper) Exists() bool {
31 return b.numberFormat != none
34 func (b numberHelper) IsNegative() bool {
35 return b.negative || b.negativeExponent
38 func (b *numberHelper) Determine(c rune) error {
40 return NewParseError(fmt.Sprintf("multiple number formats: 0%v", string(c)))
45 b.numberFormat = binary
47 b.numberFormat = octal
51 b.numberFormat = exponent
53 if b.numberFormat != exponent {
56 b.negativeExponent = true
59 b.numberFormat = decimal
61 return NewParseError(fmt.Sprintf("invalid number character: %v", string(c)))
67 func (b numberHelper) CorrectByte(c rune) bool {
69 case b.numberFormat == binary:
73 case b.numberFormat == octal:
77 case b.numberFormat == hex:
81 case b.numberFormat == decimal:
85 case b.numberFormat == exponent:
89 case b.negativeExponent:
106 func (b numberHelper) Base() int {
107 switch b.numberFormat {
119 func (b numberHelper) String() string {
120 buf := bytes.Buffer{}
123 switch b.numberFormat {
126 buf.WriteString(strconv.Itoa(i) + ": binary format\n")
129 buf.WriteString(strconv.Itoa(i) + ": octal format\n")
132 buf.WriteString(strconv.Itoa(i) + ": hex format\n")
135 buf.WriteString(strconv.Itoa(i) + ": exponent format\n")
138 buf.WriteString(strconv.Itoa(i) + ": integer format\n")
143 buf.WriteString(strconv.Itoa(i) + ": negative format\n")
146 if b.negativeExponent {
148 buf.WriteString(strconv.Itoa(i) + ": negative exponent format\n")