github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/config/lang/y.go (about)

     1  //line lang.y:6
     2  package lang
     3  
     4  import __yyfmt__ "fmt"
     5  
     6  //line lang.y:6
     7  import (
     8  	"github.com/hashicorp/terraform/config/lang/ast"
     9  )
    10  
    11  //line lang.y:14
    12  type parserSymType struct {
    13  	yys      int
    14  	node     ast.Node
    15  	nodeList []ast.Node
    16  	str      string
    17  	token    *parserToken
    18  }
    19  
    20  const PROGRAM_BRACKET_LEFT = 57346
    21  const PROGRAM_BRACKET_RIGHT = 57347
    22  const PROGRAM_STRING_START = 57348
    23  const PROGRAM_STRING_END = 57349
    24  const PAREN_LEFT = 57350
    25  const PAREN_RIGHT = 57351
    26  const COMMA = 57352
    27  const ARITH_OP = 57353
    28  const IDENTIFIER = 57354
    29  const INTEGER = 57355
    30  const FLOAT = 57356
    31  const STRING = 57357
    32  
    33  var parserToknames = [...]string{
    34  	"$end",
    35  	"error",
    36  	"$unk",
    37  	"PROGRAM_BRACKET_LEFT",
    38  	"PROGRAM_BRACKET_RIGHT",
    39  	"PROGRAM_STRING_START",
    40  	"PROGRAM_STRING_END",
    41  	"PAREN_LEFT",
    42  	"PAREN_RIGHT",
    43  	"COMMA",
    44  	"ARITH_OP",
    45  	"IDENTIFIER",
    46  	"INTEGER",
    47  	"FLOAT",
    48  	"STRING",
    49  }
    50  var parserStatenames = [...]string{}
    51  
    52  const parserEofCode = 1
    53  const parserErrCode = 2
    54  const parserMaxDepth = 200
    55  
    56  //line lang.y:165
    57  
    58  //line yacctab:1
    59  var parserExca = [...]int{
    60  	-1, 1,
    61  	1, -1,
    62  	-2, 0,
    63  }
    64  
    65  const parserNprod = 19
    66  const parserPrivate = 57344
    67  
    68  var parserTokenNames []string
    69  var parserStates []string
    70  
    71  const parserLast = 30
    72  
    73  var parserAct = [...]int{
    74  
    75  	9, 20, 16, 16, 7, 7, 3, 18, 10, 8,
    76  	1, 17, 14, 12, 13, 6, 6, 19, 8, 22,
    77  	15, 23, 24, 11, 2, 25, 16, 21, 4, 5,
    78  }
    79  var parserPact = [...]int{
    80  
    81  	1, -1000, 1, -1000, -1000, -1000, -1000, 0, -1000, 15,
    82  	0, 1, -1000, -1000, -1, -1000, 0, -8, 0, -1000,
    83  	-1000, 12, -9, -1000, 0, -9,
    84  }
    85  var parserPgo = [...]int{
    86  
    87  	0, 0, 29, 28, 23, 6, 27, 10,
    88  }
    89  var parserR1 = [...]int{
    90  
    91  	0, 7, 7, 4, 4, 5, 5, 2, 1, 1,
    92  	1, 1, 1, 1, 1, 6, 6, 6, 3,
    93  }
    94  var parserR2 = [...]int{
    95  
    96  	0, 0, 1, 1, 2, 1, 1, 3, 3, 1,
    97  	1, 1, 3, 1, 4, 0, 3, 1, 1,
    98  }
    99  var parserChk = [...]int{
   100  
   101  	-1000, -7, -4, -5, -3, -2, 15, 4, -5, -1,
   102  	8, -4, 13, 14, 12, 5, 11, -1, 8, -1,
   103  	9, -6, -1, 9, 10, -1,
   104  }
   105  var parserDef = [...]int{
   106  
   107  	1, -2, 2, 3, 5, 6, 18, 0, 4, 0,
   108  	0, 9, 10, 11, 13, 7, 0, 0, 15, 12,
   109  	8, 0, 17, 14, 0, 16,
   110  }
   111  var parserTok1 = [...]int{
   112  
   113  	1,
   114  }
   115  var parserTok2 = [...]int{
   116  
   117  	2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
   118  	12, 13, 14, 15,
   119  }
   120  var parserTok3 = [...]int{
   121  	0,
   122  }
   123  
   124  var parserErrorMessages = [...]struct {
   125  	state int
   126  	token int
   127  	msg   string
   128  }{}
   129  
   130  //line yaccpar:1
   131  
   132  /*	parser for yacc output	*/
   133  
   134  var (
   135  	parserDebug        = 0
   136  	parserErrorVerbose = false
   137  )
   138  
   139  type parserLexer interface {
   140  	Lex(lval *parserSymType) int
   141  	Error(s string)
   142  }
   143  
   144  type parserParser interface {
   145  	Parse(parserLexer) int
   146  	Lookahead() int
   147  }
   148  
   149  type parserParserImpl struct {
   150  	lookahead func() int
   151  }
   152  
   153  func (p *parserParserImpl) Lookahead() int {
   154  	return p.lookahead()
   155  }
   156  
   157  func parserNewParser() parserParser {
   158  	p := &parserParserImpl{
   159  		lookahead: func() int { return -1 },
   160  	}
   161  	return p
   162  }
   163  
   164  const parserFlag = -1000
   165  
   166  func parserTokname(c int) string {
   167  	if c >= 1 && c-1 < len(parserToknames) {
   168  		if parserToknames[c-1] != "" {
   169  			return parserToknames[c-1]
   170  		}
   171  	}
   172  	return __yyfmt__.Sprintf("tok-%v", c)
   173  }
   174  
   175  func parserStatname(s int) string {
   176  	if s >= 0 && s < len(parserStatenames) {
   177  		if parserStatenames[s] != "" {
   178  			return parserStatenames[s]
   179  		}
   180  	}
   181  	return __yyfmt__.Sprintf("state-%v", s)
   182  }
   183  
   184  func parserErrorMessage(state, lookAhead int) string {
   185  	const TOKSTART = 4
   186  
   187  	if !parserErrorVerbose {
   188  		return "syntax error"
   189  	}
   190  
   191  	for _, e := range parserErrorMessages {
   192  		if e.state == state && e.token == lookAhead {
   193  			return "syntax error: " + e.msg
   194  		}
   195  	}
   196  
   197  	res := "syntax error: unexpected " + parserTokname(lookAhead)
   198  
   199  	// To match Bison, suggest at most four expected tokens.
   200  	expected := make([]int, 0, 4)
   201  
   202  	// Look for shiftable tokens.
   203  	base := parserPact[state]
   204  	for tok := TOKSTART; tok-1 < len(parserToknames); tok++ {
   205  		if n := base + tok; n >= 0 && n < parserLast && parserChk[parserAct[n]] == tok {
   206  			if len(expected) == cap(expected) {
   207  				return res
   208  			}
   209  			expected = append(expected, tok)
   210  		}
   211  	}
   212  
   213  	if parserDef[state] == -2 {
   214  		i := 0
   215  		for parserExca[i] != -1 || parserExca[i+1] != state {
   216  			i += 2
   217  		}
   218  
   219  		// Look for tokens that we accept or reduce.
   220  		for i += 2; parserExca[i] >= 0; i += 2 {
   221  			tok := parserExca[i]
   222  			if tok < TOKSTART || parserExca[i+1] == 0 {
   223  				continue
   224  			}
   225  			if len(expected) == cap(expected) {
   226  				return res
   227  			}
   228  			expected = append(expected, tok)
   229  		}
   230  
   231  		// If the default action is to accept or reduce, give up.
   232  		if parserExca[i+1] != 0 {
   233  			return res
   234  		}
   235  	}
   236  
   237  	for i, tok := range expected {
   238  		if i == 0 {
   239  			res += ", expecting "
   240  		} else {
   241  			res += " or "
   242  		}
   243  		res += parserTokname(tok)
   244  	}
   245  	return res
   246  }
   247  
   248  func parserlex1(lex parserLexer, lval *parserSymType) (char, token int) {
   249  	token = 0
   250  	char = lex.Lex(lval)
   251  	if char <= 0 {
   252  		token = parserTok1[0]
   253  		goto out
   254  	}
   255  	if char < len(parserTok1) {
   256  		token = parserTok1[char]
   257  		goto out
   258  	}
   259  	if char >= parserPrivate {
   260  		if char < parserPrivate+len(parserTok2) {
   261  			token = parserTok2[char-parserPrivate]
   262  			goto out
   263  		}
   264  	}
   265  	for i := 0; i < len(parserTok3); i += 2 {
   266  		token = parserTok3[i+0]
   267  		if token == char {
   268  			token = parserTok3[i+1]
   269  			goto out
   270  		}
   271  	}
   272  
   273  out:
   274  	if token == 0 {
   275  		token = parserTok2[1] /* unknown char */
   276  	}
   277  	if parserDebug >= 3 {
   278  		__yyfmt__.Printf("lex %s(%d)\n", parserTokname(token), uint(char))
   279  	}
   280  	return char, token
   281  }
   282  
   283  func parserParse(parserlex parserLexer) int {
   284  	return parserNewParser().Parse(parserlex)
   285  }
   286  
   287  func (parserrcvr *parserParserImpl) Parse(parserlex parserLexer) int {
   288  	var parsern int
   289  	var parserlval parserSymType
   290  	var parserVAL parserSymType
   291  	var parserDollar []parserSymType
   292  	_ = parserDollar // silence set and not used
   293  	parserS := make([]parserSymType, parserMaxDepth)
   294  
   295  	Nerrs := 0   /* number of errors */
   296  	Errflag := 0 /* error recovery flag */
   297  	parserstate := 0
   298  	parserchar := -1
   299  	parsertoken := -1 // parserchar translated into internal numbering
   300  	parserrcvr.lookahead = func() int { return parserchar }
   301  	defer func() {
   302  		// Make sure we report no lookahead when not parsing.
   303  		parserstate = -1
   304  		parserchar = -1
   305  		parsertoken = -1
   306  	}()
   307  	parserp := -1
   308  	goto parserstack
   309  
   310  ret0:
   311  	return 0
   312  
   313  ret1:
   314  	return 1
   315  
   316  parserstack:
   317  	/* put a state and value onto the stack */
   318  	if parserDebug >= 4 {
   319  		__yyfmt__.Printf("char %v in %v\n", parserTokname(parsertoken), parserStatname(parserstate))
   320  	}
   321  
   322  	parserp++
   323  	if parserp >= len(parserS) {
   324  		nyys := make([]parserSymType, len(parserS)*2)
   325  		copy(nyys, parserS)
   326  		parserS = nyys
   327  	}
   328  	parserS[parserp] = parserVAL
   329  	parserS[parserp].yys = parserstate
   330  
   331  parsernewstate:
   332  	parsern = parserPact[parserstate]
   333  	if parsern <= parserFlag {
   334  		goto parserdefault /* simple state */
   335  	}
   336  	if parserchar < 0 {
   337  		parserchar, parsertoken = parserlex1(parserlex, &parserlval)
   338  	}
   339  	parsern += parsertoken
   340  	if parsern < 0 || parsern >= parserLast {
   341  		goto parserdefault
   342  	}
   343  	parsern = parserAct[parsern]
   344  	if parserChk[parsern] == parsertoken { /* valid shift */
   345  		parserchar = -1
   346  		parsertoken = -1
   347  		parserVAL = parserlval
   348  		parserstate = parsern
   349  		if Errflag > 0 {
   350  			Errflag--
   351  		}
   352  		goto parserstack
   353  	}
   354  
   355  parserdefault:
   356  	/* default state action */
   357  	parsern = parserDef[parserstate]
   358  	if parsern == -2 {
   359  		if parserchar < 0 {
   360  			parserchar, parsertoken = parserlex1(parserlex, &parserlval)
   361  		}
   362  
   363  		/* look through exception table */
   364  		xi := 0
   365  		for {
   366  			if parserExca[xi+0] == -1 && parserExca[xi+1] == parserstate {
   367  				break
   368  			}
   369  			xi += 2
   370  		}
   371  		for xi += 2; ; xi += 2 {
   372  			parsern = parserExca[xi+0]
   373  			if parsern < 0 || parsern == parsertoken {
   374  				break
   375  			}
   376  		}
   377  		parsern = parserExca[xi+1]
   378  		if parsern < 0 {
   379  			goto ret0
   380  		}
   381  	}
   382  	if parsern == 0 {
   383  		/* error ... attempt to resume parsing */
   384  		switch Errflag {
   385  		case 0: /* brand new error */
   386  			parserlex.Error(parserErrorMessage(parserstate, parsertoken))
   387  			Nerrs++
   388  			if parserDebug >= 1 {
   389  				__yyfmt__.Printf("%s", parserStatname(parserstate))
   390  				__yyfmt__.Printf(" saw %s\n", parserTokname(parsertoken))
   391  			}
   392  			fallthrough
   393  
   394  		case 1, 2: /* incompletely recovered error ... try again */
   395  			Errflag = 3
   396  
   397  			/* find a state where "error" is a legal shift action */
   398  			for parserp >= 0 {
   399  				parsern = parserPact[parserS[parserp].yys] + parserErrCode
   400  				if parsern >= 0 && parsern < parserLast {
   401  					parserstate = parserAct[parsern] /* simulate a shift of "error" */
   402  					if parserChk[parserstate] == parserErrCode {
   403  						goto parserstack
   404  					}
   405  				}
   406  
   407  				/* the current p has no shift on "error", pop stack */
   408  				if parserDebug >= 2 {
   409  					__yyfmt__.Printf("error recovery pops state %d\n", parserS[parserp].yys)
   410  				}
   411  				parserp--
   412  			}
   413  			/* there is no state on the stack with an error shift ... abort */
   414  			goto ret1
   415  
   416  		case 3: /* no shift yet; clobber input char */
   417  			if parserDebug >= 2 {
   418  				__yyfmt__.Printf("error recovery discards %s\n", parserTokname(parsertoken))
   419  			}
   420  			if parsertoken == parserEofCode {
   421  				goto ret1
   422  			}
   423  			parserchar = -1
   424  			parsertoken = -1
   425  			goto parsernewstate /* try again in the same state */
   426  		}
   427  	}
   428  
   429  	/* reduction by production parsern */
   430  	if parserDebug >= 2 {
   431  		__yyfmt__.Printf("reduce %v in:\n\t%v\n", parsern, parserStatname(parserstate))
   432  	}
   433  
   434  	parsernt := parsern
   435  	parserpt := parserp
   436  	_ = parserpt // guard against "declared and not used"
   437  
   438  	parserp -= parserR2[parsern]
   439  	// parserp is now the index of $0. Perform the default action. Iff the
   440  	// reduced production is ε, $1 is possibly out of range.
   441  	if parserp+1 >= len(parserS) {
   442  		nyys := make([]parserSymType, len(parserS)*2)
   443  		copy(nyys, parserS)
   444  		parserS = nyys
   445  	}
   446  	parserVAL = parserS[parserp+1]
   447  
   448  	/* consult goto table to find next state */
   449  	parsern = parserR1[parsern]
   450  	parserg := parserPgo[parsern]
   451  	parserj := parserg + parserS[parserp].yys + 1
   452  
   453  	if parserj >= parserLast {
   454  		parserstate = parserAct[parserg]
   455  	} else {
   456  		parserstate = parserAct[parserj]
   457  		if parserChk[parserstate] != -parsern {
   458  			parserstate = parserAct[parserg]
   459  		}
   460  	}
   461  	// dummy call; replaced with literal code
   462  	switch parsernt {
   463  
   464  	case 1:
   465  		parserDollar = parserS[parserpt-0 : parserpt+1]
   466  		//line lang.y:35
   467  		{
   468  			parserResult = &ast.LiteralNode{
   469  				Value: "",
   470  				Typex: ast.TypeString,
   471  				Posx:  ast.Pos{Column: 1, Line: 1},
   472  			}
   473  		}
   474  	case 2:
   475  		parserDollar = parserS[parserpt-1 : parserpt+1]
   476  		//line lang.y:43
   477  		{
   478  			parserResult = parserDollar[1].node
   479  
   480  			// We want to make sure that the top value is always a Concat
   481  			// so that the return value is always a string type from an
   482  			// interpolation.
   483  			//
   484  			// The logic for checking for a LiteralNode is a little annoying
   485  			// because functionally the AST is the same, but we do that because
   486  			// it makes for an easy literal check later (to check if a string
   487  			// has any interpolations).
   488  			if _, ok := parserDollar[1].node.(*ast.Concat); !ok {
   489  				if n, ok := parserDollar[1].node.(*ast.LiteralNode); !ok || n.Typex != ast.TypeString {
   490  					parserResult = &ast.Concat{
   491  						Exprs: []ast.Node{parserDollar[1].node},
   492  						Posx:  parserDollar[1].node.Pos(),
   493  					}
   494  				}
   495  			}
   496  		}
   497  	case 3:
   498  		parserDollar = parserS[parserpt-1 : parserpt+1]
   499  		//line lang.y:66
   500  		{
   501  			parserVAL.node = parserDollar[1].node
   502  		}
   503  	case 4:
   504  		parserDollar = parserS[parserpt-2 : parserpt+1]
   505  		//line lang.y:70
   506  		{
   507  			var result []ast.Node
   508  			if c, ok := parserDollar[1].node.(*ast.Concat); ok {
   509  				result = append(c.Exprs, parserDollar[2].node)
   510  			} else {
   511  				result = []ast.Node{parserDollar[1].node, parserDollar[2].node}
   512  			}
   513  
   514  			parserVAL.node = &ast.Concat{
   515  				Exprs: result,
   516  				Posx:  result[0].Pos(),
   517  			}
   518  		}
   519  	case 5:
   520  		parserDollar = parserS[parserpt-1 : parserpt+1]
   521  		//line lang.y:86
   522  		{
   523  			parserVAL.node = parserDollar[1].node
   524  		}
   525  	case 6:
   526  		parserDollar = parserS[parserpt-1 : parserpt+1]
   527  		//line lang.y:90
   528  		{
   529  			parserVAL.node = parserDollar[1].node
   530  		}
   531  	case 7:
   532  		parserDollar = parserS[parserpt-3 : parserpt+1]
   533  		//line lang.y:96
   534  		{
   535  			parserVAL.node = parserDollar[2].node
   536  		}
   537  	case 8:
   538  		parserDollar = parserS[parserpt-3 : parserpt+1]
   539  		//line lang.y:102
   540  		{
   541  			parserVAL.node = parserDollar[2].node
   542  		}
   543  	case 9:
   544  		parserDollar = parserS[parserpt-1 : parserpt+1]
   545  		//line lang.y:106
   546  		{
   547  			parserVAL.node = parserDollar[1].node
   548  		}
   549  	case 10:
   550  		parserDollar = parserS[parserpt-1 : parserpt+1]
   551  		//line lang.y:110
   552  		{
   553  			parserVAL.node = &ast.LiteralNode{
   554  				Value: parserDollar[1].token.Value.(int),
   555  				Typex: ast.TypeInt,
   556  				Posx:  parserDollar[1].token.Pos,
   557  			}
   558  		}
   559  	case 11:
   560  		parserDollar = parserS[parserpt-1 : parserpt+1]
   561  		//line lang.y:118
   562  		{
   563  			parserVAL.node = &ast.LiteralNode{
   564  				Value: parserDollar[1].token.Value.(float64),
   565  				Typex: ast.TypeFloat,
   566  				Posx:  parserDollar[1].token.Pos,
   567  			}
   568  		}
   569  	case 12:
   570  		parserDollar = parserS[parserpt-3 : parserpt+1]
   571  		//line lang.y:126
   572  		{
   573  			parserVAL.node = &ast.Arithmetic{
   574  				Op:    parserDollar[2].token.Value.(ast.ArithmeticOp),
   575  				Exprs: []ast.Node{parserDollar[1].node, parserDollar[3].node},
   576  				Posx:  parserDollar[1].node.Pos(),
   577  			}
   578  		}
   579  	case 13:
   580  		parserDollar = parserS[parserpt-1 : parserpt+1]
   581  		//line lang.y:134
   582  		{
   583  			parserVAL.node = &ast.VariableAccess{Name: parserDollar[1].token.Value.(string), Posx: parserDollar[1].token.Pos}
   584  		}
   585  	case 14:
   586  		parserDollar = parserS[parserpt-4 : parserpt+1]
   587  		//line lang.y:138
   588  		{
   589  			parserVAL.node = &ast.Call{Func: parserDollar[1].token.Value.(string), Args: parserDollar[3].nodeList, Posx: parserDollar[1].token.Pos}
   590  		}
   591  	case 15:
   592  		parserDollar = parserS[parserpt-0 : parserpt+1]
   593  		//line lang.y:143
   594  		{
   595  			parserVAL.nodeList = nil
   596  		}
   597  	case 16:
   598  		parserDollar = parserS[parserpt-3 : parserpt+1]
   599  		//line lang.y:147
   600  		{
   601  			parserVAL.nodeList = append(parserDollar[1].nodeList, parserDollar[3].node)
   602  		}
   603  	case 17:
   604  		parserDollar = parserS[parserpt-1 : parserpt+1]
   605  		//line lang.y:151
   606  		{
   607  			parserVAL.nodeList = append(parserVAL.nodeList, parserDollar[1].node)
   608  		}
   609  	case 18:
   610  		parserDollar = parserS[parserpt-1 : parserpt+1]
   611  		//line lang.y:157
   612  		{
   613  			parserVAL.node = &ast.LiteralNode{
   614  				Value: parserDollar[1].token.Value.(string),
   615  				Typex: ast.TypeString,
   616  				Posx:  parserDollar[1].token.Pos,
   617  			}
   618  		}
   619  	}
   620  	goto parserstack /* stack new state and value */
   621  }