MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / scanNumberImpl

Method scanNumberImpl

pkg/sql/scanner/scan.go:703–806  ·  view source on GitHub ↗
(lval ScanSymType, ch int, errorID, fconstID, iconstID int32)

Source from the content-addressed store, hash-verified

701}
702
703func (s *Scanner) scanNumberImpl(lval ScanSymType, ch int, errorID, fconstID, iconstID int32) {
704 start := s.pos - 1
705 isHex := false
706 hasDecimal := ch == '.'
707 hasExponent := false
708
709 for {
710 ch := s.peek()
711 if (isHex && lexbase.IsHexDigit(ch)) || lexbase.IsDigit(ch) {
712 s.pos++
713 continue
714 }
715 if ch == 'x' || ch == 'X' {
716 if isHex || s.in[start] != '0' || s.pos != start+1 {
717 lval.SetID(errorID)
718 lval.SetStr(errInvalidHexNumeric)
719 return
720 }
721 s.pos++
722 isHex = true
723 continue
724 }
725 if isHex {
726 break
727 }
728 if ch == '.' {
729 if hasDecimal || hasExponent {
730 break
731 }
732 s.pos++
733 if s.peek() == '.' {
734 // Found ".." while scanning a number: back up to the end of the
735 // integer.
736 s.pos--
737 break
738 }
739 hasDecimal = true
740 continue
741 }
742 if ch == 'e' || ch == 'E' {
743 if hasExponent {
744 break
745 }
746 hasExponent = true
747 s.pos++
748 ch = s.peek()
749 if ch == '-' || ch == '+' {
750 s.pos++
751 ch = s.peek()
752 }
753 if !lexbase.IsDigit(ch) {
754 lval.SetID(errorID)
755 lval.SetStr("invalid floating point literal")
756 return
757 }
758 continue
759 }
760 break

Callers 3

scanNumberMethod · 0.95
scanNumberMethod · 0.80
scanNumberMethod · 0.80

Calls 9

peekMethod · 0.95
IsHexDigitFunction · 0.92
IsDigitFunction · 0.92
IsIdentStartFunction · 0.92
KindMethod · 0.80
SetIDMethod · 0.65
SetStrMethod · 0.65
StrMethod · 0.65
SetUnionValMethod · 0.65

Tested by

no test coverage detected