()
| 685 | } |
| 686 | |
| 687 | func (n *NumberNode) load() error { |
| 688 | // Do integer test first so we get 0x123 etc. |
| 689 | iv, err := strconv.ParseInt(n.Text, 0, 64) // will fail for -0. |
| 690 | if err == nil { |
| 691 | n.IsInt = true |
| 692 | n.Int64 = iv |
| 693 | } |
| 694 | // If an integer extraction succeeded, promote the float. |
| 695 | if n.IsInt { |
| 696 | n.IsFloat = true |
| 697 | n.Float64 = float64(n.Int64) |
| 698 | } else { |
| 699 | f, err := strconv.ParseFloat(n.Text, 64) |
| 700 | if err == nil { |
| 701 | n.IsFloat = true |
| 702 | n.Float64 = f |
| 703 | // If a floating-point extraction succeeded, extract the int if needed. |
| 704 | if !n.IsInt && float64(int64(f)) == f { |
| 705 | n.IsInt = true |
| 706 | n.Int64 = int64(f) |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | if !n.IsInt && !n.IsFloat { |
| 711 | return fmt.Errorf("illegal number syntax: %q", n.Text) |
| 712 | } |
| 713 | return nil |
| 714 | } |
| 715 | func (m *NumberNode) NodeType() string { return "Number" } |
| 716 | func (n *NumberNode) String() string { return n.Text } |
| 717 | func (m *NumberNode) WriteDialect(w DialectWriter) { w.WriteNumber(m.Text) } |
no test coverage detected