all: first stab to full scientific notation support
This commit is contained in:
parent
26239b8eab
commit
8438e17f49
@ -51,6 +51,9 @@ func TestDecode_interface(t *testing.T) {
|
|||||||
"a": 1e-10,
|
"a": 1e-10,
|
||||||
"b": 1e+10,
|
"b": 1e+10,
|
||||||
"c": 1e10,
|
"c": 1e10,
|
||||||
|
"d": 1.2e-10,
|
||||||
|
"e": 1.2e+10,
|
||||||
|
"f": 1.2e10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -60,6 +63,9 @@ func TestDecode_interface(t *testing.T) {
|
|||||||
"a": 1e-10,
|
"a": 1e-10,
|
||||||
"b": 1e+10,
|
"b": 1e+10,
|
||||||
"c": 1e10,
|
"c": 1e10,
|
||||||
|
"d": 1.2e-10,
|
||||||
|
"e": 1.2e+10,
|
||||||
|
"f": 1.2e10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
13
hcl/parse.y
13
hcl/parse.y
@ -193,6 +193,19 @@ number:
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$$ = &Object{
|
||||||
|
Type: ValueTypeFloat,
|
||||||
|
Value: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| int frac exp
|
||||||
|
{
|
||||||
|
fs := fmt.Sprintf("%d.%s%s", $1, $2, $3)
|
||||||
|
f, err := strconv.ParseFloat(fs, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
$$ = &Object{
|
$$ = &Object{
|
||||||
Type: ValueTypeFloat,
|
Type: ValueTypeFloat,
|
||||||
Value: f,
|
Value: f,
|
||||||
|
80
hcl/y.go
80
hcl/y.go
@ -58,7 +58,7 @@ const hclEofCode = 1
|
|||||||
const hclErrCode = 2
|
const hclErrCode = 2
|
||||||
const hclMaxDepth = 200
|
const hclMaxDepth = 200
|
||||||
|
|
||||||
//line parse.y:228
|
//line parse.y:241
|
||||||
|
|
||||||
//line yacctab:1
|
//line yacctab:1
|
||||||
var hclExca = []int{
|
var hclExca = []int{
|
||||||
@ -67,63 +67,65 @@ var hclExca = []int{
|
|||||||
-2, 0,
|
-2, 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
const hclNprod = 30
|
const hclNprod = 31
|
||||||
const hclPrivate = 57344
|
const hclPrivate = 57344
|
||||||
|
|
||||||
var hclTokenNames []string
|
var hclTokenNames []string
|
||||||
var hclStates []string
|
var hclStates []string
|
||||||
|
|
||||||
const hclLast = 56
|
const hclLast = 60
|
||||||
|
|
||||||
var hclAct = []int{
|
var hclAct = []int{
|
||||||
|
|
||||||
32, 3, 19, 41, 8, 27, 28, 29, 15, 22,
|
32, 26, 3, 19, 42, 8, 27, 28, 29, 28,
|
||||||
10, 33, 40, 22, 16, 21, 12, 22, 20, 21,
|
29, 15, 22, 41, 22, 5, 9, 16, 21, 12,
|
||||||
17, 14, 34, 21, 35, 8, 4, 31, 4, 7,
|
21, 20, 11, 22, 40, 35, 8, 37, 34, 21,
|
||||||
13, 7, 36, 7, 24, 12, 2, 4, 22, 9,
|
1, 4, 4, 31, 7, 7, 13, 36, 24, 7,
|
||||||
7, 5, 42, 34, 21, 39, 38, 37, 11, 23,
|
22, 12, 2, 43, 4, 34, 21, 7, 10, 33,
|
||||||
1, 25, 26, 6, 30, 18,
|
39, 38, 25, 6, 30, 23, 18, 0, 17, 14,
|
||||||
}
|
}
|
||||||
var hclPact = []int{
|
var hclPact = []int{
|
||||||
|
|
||||||
30, -1000, 30, -1000, 31, -1000, 23, -1000, -1000, 4,
|
37, -1000, 37, -1000, 8, -1000, 29, -1000, -1000, 7,
|
||||||
-1000, -1000, 21, -1000, -1000, -1000, -1000, -1000, -1000, -11,
|
-1000, -1000, 25, -1000, -1000, -1000, -1000, -1000, -1000, -10,
|
||||||
12, 8, -1000, 19, -1000, -1000, -1000, 42, 41, 40,
|
18, 9, -1000, 24, -1000, -8, -1000, 46, 45, 19,
|
||||||
-3, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
-2, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||||
-1000, 33, -1000,
|
-1000, -1000, 35, -1000,
|
||||||
}
|
}
|
||||||
var hclPgo = []int{
|
var hclPgo = []int{
|
||||||
|
|
||||||
0, 2, 55, 54, 36, 41, 11, 10, 1, 0,
|
0, 3, 56, 54, 42, 15, 49, 48, 2, 0,
|
||||||
53, 52, 51, 50,
|
53, 1, 52, 30,
|
||||||
}
|
}
|
||||||
var hclR1 = []int{
|
var hclR1 = []int{
|
||||||
|
|
||||||
0, 13, 4, 4, 7, 7, 8, 8, 8, 8,
|
0, 13, 4, 4, 7, 7, 8, 8, 8, 8,
|
||||||
8, 8, 5, 5, 10, 10, 2, 2, 3, 3,
|
8, 8, 5, 5, 10, 10, 2, 2, 3, 3,
|
||||||
9, 9, 6, 6, 6, 1, 1, 11, 11, 12,
|
9, 9, 6, 6, 6, 6, 1, 1, 11, 11,
|
||||||
|
12,
|
||||||
}
|
}
|
||||||
var hclR2 = []int{
|
var hclR2 = []int{
|
||||||
|
|
||||||
0, 1, 1, 2, 3, 2, 3, 3, 3, 3,
|
0, 1, 1, 2, 3, 2, 3, 3, 3, 3,
|
||||||
3, 1, 2, 2, 1, 1, 3, 2, 1, 3,
|
3, 1, 2, 2, 1, 1, 3, 2, 1, 3,
|
||||||
1, 1, 1, 2, 2, 2, 1, 2, 2, 2,
|
1, 1, 1, 2, 2, 3, 2, 1, 2, 2,
|
||||||
|
2,
|
||||||
}
|
}
|
||||||
var hclChk = []int{
|
var hclChk = []int{
|
||||||
|
|
||||||
-1000, -13, -4, -8, 7, -5, -10, 10, -8, 8,
|
-1000, -13, -4, -8, 7, -5, -10, 10, -8, 8,
|
||||||
-7, -5, 12, 7, -6, 4, 10, -7, -2, -1,
|
-7, -5, 12, 7, -6, 4, 10, -7, -2, -1,
|
||||||
14, 11, 5, -4, 13, -12, -11, 16, 17, 18,
|
14, 11, 5, -4, 13, -12, -11, 16, 17, 18,
|
||||||
-3, 15, -9, -6, 10, -1, 13, 5, 5, 5,
|
-3, 15, -9, -6, 10, -1, 13, -11, 5, 5,
|
||||||
15, 6, -9,
|
5, 15, 6, -9,
|
||||||
}
|
}
|
||||||
var hclDef = []int{
|
var hclDef = []int{
|
||||||
|
|
||||||
0, -2, 1, 2, 14, 11, 0, 15, 3, 0,
|
0, -2, 1, 2, 14, 11, 0, 15, 3, 0,
|
||||||
12, 13, 0, 14, 6, 7, 8, 9, 10, 22,
|
12, 13, 0, 14, 6, 7, 8, 9, 10, 22,
|
||||||
0, 0, 26, 0, 5, 23, 24, 0, 0, 0,
|
0, 0, 27, 0, 5, 23, 24, 0, 0, 0,
|
||||||
0, 17, 18, 20, 21, 25, 4, 29, 27, 28,
|
0, 17, 18, 20, 21, 26, 4, 25, 30, 28,
|
||||||
16, 0, 19,
|
29, 16, 0, 19,
|
||||||
}
|
}
|
||||||
var hclTok1 = []int{
|
var hclTok1 = []int{
|
||||||
|
|
||||||
@ -535,27 +537,41 @@ hcldefault:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 25:
|
case 25:
|
||||||
//line parse.y:204
|
//line parse.y:202
|
||||||
|
{
|
||||||
|
fs := fmt.Sprintf("%d.%s%s", hclS[hclpt-2].num, hclS[hclpt-1].str, hclS[hclpt-0].str)
|
||||||
|
f, err := strconv.ParseFloat(fs, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
hclVAL.obj = &Object{
|
||||||
|
Type: ValueTypeFloat,
|
||||||
|
Value: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 26:
|
||||||
|
//line parse.y:217
|
||||||
{
|
{
|
||||||
hclVAL.num = hclS[hclpt-0].num * -1
|
hclVAL.num = hclS[hclpt-0].num * -1
|
||||||
}
|
}
|
||||||
case 26:
|
case 27:
|
||||||
//line parse.y:208
|
//line parse.y:221
|
||||||
{
|
{
|
||||||
hclVAL.num = hclS[hclpt-0].num
|
hclVAL.num = hclS[hclpt-0].num
|
||||||
}
|
}
|
||||||
case 27:
|
case 28:
|
||||||
//line parse.y:214
|
//line parse.y:227
|
||||||
{
|
{
|
||||||
hclVAL.str = "e" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
hclVAL.str = "e" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||||
}
|
}
|
||||||
case 28:
|
case 29:
|
||||||
//line parse.y:218
|
//line parse.y:231
|
||||||
{
|
{
|
||||||
hclVAL.str = "e-" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
hclVAL.str = "e-" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||||
}
|
}
|
||||||
case 29:
|
case 30:
|
||||||
//line parse.y:224
|
//line parse.y:237
|
||||||
{
|
{
|
||||||
hclVAL.str = strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
hclVAL.str = strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||||
}
|
}
|
||||||
|
13
json/parse.y
13
json/parse.y
@ -161,6 +161,19 @@ number:
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$$ = &hcl.Object{
|
||||||
|
Type: hcl.ValueTypeFloat,
|
||||||
|
Value: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| int frac exp
|
||||||
|
{
|
||||||
|
fs := fmt.Sprintf("%d.%s%s", $1, $2, $3)
|
||||||
|
f, err := strconv.ParseFloat(fs, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
$$ = &hcl.Object{
|
$$ = &hcl.Object{
|
||||||
Type: hcl.ValueTypeFloat,
|
Type: hcl.ValueTypeFloat,
|
||||||
Value: f,
|
Value: f,
|
||||||
|
69
json/y.go
69
json/y.go
@ -65,7 +65,7 @@ const jsonEofCode = 1
|
|||||||
const jsonErrCode = 2
|
const jsonErrCode = 2
|
||||||
const jsonMaxDepth = 200
|
const jsonMaxDepth = 200
|
||||||
|
|
||||||
//line parse.y:196
|
//line parse.y:209
|
||||||
|
|
||||||
//line yacctab:1
|
//line yacctab:1
|
||||||
var jsonExca = []int{
|
var jsonExca = []int{
|
||||||
@ -74,59 +74,60 @@ var jsonExca = []int{
|
|||||||
-2, 0,
|
-2, 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonNprod = 26
|
const jsonNprod = 27
|
||||||
const jsonPrivate = 57344
|
const jsonPrivate = 57344
|
||||||
|
|
||||||
var jsonTokenNames []string
|
var jsonTokenNames []string
|
||||||
var jsonStates []string
|
var jsonStates []string
|
||||||
|
|
||||||
const jsonLast = 50
|
const jsonLast = 53
|
||||||
|
|
||||||
var jsonAct = []int{
|
var jsonAct = []int{
|
||||||
|
|
||||||
12, 23, 26, 27, 28, 23, 3, 13, 3, 20,
|
12, 23, 25, 26, 27, 28, 23, 13, 3, 20,
|
||||||
21, 29, 17, 18, 19, 22, 7, 23, 5, 22,
|
21, 29, 17, 18, 19, 22, 3, 23, 27, 28,
|
||||||
7, 9, 31, 13, 3, 37, 21, 8, 17, 18,
|
22, 7, 31, 13, 3, 38, 21, 33, 17, 18,
|
||||||
19, 22, 32, 36, 6, 10, 35, 34, 38, 33,
|
19, 22, 32, 37, 9, 7, 6, 5, 10, 39,
|
||||||
15, 2, 1, 24, 11, 25, 4, 30, 16, 14,
|
8, 36, 35, 34, 15, 2, 11, 1, 24, 4,
|
||||||
|
30, 16, 14,
|
||||||
}
|
}
|
||||||
var jsonPact = []int{
|
var jsonPact = []int{
|
||||||
|
|
||||||
-5, -1000, -1000, 6, 15, -1000, -1000, 30, -1000, 10,
|
5, -1000, -1000, 25, 28, -1000, -1000, 33, -1000, 11,
|
||||||
13, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
13, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||||
-17, -3, 1, -1000, -1000, -1000, 35, 33, 32, -1000,
|
-16, -3, 2, -1000, -2, -1000, 39, 38, 37, -1000,
|
||||||
19, -1000, -1000, -1000, -1000, -1000, -1000, 13, -1000,
|
19, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 13, -1000,
|
||||||
}
|
}
|
||||||
var jsonPgo = []int{
|
var jsonPgo = []int{
|
||||||
|
|
||||||
0, 9, 49, 40, 34, 0, 48, 47, 46, 45,
|
0, 9, 52, 44, 36, 0, 51, 50, 49, 2,
|
||||||
43, 42,
|
48, 47,
|
||||||
}
|
}
|
||||||
var jsonR1 = []int{
|
var jsonR1 = []int{
|
||||||
|
|
||||||
0, 11, 3, 3, 8, 8, 4, 5, 5, 5,
|
0, 11, 3, 3, 8, 8, 4, 5, 5, 5,
|
||||||
5, 5, 5, 5, 6, 6, 7, 7, 2, 2,
|
5, 5, 5, 5, 6, 6, 7, 7, 2, 2,
|
||||||
2, 1, 1, 9, 9, 10,
|
2, 2, 1, 1, 9, 9, 10,
|
||||||
}
|
}
|
||||||
var jsonR2 = []int{
|
var jsonR2 = []int{
|
||||||
|
|
||||||
0, 1, 3, 2, 1, 3, 3, 1, 1, 1,
|
0, 1, 3, 2, 1, 3, 3, 1, 1, 1,
|
||||||
1, 1, 1, 1, 2, 3, 1, 3, 1, 2,
|
1, 1, 1, 1, 2, 3, 1, 3, 1, 2,
|
||||||
2, 2, 1, 2, 2, 2,
|
2, 3, 2, 1, 2, 2, 2,
|
||||||
}
|
}
|
||||||
var jsonChk = []int{
|
var jsonChk = []int{
|
||||||
|
|
||||||
-1000, -11, -3, 11, -8, 12, -4, 10, 12, 6,
|
-1000, -11, -3, 11, -8, 12, -4, 10, 12, 6,
|
||||||
5, -4, -5, 10, -2, -3, -6, 15, 16, 17,
|
5, -4, -5, 10, -2, -3, -6, 15, 16, 17,
|
||||||
-1, 13, 18, 4, -10, -9, 19, 20, 21, 14,
|
-1, 13, 18, 4, -10, -9, 19, 20, 21, 14,
|
||||||
-7, -5, -1, 4, 4, 4, 14, 6, -5,
|
-7, -5, -1, -9, 4, 4, 4, 14, 6, -5,
|
||||||
}
|
}
|
||||||
var jsonDef = []int{
|
var jsonDef = []int{
|
||||||
|
|
||||||
0, -2, 1, 0, 0, 3, 4, 0, 2, 0,
|
0, -2, 1, 0, 0, 3, 4, 0, 2, 0,
|
||||||
0, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
0, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||||
18, 0, 0, 22, 19, 20, 0, 0, 0, 14,
|
18, 0, 0, 23, 19, 20, 0, 0, 0, 14,
|
||||||
0, 16, 21, 25, 23, 24, 15, 0, 17,
|
0, 16, 22, 21, 26, 24, 25, 15, 0, 17,
|
||||||
}
|
}
|
||||||
var jsonTok1 = []int{
|
var jsonTok1 = []int{
|
||||||
|
|
||||||
@ -507,27 +508,41 @@ jsondefault:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 21:
|
case 21:
|
||||||
//line parse.y:172
|
//line parse.y:170
|
||||||
|
{
|
||||||
|
fs := fmt.Sprintf("%d.%s%s", jsonS[jsonpt-2].num, jsonS[jsonpt-1].str, jsonS[jsonpt-0].str)
|
||||||
|
f, err := strconv.ParseFloat(fs, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonVAL.obj = &hcl.Object{
|
||||||
|
Type: hcl.ValueTypeFloat,
|
||||||
|
Value: f,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 22:
|
||||||
|
//line parse.y:185
|
||||||
{
|
{
|
||||||
jsonVAL.num = jsonS[jsonpt-0].num * -1
|
jsonVAL.num = jsonS[jsonpt-0].num * -1
|
||||||
}
|
}
|
||||||
case 22:
|
case 23:
|
||||||
//line parse.y:176
|
//line parse.y:189
|
||||||
{
|
{
|
||||||
jsonVAL.num = jsonS[jsonpt-0].num
|
jsonVAL.num = jsonS[jsonpt-0].num
|
||||||
}
|
}
|
||||||
case 23:
|
case 24:
|
||||||
//line parse.y:182
|
//line parse.y:195
|
||||||
{
|
{
|
||||||
jsonVAL.str = "e" + strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
|
jsonVAL.str = "e" + strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
|
||||||
}
|
}
|
||||||
case 24:
|
case 25:
|
||||||
//line parse.y:186
|
//line parse.y:199
|
||||||
{
|
{
|
||||||
jsonVAL.str = "e-" + strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
|
jsonVAL.str = "e-" + strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
|
||||||
}
|
}
|
||||||
case 25:
|
case 26:
|
||||||
//line parse.y:192
|
//line parse.y:205
|
||||||
{
|
{
|
||||||
jsonVAL.str = strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
|
jsonVAL.str = strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
a = 1e-10
|
a = 1e-10
|
||||||
b = 1e+10
|
b = 1e+10
|
||||||
c = 1e10
|
c = 1e10
|
||||||
|
d = 1.2e-10
|
||||||
|
e = 1.2e+10
|
||||||
|
f = 1.2e10
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"a": 1e-10,
|
"a": 1e-10,
|
||||||
"b": 1e+10,
|
"b": 1e+10,
|
||||||
"c": 1e10
|
"c": 1e10,
|
||||||
|
"d": 1.2e-10,
|
||||||
|
"e": 1.2e+10,
|
||||||
|
"f": 1.2e10
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user