hcl: complex keys can be set using strings
This commit is contained in:
parent
96d5b40433
commit
ab2c4c3120
@ -45,6 +45,8 @@ func TestLex(t *testing.T) {
|
||||
[]int{
|
||||
IDENTIFIER, LEFTBRACE,
|
||||
IDENTIFIER, EQUAL, NUMBER,
|
||||
STRING, EQUAL, NUMBER,
|
||||
STRING, EQUAL, NUMBER,
|
||||
RIGHTBRACE, lexEOF,
|
||||
},
|
||||
},
|
||||
|
22
hcl/parse.y
22
hcl/parse.y
@ -22,7 +22,7 @@ import (
|
||||
%type <objlist> list listitems objectlist
|
||||
%type <obj> block number object objectitem
|
||||
%type <obj> listitem
|
||||
%type <str> blockId exp frac
|
||||
%type <str> blockId exp objectkey frac
|
||||
|
||||
%token <b> BOOL
|
||||
%token <num> NUMBER
|
||||
@ -69,13 +69,23 @@ object:
|
||||
}
|
||||
}
|
||||
|
||||
objectkey:
|
||||
IDENTIFIER
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
| STRING
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
objectitem:
|
||||
IDENTIFIER EQUAL number
|
||||
objectkey EQUAL number
|
||||
{
|
||||
$$ = $3
|
||||
$$.Key = $1
|
||||
}
|
||||
| IDENTIFIER EQUAL BOOL
|
||||
| objectkey EQUAL BOOL
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
@ -83,7 +93,7 @@ objectitem:
|
||||
Value: $3,
|
||||
}
|
||||
}
|
||||
| IDENTIFIER EQUAL STRING
|
||||
| objectkey EQUAL STRING
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
@ -91,12 +101,12 @@ objectitem:
|
||||
Value: $3,
|
||||
}
|
||||
}
|
||||
| IDENTIFIER EQUAL object
|
||||
| objectkey EQUAL object
|
||||
{
|
||||
$3.Key = $1
|
||||
$$ = $3
|
||||
}
|
||||
| IDENTIFIER EQUAL list
|
||||
| objectkey EQUAL list
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
|
@ -1,3 +1,5 @@
|
||||
foo {
|
||||
value = 7
|
||||
"value" = 8
|
||||
"complex::value" = 9
|
||||
}
|
||||
|
188
hcl/y.go
188
hcl/y.go
@ -60,75 +60,81 @@ const hclEofCode = 1
|
||||
const hclErrCode = 2
|
||||
const hclMaxDepth = 200
|
||||
|
||||
//line parse.y:248
|
||||
//line parse.y:258
|
||||
|
||||
//line yacctab:1
|
||||
var hclExca = []int{
|
||||
-1, 1,
|
||||
1, -1,
|
||||
-2, 0,
|
||||
-1, 6,
|
||||
9, 7,
|
||||
-2, 17,
|
||||
-1, 7,
|
||||
9, 8,
|
||||
-2, 18,
|
||||
}
|
||||
|
||||
const hclNprod = 33
|
||||
const hclNprod = 35
|
||||
const hclPrivate = 57344
|
||||
|
||||
var hclTokenNames []string
|
||||
var hclStates []string
|
||||
|
||||
const hclLast = 61
|
||||
const hclLast = 63
|
||||
|
||||
var hclAct = []int{
|
||||
|
||||
32, 26, 3, 19, 9, 8, 27, 28, 29, 28,
|
||||
29, 15, 22, 4, 22, 40, 7, 22, 16, 21,
|
||||
12, 21, 20, 34, 21, 35, 8, 37, 31, 42,
|
||||
43, 1, 4, 39, 4, 7, 38, 7, 36, 41,
|
||||
24, 13, 22, 44, 7, 2, 12, 10, 34, 21,
|
||||
33, 25, 5, 6, 30, 18, 0, 17, 23, 11,
|
||||
14,
|
||||
34, 28, 3, 21, 10, 9, 29, 30, 31, 30,
|
||||
31, 17, 24, 42, 6, 44, 45, 7, 18, 23,
|
||||
13, 41, 22, 40, 24, 43, 1, 37, 9, 39,
|
||||
36, 23, 2, 6, 6, 33, 7, 7, 14, 38,
|
||||
26, 15, 24, 13, 24, 46, 25, 11, 36, 23,
|
||||
35, 23, 27, 5, 4, 8, 32, 20, 19, 0,
|
||||
0, 16, 12,
|
||||
}
|
||||
var hclPact = []int{
|
||||
|
||||
5, -1000, 5, -1000, -5, -1000, 33, -1000, -1000, 7,
|
||||
-1000, -1000, 26, -1000, -1000, -1000, -1000, -1000, -1000, -11,
|
||||
12, 9, -1000, 24, -1000, -9, -1000, 31, 28, 10,
|
||||
23, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||
-1000, -1000, 37, -1000, -1000,
|
||||
6, -1000, 6, -1000, -5, -1000, -1000, -1000, 30, -1000,
|
||||
7, -1000, -1000, 26, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||
-1000, -11, 19, 39, -1000, 25, -1000, -9, -1000, 18,
|
||||
16, 8, 9, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||
-1000, -1000, -1000, -1000, 37, -1000, -1000,
|
||||
}
|
||||
var hclPgo = []int{
|
||||
|
||||
0, 3, 55, 54, 45, 52, 50, 47, 2, 0,
|
||||
53, 1, 51, 31,
|
||||
0, 3, 57, 56, 32, 53, 50, 47, 2, 0,
|
||||
55, 1, 54, 52, 26,
|
||||
}
|
||||
var hclR1 = []int{
|
||||
|
||||
0, 13, 13, 4, 4, 7, 7, 8, 8, 8,
|
||||
8, 8, 8, 5, 5, 10, 10, 2, 2, 3,
|
||||
3, 3, 9, 9, 6, 6, 6, 6, 1, 1,
|
||||
11, 11, 12,
|
||||
0, 14, 14, 4, 4, 7, 7, 12, 12, 8,
|
||||
8, 8, 8, 8, 8, 5, 5, 10, 10, 2,
|
||||
2, 3, 3, 3, 9, 9, 6, 6, 6, 6,
|
||||
1, 1, 11, 11, 13,
|
||||
}
|
||||
var hclR2 = []int{
|
||||
|
||||
0, 0, 1, 1, 2, 3, 2, 3, 3, 3,
|
||||
3, 3, 1, 2, 2, 1, 1, 3, 2, 1,
|
||||
3, 2, 1, 1, 1, 2, 2, 3, 2, 1,
|
||||
2, 2, 2,
|
||||
0, 0, 1, 1, 2, 3, 2, 1, 1, 3,
|
||||
3, 3, 3, 3, 1, 2, 2, 1, 1, 3,
|
||||
2, 1, 3, 2, 1, 1, 1, 2, 2, 3,
|
||||
2, 1, 2, 2, 2,
|
||||
}
|
||||
var hclChk = []int{
|
||||
|
||||
-1000, -13, -4, -8, 8, -5, -10, 11, -8, 9,
|
||||
-7, -5, 13, 8, -6, 4, 11, -7, -2, -1,
|
||||
15, 12, 5, -4, 14, -12, -11, 17, 18, 19,
|
||||
-3, 16, -9, -6, 11, -1, 14, -11, 5, 5,
|
||||
5, 16, 6, 7, -9,
|
||||
-1000, -14, -4, -8, -12, -5, 8, 11, -10, -8,
|
||||
9, -7, -5, 13, 8, 11, -6, 4, 11, -7,
|
||||
-2, -1, 15, 12, 5, -4, 14, -13, -11, 17,
|
||||
18, 19, -3, 16, -9, -6, 11, -1, 14, -11,
|
||||
5, 5, 5, 16, 6, 7, -9,
|
||||
}
|
||||
var hclDef = []int{
|
||||
|
||||
1, -2, 2, 3, 15, 12, 0, 16, 4, 0,
|
||||
13, 14, 0, 15, 7, 8, 9, 10, 11, 24,
|
||||
0, 0, 29, 0, 6, 25, 26, 0, 0, 0,
|
||||
0, 18, 19, 22, 23, 28, 5, 27, 32, 30,
|
||||
31, 17, 0, 21, 20,
|
||||
1, -2, 2, 3, 0, 14, -2, -2, 0, 4,
|
||||
0, 15, 16, 0, 17, 18, 9, 10, 11, 12,
|
||||
13, 26, 0, 0, 31, 0, 6, 27, 28, 0,
|
||||
0, 0, 0, 20, 21, 24, 25, 30, 5, 29,
|
||||
34, 32, 33, 19, 0, 23, 22,
|
||||
}
|
||||
var hclTok1 = []int{
|
||||
|
||||
@ -408,12 +414,22 @@ hcldefault:
|
||||
}
|
||||
case 7:
|
||||
//line parse.y:74
|
||||
{
|
||||
hclVAL.str = hclS[hclpt-0].str
|
||||
}
|
||||
case 8:
|
||||
//line parse.y:78
|
||||
{
|
||||
hclVAL.str = hclS[hclpt-0].str
|
||||
}
|
||||
case 9:
|
||||
//line parse.y:84
|
||||
{
|
||||
hclVAL.obj = hclS[hclpt-0].obj
|
||||
hclVAL.obj.Key = hclS[hclpt-2].str
|
||||
}
|
||||
case 8:
|
||||
//line parse.y:79
|
||||
case 10:
|
||||
//line parse.y:89
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclS[hclpt-2].str,
|
||||
@ -421,8 +437,8 @@ hcldefault:
|
||||
Value: hclS[hclpt-0].b,
|
||||
}
|
||||
}
|
||||
case 9:
|
||||
//line parse.y:87
|
||||
case 11:
|
||||
//line parse.y:97
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclS[hclpt-2].str,
|
||||
@ -430,14 +446,14 @@ hcldefault:
|
||||
Value: hclS[hclpt-0].str,
|
||||
}
|
||||
}
|
||||
case 10:
|
||||
//line parse.y:95
|
||||
case 12:
|
||||
//line parse.y:105
|
||||
{
|
||||
hclS[hclpt-0].obj.Key = hclS[hclpt-2].str
|
||||
hclVAL.obj = hclS[hclpt-0].obj
|
||||
}
|
||||
case 11:
|
||||
//line parse.y:100
|
||||
case 13:
|
||||
//line parse.y:110
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclS[hclpt-2].str,
|
||||
@ -445,19 +461,19 @@ hcldefault:
|
||||
Value: hclS[hclpt-0].objlist,
|
||||
}
|
||||
}
|
||||
case 12:
|
||||
//line parse.y:108
|
||||
case 14:
|
||||
//line parse.y:118
|
||||
{
|
||||
hclVAL.obj = hclS[hclpt-0].obj
|
||||
}
|
||||
case 13:
|
||||
//line parse.y:114
|
||||
case 15:
|
||||
//line parse.y:124
|
||||
{
|
||||
hclS[hclpt-0].obj.Key = hclS[hclpt-1].str
|
||||
hclVAL.obj = hclS[hclpt-0].obj
|
||||
}
|
||||
case 14:
|
||||
//line parse.y:119
|
||||
case 16:
|
||||
//line parse.y:129
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclS[hclpt-1].str,
|
||||
@ -465,64 +481,64 @@ hcldefault:
|
||||
Value: []*Object{hclS[hclpt-0].obj},
|
||||
}
|
||||
}
|
||||
case 15:
|
||||
//line parse.y:129
|
||||
{
|
||||
hclVAL.str = hclS[hclpt-0].str
|
||||
}
|
||||
case 16:
|
||||
//line parse.y:133
|
||||
{
|
||||
hclVAL.str = hclS[hclpt-0].str
|
||||
}
|
||||
case 17:
|
||||
//line parse.y:139
|
||||
{
|
||||
hclVAL.objlist = hclS[hclpt-1].objlist
|
||||
hclVAL.str = hclS[hclpt-0].str
|
||||
}
|
||||
case 18:
|
||||
//line parse.y:143
|
||||
{
|
||||
hclVAL.objlist = nil
|
||||
hclVAL.str = hclS[hclpt-0].str
|
||||
}
|
||||
case 19:
|
||||
//line parse.y:149
|
||||
{
|
||||
hclVAL.objlist = []*Object{hclS[hclpt-0].obj}
|
||||
hclVAL.objlist = hclS[hclpt-1].objlist
|
||||
}
|
||||
case 20:
|
||||
//line parse.y:153
|
||||
{
|
||||
hclVAL.objlist = append(hclS[hclpt-2].objlist, hclS[hclpt-0].obj)
|
||||
hclVAL.objlist = nil
|
||||
}
|
||||
case 21:
|
||||
//line parse.y:157
|
||||
//line parse.y:159
|
||||
{
|
||||
hclVAL.objlist = hclS[hclpt-1].objlist
|
||||
hclVAL.objlist = []*Object{hclS[hclpt-0].obj}
|
||||
}
|
||||
case 22:
|
||||
//line parse.y:163
|
||||
{
|
||||
hclVAL.obj = hclS[hclpt-0].obj
|
||||
hclVAL.objlist = append(hclS[hclpt-2].objlist, hclS[hclpt-0].obj)
|
||||
}
|
||||
case 23:
|
||||
//line parse.y:167
|
||||
{
|
||||
hclVAL.objlist = hclS[hclpt-1].objlist
|
||||
}
|
||||
case 24:
|
||||
//line parse.y:173
|
||||
{
|
||||
hclVAL.obj = hclS[hclpt-0].obj
|
||||
}
|
||||
case 25:
|
||||
//line parse.y:177
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeString,
|
||||
Value: hclS[hclpt-0].str,
|
||||
}
|
||||
}
|
||||
case 24:
|
||||
//line parse.y:176
|
||||
case 26:
|
||||
//line parse.y:186
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeInt,
|
||||
Value: hclS[hclpt-0].num,
|
||||
}
|
||||
}
|
||||
case 25:
|
||||
//line parse.y:183
|
||||
case 27:
|
||||
//line parse.y:193
|
||||
{
|
||||
fs := fmt.Sprintf("%d.%s", hclS[hclpt-1].num, hclS[hclpt-0].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
@ -535,8 +551,8 @@ hcldefault:
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 26:
|
||||
//line parse.y:196
|
||||
case 28:
|
||||
//line parse.y:206
|
||||
{
|
||||
fs := fmt.Sprintf("%d%s", hclS[hclpt-1].num, hclS[hclpt-0].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
@ -549,8 +565,8 @@ hcldefault:
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 27:
|
||||
//line parse.y:209
|
||||
case 29:
|
||||
//line parse.y:219
|
||||
{
|
||||
fs := fmt.Sprintf("%d.%s%s", hclS[hclpt-2].num, hclS[hclpt-1].str, hclS[hclpt-0].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
@ -563,28 +579,28 @@ hcldefault:
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 28:
|
||||
//line parse.y:224
|
||||
{
|
||||
hclVAL.num = hclS[hclpt-0].num * -1
|
||||
}
|
||||
case 29:
|
||||
//line parse.y:228
|
||||
{
|
||||
hclVAL.num = hclS[hclpt-0].num
|
||||
}
|
||||
case 30:
|
||||
//line parse.y:234
|
||||
{
|
||||
hclVAL.str = "e" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||
hclVAL.num = hclS[hclpt-0].num * -1
|
||||
}
|
||||
case 31:
|
||||
//line parse.y:238
|
||||
{
|
||||
hclVAL.str = "e-" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||
hclVAL.num = hclS[hclpt-0].num
|
||||
}
|
||||
case 32:
|
||||
//line parse.y:244
|
||||
{
|
||||
hclVAL.str = "e" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||
}
|
||||
case 33:
|
||||
//line parse.y:248
|
||||
{
|
||||
hclVAL.str = "e-" + strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||
}
|
||||
case 34:
|
||||
//line parse.y:254
|
||||
{
|
||||
hclVAL.str = strconv.FormatInt(int64(hclS[hclpt-0].num), 10)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user