// scanNumber consumes the current number rune and all contiguous number runes.
// Numbers can be floating point, i.e. contain a single dot.
// Other formats, especially a leading + or - sign are not considered here.
scanNumber consumes the current number rune and all contiguous number runes.
Numbers can be floating point, i.e. contain a single dot.
Other formats, especially a leading + or - sign are not considered here.
// scanNumber consumes the current number rune and all contiguous number runes . // Numbers can be floating point i . e . contain a single dot . // Other formats especially a leading + or - sign are not considered here .
func (s *Scanner) scanNumber() (tok Token, lit string) {
	var buf bytes.Buffer
	for {
		if ch := s.read(); !unicode.IsDigit(ch) && ch != '.' {
			s.unread()
			break
		} else {
			_, _ = buf.WriteRune(ch)
		}
	}
	bs := buf.String()
	var err error
	if _, err = strconv.Atoi(bs); err == nil {
		return INTLIT, bs
	}
	if _, err = strconv.ParseFloat(bs, 64); err == nil {
		return FLOATLIT, bs
	}
	return ILLEGAL, bs
}
func ( s * Scanner ) scanNumber ( ) ( tok Token , lit string ) { var buf bytes . Buffer for { if ch := s . read ( ) ; ! unicode . IsDigit ( ch ) && ch != '.' { s . unread ( ) break } else { _ , _ = buf . WriteRune ( ch ) } } bs := buf . String ( ) var err error if _ , err = strconv . Atoi ( bs ) ; err == nil { return INTLIT , bs } if _ , err = strconv . ParseFloat ( bs , 64 ) ; err == nil { return FLOATLIT , bs } return ILLEGAL , bs }
scanNumber consumes the current number rune and all contiguous number runes.
scanNumber consumes the current number rune and all contiguous number runes .
// Create a buffer and read the current character into it. // Read every subsequent ident character into the buffer. // Non-number chars cause exit. // no need to stop with a second dot. There is no regular way for . to directly follow a number, i.e. // a second dot surely is an error. // If the string matches a number then return the right number type // There could still be an unparseable number with multiple dots in the buffer. // Otherwise give up: