Esempio n. 1
0
func (jsonrcvr *jsonParserImpl) Parse(jsonlex jsonLexer) int {
	var jsonn int
	var jsonlval jsonSymType
	var jsonVAL jsonSymType
	var jsonDollar []jsonSymType
	_ = jsonDollar // silence set and not used
	jsonS := make([]jsonSymType, jsonMaxDepth)

	Nerrs := 0   /* number of errors */
	Errflag := 0 /* error recovery flag */
	jsonstate := 0
	jsonchar := -1
	jsontoken := -1 // jsonchar translated into internal numbering
	jsonrcvr.lookahead = func() int { return jsonchar }
	defer func() {
		// Make sure we report no lookahead when not parsing.
		jsonstate = -1
		jsonchar = -1
		jsontoken = -1
	}()
	jsonp := -1
	goto jsonstack

ret0:
	return 0

ret1:
	return 1

jsonstack:
	/* put a state and value onto the stack */
	if jsonDebug >= 4 {
		__yyfmt__.Printf("char %v in %v\n", jsonTokname(jsontoken), jsonStatname(jsonstate))
	}

	jsonp++
	if jsonp >= len(jsonS) {
		nyys := make([]jsonSymType, len(jsonS)*2)
		copy(nyys, jsonS)
		jsonS = nyys
	}
	jsonS[jsonp] = jsonVAL
	jsonS[jsonp].yys = jsonstate

jsonnewstate:
	jsonn = jsonPact[jsonstate]
	if jsonn <= jsonFlag {
		goto jsondefault /* simple state */
	}
	if jsonchar < 0 {
		jsonchar, jsontoken = jsonlex1(jsonlex, &jsonlval)
	}
	jsonn += jsontoken
	if jsonn < 0 || jsonn >= jsonLast {
		goto jsondefault
	}
	jsonn = jsonAct[jsonn]
	if jsonChk[jsonn] == jsontoken { /* valid shift */
		jsonchar = -1
		jsontoken = -1
		jsonVAL = jsonlval
		jsonstate = jsonn
		if Errflag > 0 {
			Errflag--
		}
		goto jsonstack
	}

jsondefault:
	/* default state action */
	jsonn = jsonDef[jsonstate]
	if jsonn == -2 {
		if jsonchar < 0 {
			jsonchar, jsontoken = jsonlex1(jsonlex, &jsonlval)
		}

		/* look through exception table */
		xi := 0
		for {
			if jsonExca[xi+0] == -1 && jsonExca[xi+1] == jsonstate {
				break
			}
			xi += 2
		}
		for xi += 2; ; xi += 2 {
			jsonn = jsonExca[xi+0]
			if jsonn < 0 || jsonn == jsontoken {
				break
			}
		}
		jsonn = jsonExca[xi+1]
		if jsonn < 0 {
			goto ret0
		}
	}
	if jsonn == 0 {
		/* error ... attempt to resume parsing */
		switch Errflag {
		case 0: /* brand new error */
			jsonlex.Error(jsonErrorMessage(jsonstate, jsontoken))
			Nerrs++
			if jsonDebug >= 1 {
				__yyfmt__.Printf("%s", jsonStatname(jsonstate))
				__yyfmt__.Printf(" saw %s\n", jsonTokname(jsontoken))
			}
			fallthrough

		case 1, 2: /* incompletely recovered error ... try again */
			Errflag = 3

			/* find a state where "error" is a legal shift action */
			for jsonp >= 0 {
				jsonn = jsonPact[jsonS[jsonp].yys] + jsonErrCode
				if jsonn >= 0 && jsonn < jsonLast {
					jsonstate = jsonAct[jsonn] /* simulate a shift of "error" */
					if jsonChk[jsonstate] == jsonErrCode {
						goto jsonstack
					}
				}

				/* the current p has no shift on "error", pop stack */
				if jsonDebug >= 2 {
					__yyfmt__.Printf("error recovery pops state %d\n", jsonS[jsonp].yys)
				}
				jsonp--
			}
			/* there is no state on the stack with an error shift ... abort */
			goto ret1

		case 3: /* no shift yet; clobber input char */
			if jsonDebug >= 2 {
				__yyfmt__.Printf("error recovery discards %s\n", jsonTokname(jsontoken))
			}
			if jsontoken == jsonEofCode {
				goto ret1
			}
			jsonchar = -1
			jsontoken = -1
			goto jsonnewstate /* try again in the same state */
		}
	}

	/* reduction by production jsonn */
	if jsonDebug >= 2 {
		__yyfmt__.Printf("reduce %v in:\n\t%v\n", jsonn, jsonStatname(jsonstate))
	}

	jsonnt := jsonn
	jsonpt := jsonp
	_ = jsonpt // guard against "declared and not used"

	jsonp -= jsonR2[jsonn]
	// jsonp is now the index of $0. Perform the default action. Iff the
	// reduced production is ε, $1 is possibly out of range.
	if jsonp+1 >= len(jsonS) {
		nyys := make([]jsonSymType, len(jsonS)*2)
		copy(nyys, jsonS)
		jsonS = nyys
	}
	jsonVAL = jsonS[jsonp+1]

	/* consult goto table to find next state */
	jsonn = jsonR1[jsonn]
	jsong := jsonPgo[jsonn]
	jsonj := jsong + jsonS[jsonp].yys + 1

	if jsonj >= jsonLast {
		jsonstate = jsonAct[jsong]
	} else {
		jsonstate = jsonAct[jsonj]
		if jsonChk[jsonstate] != -jsonn {
			jsonstate = jsonAct[jsong]
		}
	}
	// dummy call; replaced with literal code
	switch jsonnt {

	case 1:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:39
		{
			jsonResult = jsonDollar[1].obj
		}
	case 2:
		jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
		//line parse.y:45
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeObject,
				Value: hcl.ObjectList(jsonDollar[2].objlist).Flat(),
			}
		}
	case 3:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:52
		{
			jsonVAL.obj = &hcl.Object{Type: hcl.ValueTypeObject}
		}
	case 4:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:58
		{
			jsonVAL.objlist = []*hcl.Object{jsonDollar[1].obj}
		}
	case 5:
		jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
		//line parse.y:62
		{
			jsonVAL.objlist = append(jsonDollar[1].objlist, jsonDollar[3].obj)
		}
	case 6:
		jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
		//line parse.y:68
		{
			jsonDollar[3].obj.Key = jsonDollar[1].str
			jsonVAL.obj = jsonDollar[3].obj
		}
	case 7:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:75
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeString,
				Value: jsonDollar[1].str,
			}
		}
	case 8:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:82
		{
			jsonVAL.obj = jsonDollar[1].obj
		}
	case 9:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:86
		{
			jsonVAL.obj = jsonDollar[1].obj
		}
	case 10:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:90
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeList,
				Value: jsonDollar[1].objlist,
			}
		}
	case 11:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:97
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeBool,
				Value: true,
			}
		}
	case 12:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:104
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeBool,
				Value: false,
			}
		}
	case 13:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:111
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeNil,
				Value: nil,
			}
		}
	case 14:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:120
		{
			jsonVAL.objlist = nil
		}
	case 15:
		jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
		//line parse.y:124
		{
			jsonVAL.objlist = jsonDollar[2].objlist
		}
	case 16:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:130
		{
			jsonVAL.objlist = []*hcl.Object{jsonDollar[1].obj}
		}
	case 17:
		jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
		//line parse.y:134
		{
			jsonVAL.objlist = append(jsonDollar[1].objlist, jsonDollar[3].obj)
		}
	case 18:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:140
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeInt,
				Value: jsonDollar[1].num,
			}
		}
	case 19:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:147
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeFloat,
				Value: jsonDollar[1].f,
			}
		}
	case 20:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:154
		{
			fs := fmt.Sprintf("%d%s", jsonDollar[1].num, jsonDollar[2].str)
			f, err := strconv.ParseFloat(fs, 64)
			if err != nil {
				panic(err)
			}

			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeFloat,
				Value: f,
			}
		}
	case 21:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:167
		{
			fs := fmt.Sprintf("%f%s", jsonDollar[1].f, jsonDollar[2].str)
			f, err := strconv.ParseFloat(fs, 64)
			if err != nil {
				panic(err)
			}

			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeFloat,
				Value: f,
			}
		}
	case 22:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:182
		{
			jsonVAL.num = jsonDollar[2].num * -1
		}
	case 23:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:186
		{
			jsonVAL.num = jsonDollar[1].num
		}
	case 24:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:192
		{
			jsonVAL.f = jsonDollar[2].f * -1
		}
	case 25:
		jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
		//line parse.y:196
		{
			jsonVAL.f = jsonDollar[1].f
		}
	case 26:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:202
		{
			jsonVAL.str = "e" + strconv.FormatInt(int64(jsonDollar[2].num), 10)
		}
	case 27:
		jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
		//line parse.y:206
		{
			jsonVAL.str = "e-" + strconv.FormatInt(int64(jsonDollar[2].num), 10)
		}
	}
	goto jsonstack /* stack new state and value */
}
Esempio n. 2
0
File: y.go Progetto: johnnoone/hcl
func jsonParse(jsonlex jsonLexer) int {
	var jsonn int
	var jsonlval jsonSymType
	var jsonVAL jsonSymType
	jsonS := make([]jsonSymType, jsonMaxDepth)

	Nerrs := 0   /* number of errors */
	Errflag := 0 /* error recovery flag */
	jsonstate := 0
	jsonchar := -1
	jsonp := -1
	goto jsonstack

ret0:
	return 0

ret1:
	return 1

jsonstack:
	/* put a state and value onto the stack */
	if jsonDebug >= 4 {
		__yyfmt__.Printf("char %v in %v\n", jsonTokname(jsonchar), jsonStatname(jsonstate))
	}

	jsonp++
	if jsonp >= len(jsonS) {
		nyys := make([]jsonSymType, len(jsonS)*2)
		copy(nyys, jsonS)
		jsonS = nyys
	}
	jsonS[jsonp] = jsonVAL
	jsonS[jsonp].yys = jsonstate

jsonnewstate:
	jsonn = jsonPact[jsonstate]
	if jsonn <= jsonFlag {
		goto jsondefault /* simple state */
	}
	if jsonchar < 0 {
		jsonchar = jsonlex1(jsonlex, &jsonlval)
	}
	jsonn += jsonchar
	if jsonn < 0 || jsonn >= jsonLast {
		goto jsondefault
	}
	jsonn = jsonAct[jsonn]
	if jsonChk[jsonn] == jsonchar { /* valid shift */
		jsonchar = -1
		jsonVAL = jsonlval
		jsonstate = jsonn
		if Errflag > 0 {
			Errflag--
		}
		goto jsonstack
	}

jsondefault:
	/* default state action */
	jsonn = jsonDef[jsonstate]
	if jsonn == -2 {
		if jsonchar < 0 {
			jsonchar = jsonlex1(jsonlex, &jsonlval)
		}

		/* look through exception table */
		xi := 0
		for {
			if jsonExca[xi+0] == -1 && jsonExca[xi+1] == jsonstate {
				break
			}
			xi += 2
		}
		for xi += 2; ; xi += 2 {
			jsonn = jsonExca[xi+0]
			if jsonn < 0 || jsonn == jsonchar {
				break
			}
		}
		jsonn = jsonExca[xi+1]
		if jsonn < 0 {
			goto ret0
		}
	}
	if jsonn == 0 {
		/* error ... attempt to resume parsing */
		switch Errflag {
		case 0: /* brand new error */
			jsonlex.Error("syntax error")
			Nerrs++
			if jsonDebug >= 1 {
				__yyfmt__.Printf("%s", jsonStatname(jsonstate))
				__yyfmt__.Printf(" saw %s\n", jsonTokname(jsonchar))
			}
			fallthrough

		case 1, 2: /* incompletely recovered error ... try again */
			Errflag = 3

			/* find a state where "error" is a legal shift action */
			for jsonp >= 0 {
				jsonn = jsonPact[jsonS[jsonp].yys] + jsonErrCode
				if jsonn >= 0 && jsonn < jsonLast {
					jsonstate = jsonAct[jsonn] /* simulate a shift of "error" */
					if jsonChk[jsonstate] == jsonErrCode {
						goto jsonstack
					}
				}

				/* the current p has no shift on "error", pop stack */
				if jsonDebug >= 2 {
					__yyfmt__.Printf("error recovery pops state %d\n", jsonS[jsonp].yys)
				}
				jsonp--
			}
			/* there is no state on the stack with an error shift ... abort */
			goto ret1

		case 3: /* no shift yet; clobber input char */
			if jsonDebug >= 2 {
				__yyfmt__.Printf("error recovery discards %s\n", jsonTokname(jsonchar))
			}
			if jsonchar == jsonEofCode {
				goto ret1
			}
			jsonchar = -1
			goto jsonnewstate /* try again in the same state */
		}
	}

	/* reduction by production jsonn */
	if jsonDebug >= 2 {
		__yyfmt__.Printf("reduce %v in:\n\t%v\n", jsonn, jsonStatname(jsonstate))
	}

	jsonnt := jsonn
	jsonpt := jsonp
	_ = jsonpt // guard against "declared and not used"

	jsonp -= jsonR2[jsonn]
	jsonVAL = jsonS[jsonp+1]

	/* consult goto table to find next state */
	jsonn = jsonR1[jsonn]
	jsong := jsonPgo[jsonn]
	jsonj := jsong + jsonS[jsonp].yys + 1

	if jsonj >= jsonLast {
		jsonstate = jsonAct[jsong]
	} else {
		jsonstate = jsonAct[jsonj]
		if jsonChk[jsonstate] != -jsonn {
			jsonstate = jsonAct[jsong]
		}
	}
	// dummy call; replaced with literal code
	switch jsonnt {

	case 1:
		//line parse.y:36
		{
			jsonResult = jsonS[jsonpt-0].obj
		}
	case 2:
		//line parse.y:42
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeObject,
				Value: hcl.ObjectList(jsonS[jsonpt-1].objlist).Flat(),
			}
		}
	case 3:
		//line parse.y:49
		{
			jsonVAL.obj = &hcl.Object{Type: hcl.ValueTypeObject}
		}
	case 4:
		//line parse.y:55
		{
			jsonVAL.objlist = []*hcl.Object{jsonS[jsonpt-0].obj}
		}
	case 5:
		//line parse.y:59
		{
			jsonVAL.objlist = append(jsonS[jsonpt-2].objlist, jsonS[jsonpt-0].obj)
		}
	case 6:
		//line parse.y:65
		{
			jsonS[jsonpt-0].obj.Key = jsonS[jsonpt-2].str
			jsonVAL.obj = jsonS[jsonpt-0].obj
		}
	case 7:
		//line parse.y:72
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeString,
				Value: jsonS[jsonpt-0].str,
			}
		}
	case 8:
		//line parse.y:79
		{
			jsonVAL.obj = jsonS[jsonpt-0].obj
		}
	case 9:
		//line parse.y:83
		{
			jsonVAL.obj = jsonS[jsonpt-0].obj
		}
	case 10:
		//line parse.y:87
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeList,
				Value: jsonS[jsonpt-0].objlist,
			}
		}
	case 11:
		//line parse.y:94
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeBool,
				Value: true,
			}
		}
	case 12:
		//line parse.y:101
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeBool,
				Value: false,
			}
		}
	case 13:
		//line parse.y:108
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeNil,
				Value: nil,
			}
		}
	case 14:
		//line parse.y:117
		{
			jsonVAL.objlist = nil
		}
	case 15:
		//line parse.y:121
		{
			jsonVAL.objlist = jsonS[jsonpt-1].objlist
		}
	case 16:
		//line parse.y:127
		{
			jsonVAL.objlist = []*hcl.Object{jsonS[jsonpt-0].obj}
		}
	case 17:
		//line parse.y:131
		{
			jsonVAL.objlist = append(jsonS[jsonpt-2].objlist, jsonS[jsonpt-0].obj)
		}
	case 18:
		//line parse.y:137
		{
			jsonVAL.obj = &hcl.Object{
				Type:  hcl.ValueTypeInt,
				Value: jsonS[jsonpt-0].num,
			}
		}
	case 19:
		//line parse.y:144
		{
			fs := fmt.Sprintf("%d.%s", jsonS[jsonpt-1].num, 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 20:
		//line parse.y:157
		{
			fs := fmt.Sprintf("%d%s", jsonS[jsonpt-1].num, 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 21:
		//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
		}
	case 23:
		//line parse.y:189
		{
			jsonVAL.num = jsonS[jsonpt-0].num
		}
	case 24:
		//line parse.y:195
		{
			jsonVAL.str = "e" + strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
		}
	case 25:
		//line parse.y:199
		{
			jsonVAL.str = "e-" + strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
		}
	case 26:
		//line parse.y:205
		{
			jsonVAL.str = strconv.FormatInt(int64(jsonS[jsonpt-0].num), 10)
		}
	}
	goto jsonstack /* stack new state and value */
}