()
| 233 | } |
| 234 | |
| 235 | func (s *scanner) readNumber() token { |
| 236 | const bits64, base10 = 64, 10 |
| 237 | c := s.current |
| 238 | s.assert(isDecimal(c)) |
| 239 | s.saveAndAdvance() |
| 240 | if c == '0' && s.checkNext("Xx") { // hexadecimal |
| 241 | prefix := s.buffer.String() |
| 242 | s.assert(prefix == "0x" || prefix == "0X") |
| 243 | s.buffer.Reset() |
| 244 | var exponent int |
| 245 | fraction, c, i := s.readHexNumber(0) |
| 246 | if c == '.' { |
| 247 | s.advance() |
| 248 | fraction, c, exponent = s.readHexNumber(fraction) |
| 249 | } |
| 250 | if i == 0 && exponent == 0 { |
| 251 | s.numberError() |
| 252 | } |
| 253 | exponent *= -4 |
| 254 | if c == 'p' || c == 'P' { |
| 255 | s.advance() |
| 256 | var negativeExponent bool |
| 257 | if c = s.current; c == '+' || c == '-' { |
| 258 | negativeExponent = c == '-' |
| 259 | s.advance() |
| 260 | } |
| 261 | if !isDecimal(s.current) { |
| 262 | s.numberError() |
| 263 | } |
| 264 | _ = s.readDigits() |
| 265 | if e, err := strconv.ParseInt(s.buffer.String(), base10, bits64); err != nil { |
| 266 | s.numberError() |
| 267 | } else if negativeExponent { |
| 268 | exponent += int(-e) |
| 269 | } else { |
| 270 | exponent += int(e) |
| 271 | } |
| 272 | s.buffer.Reset() |
| 273 | } |
| 274 | return token{t: tkNumber, n: math.Ldexp(fraction, exponent)} |
| 275 | } |
| 276 | c = s.readDigits() |
| 277 | if c == '.' { |
| 278 | s.saveAndAdvance() |
| 279 | c = s.readDigits() |
| 280 | } |
| 281 | if c == 'e' || c == 'E' { |
| 282 | s.saveAndAdvance() |
| 283 | if c = s.current; c == '+' || c == '-' { |
| 284 | s.saveAndAdvance() |
| 285 | } |
| 286 | _ = s.readDigits() |
| 287 | } |
| 288 | str := s.buffer.String() |
| 289 | if strings.HasPrefix(str, "0") { |
| 290 | if str = strings.TrimLeft(str, "0"); str == "" || !isDecimal(rune(str[0])) { |
| 291 | str = "0" + str |
| 292 | } |
no test coverage detected