separate number into float and integer
This commit is contained in:
parent
10f55313b0
commit
daab50d54c
22 changed files with 848 additions and 428 deletions
|
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -21,7 +22,8 @@ type Boundary interface {
|
|||
|
||||
const (
|
||||
StringNodeType NodeType = iota
|
||||
NumberNodeType
|
||||
FloatNodeType
|
||||
IntegerNodeType
|
||||
ReferenceNodeType
|
||||
BooleanNodeType
|
||||
NilNodeType
|
||||
|
|
@ -43,8 +45,10 @@ func (n NodeType) String() string {
|
|||
switch n {
|
||||
case StringNodeType:
|
||||
return "String"
|
||||
case NumberNodeType:
|
||||
return "Number"
|
||||
case FloatNodeType:
|
||||
return "Float"
|
||||
case IntegerNodeType:
|
||||
return "Integer"
|
||||
case ReferenceNodeType:
|
||||
return "Reference"
|
||||
case BinaryNodeType:
|
||||
|
|
@ -120,22 +124,41 @@ func (n StringNode) Bounds() (Pos, Pos) {
|
|||
return n.start, n.end
|
||||
}
|
||||
|
||||
type NumberNode struct {
|
||||
type FloatNode struct {
|
||||
value float64
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n NumberNode) Type() NodeType {
|
||||
return NumberNodeType
|
||||
func (n FloatNode) Type() NodeType {
|
||||
return FloatNodeType
|
||||
}
|
||||
|
||||
func (n NumberNode) String() string {
|
||||
return strconv.FormatFloat(n.value, 'g', -1, NumberSize)
|
||||
func (n FloatNode) String() string {
|
||||
return strconv.FormatFloat(n.value, 'g', -1, FloatSize)
|
||||
}
|
||||
|
||||
func (n NumberNode) Bounds() (Pos, Pos) {
|
||||
func (n FloatNode) Bounds() (Pos, Pos) {
|
||||
return n.start, n.end
|
||||
}
|
||||
|
||||
type IntegerNode struct {
|
||||
value *big.Int
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n IntegerNode) Type() NodeType {
|
||||
return IntegerNodeType
|
||||
}
|
||||
|
||||
func (n IntegerNode) String() string {
|
||||
return n.value.String()
|
||||
}
|
||||
|
||||
func (n IntegerNode) Bounds() (Pos, Pos) {
|
||||
return n.start, n.end
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue