github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/logentry/logql/expr.y.go (about)

     1  // Code generated by goyacc -p expr -o clients/pkg/logentry/logql/expr.y.go clients/pkg/logentry/logql/expr.y. DO NOT EDIT.
     2  
     3  package logql
     4  
     5  import __yyfmt__ "fmt"
     6  
     7  import (
     8  	"github.com/prometheus/prometheus/model/labels"
     9  )
    10  
    11  type exprSymType struct {
    12  	yys      int
    13  	Expr     Expr
    14  	Filter   labels.MatchType
    15  	Selector []*labels.Matcher
    16  	Matchers []*labels.Matcher
    17  	Matcher  *labels.Matcher
    18  	str      string
    19  	int      int64
    20  }
    21  
    22  const IDENTIFIER = 57346
    23  const STRING = 57347
    24  const MATCHERS = 57348
    25  const LABELS = 57349
    26  const EQ = 57350
    27  const NEQ = 57351
    28  const RE = 57352
    29  const NRE = 57353
    30  const OPEN_BRACE = 57354
    31  const CLOSE_BRACE = 57355
    32  const COMMA = 57356
    33  const DOT = 57357
    34  const PIPE_MATCH = 57358
    35  const PIPE_EXACT = 57359
    36  
    37  var exprToknames = [...]string{
    38  	"$end",
    39  	"error",
    40  	"$unk",
    41  	"IDENTIFIER",
    42  	"STRING",
    43  	"MATCHERS",
    44  	"LABELS",
    45  	"EQ",
    46  	"NEQ",
    47  	"RE",
    48  	"NRE",
    49  	"OPEN_BRACE",
    50  	"CLOSE_BRACE",
    51  	"COMMA",
    52  	"DOT",
    53  	"PIPE_MATCH",
    54  	"PIPE_EXACT",
    55  }
    56  var exprStatenames = [...]string{}
    57  
    58  const exprEofCode = 1
    59  const exprErrCode = 2
    60  const exprInitialStackSize = 16
    61  
    62  var exprExca = [...]int{
    63  	-1, 1,
    64  	1, -1,
    65  	-2, 0,
    66  	-1, 2,
    67  	1, 1,
    68  	-2, 0,
    69  }
    70  
    71  const exprPrivate = 57344
    72  
    73  const exprLast = 30
    74  
    75  var exprAct = [...]int{
    76  
    77  	6, 13, 20, 4, 29, 18, 28, 10, 14, 9,
    78  	21, 22, 23, 24, 7, 8, 17, 19, 27, 16,
    79  	26, 25, 15, 12, 11, 14, 3, 5, 2, 1,
    80  }
    81  var exprPact = [...]int{
    82  
    83  	-9, -1000, -2, -1000, 21, 17, -1000, -1000, -1000, -1000,
    84  	-1000, 3, -11, -1000, 2, -1000, -1000, -1000, -1000, 4,
    85  	-1000, 15, 13, 1, -1, -1000, -1000, -1000, -1000, -1000,
    86  }
    87  var exprPgo = [...]int{
    88  
    89  	0, 29, 28, 27, 26, 24, 1,
    90  }
    91  var exprR1 = [...]int{
    92  
    93  	0, 1, 2, 2, 2, 2, 3, 3, 3, 3,
    94  	4, 4, 4, 5, 5, 6, 6, 6, 6,
    95  }
    96  var exprR2 = [...]int{
    97  
    98  	0, 1, 1, 3, 3, 2, 1, 1, 1, 1,
    99  	3, 3, 3, 1, 3, 3, 3, 3, 3,
   100  }
   101  var exprChk = [...]int{
   102  
   103  	-1000, -1, -2, -4, 12, -3, 2, 16, 17, 11,
   104  	9, -5, 2, -6, 4, 5, 2, 13, 2, 14,
   105  	13, 8, 9, 10, 11, -6, 5, 5, 5, 5,
   106  }
   107  var exprDef = [...]int{
   108  
   109  	0, -2, -2, 2, 0, 0, 5, 6, 7, 8,
   110  	9, 0, 0, 13, 0, 3, 4, 10, 11, 0,
   111  	12, 0, 0, 0, 0, 14, 15, 16, 17, 18,
   112  }
   113  var exprTok1 = [...]int{
   114  
   115  	1,
   116  }
   117  var exprTok2 = [...]int{
   118  
   119  	2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
   120  	12, 13, 14, 15, 16, 17,
   121  }
   122  var exprTok3 = [...]int{
   123  	0,
   124  }
   125  
   126  var exprErrorMessages = [...]struct {
   127  	state int
   128  	token int
   129  	msg   string
   130  }{}
   131  
   132  /*	parser for yacc output	*/
   133  
   134  var (
   135  	exprDebug        = 0
   136  	exprErrorVerbose = false
   137  )
   138  
   139  type exprLexer interface {
   140  	Lex(lval *exprSymType) int
   141  	Error(s string)
   142  }
   143  
   144  type exprParser interface {
   145  	Parse(exprLexer) int
   146  	Lookahead() int
   147  }
   148  
   149  type exprParserImpl struct {
   150  	lval  exprSymType
   151  	stack [exprInitialStackSize]exprSymType
   152  	char  int
   153  }
   154  
   155  func (p *exprParserImpl) Lookahead() int {
   156  	return p.char
   157  }
   158  
   159  func exprNewParser() exprParser {
   160  	return &exprParserImpl{}
   161  }
   162  
   163  const exprFlag = -1000
   164  
   165  func exprTokname(c int) string {
   166  	if c >= 1 && c-1 < len(exprToknames) {
   167  		if exprToknames[c-1] != "" {
   168  			return exprToknames[c-1]
   169  		}
   170  	}
   171  	return __yyfmt__.Sprintf("tok-%v", c)
   172  }
   173  
   174  func exprStatname(s int) string {
   175  	if s >= 0 && s < len(exprStatenames) {
   176  		if exprStatenames[s] != "" {
   177  			return exprStatenames[s]
   178  		}
   179  	}
   180  	return __yyfmt__.Sprintf("state-%v", s)
   181  }
   182  
   183  func exprErrorMessage(state, lookAhead int) string {
   184  	const TOKSTART = 4
   185  
   186  	if !exprErrorVerbose {
   187  		return "syntax error"
   188  	}
   189  
   190  	for _, e := range exprErrorMessages {
   191  		if e.state == state && e.token == lookAhead {
   192  			return "syntax error: " + e.msg
   193  		}
   194  	}
   195  
   196  	res := "syntax error: unexpected " + exprTokname(lookAhead)
   197  
   198  	// To match Bison, suggest at most four expected tokens.
   199  	expected := make([]int, 0, 4)
   200  
   201  	// Look for shiftable tokens.
   202  	base := exprPact[state]
   203  	for tok := TOKSTART; tok-1 < len(exprToknames); tok++ {
   204  		if n := base + tok; n >= 0 && n < exprLast && exprChk[exprAct[n]] == tok {
   205  			if len(expected) == cap(expected) {
   206  				return res
   207  			}
   208  			expected = append(expected, tok)
   209  		}
   210  	}
   211  
   212  	if exprDef[state] == -2 {
   213  		i := 0
   214  		for exprExca[i] != -1 || exprExca[i+1] != state {
   215  			i += 2
   216  		}
   217  
   218  		// Look for tokens that we accept or reduce.
   219  		for i += 2; exprExca[i] >= 0; i += 2 {
   220  			tok := exprExca[i]
   221  			if tok < TOKSTART || exprExca[i+1] == 0 {
   222  				continue
   223  			}
   224  			if len(expected) == cap(expected) {
   225  				return res
   226  			}
   227  			expected = append(expected, tok)
   228  		}
   229  
   230  		// If the default action is to accept or reduce, give up.
   231  		if exprExca[i+1] != 0 {
   232  			return res
   233  		}
   234  	}
   235  
   236  	for i, tok := range expected {
   237  		if i == 0 {
   238  			res += ", expecting "
   239  		} else {
   240  			res += " or "
   241  		}
   242  		res += exprTokname(tok)
   243  	}
   244  	return res
   245  }
   246  
   247  func exprlex1(lex exprLexer, lval *exprSymType) (char, token int) {
   248  	token = 0
   249  	char = lex.Lex(lval)
   250  	if char <= 0 {
   251  		token = exprTok1[0]
   252  		goto out
   253  	}
   254  	if char < len(exprTok1) {
   255  		token = exprTok1[char]
   256  		goto out
   257  	}
   258  	if char >= exprPrivate {
   259  		if char < exprPrivate+len(exprTok2) {
   260  			token = exprTok2[char-exprPrivate]
   261  			goto out
   262  		}
   263  	}
   264  	for i := 0; i < len(exprTok3); i += 2 {
   265  		token = exprTok3[i+0]
   266  		if token == char {
   267  			token = exprTok3[i+1]
   268  			goto out
   269  		}
   270  	}
   271  
   272  out:
   273  	if token == 0 {
   274  		token = exprTok2[1] /* unknown char */
   275  	}
   276  	if exprDebug >= 3 {
   277  		__yyfmt__.Printf("lex %s(%d)\n", exprTokname(token), uint(char))
   278  	}
   279  	return char, token
   280  }
   281  
   282  func exprParse(exprlex exprLexer) int {
   283  	return exprNewParser().Parse(exprlex)
   284  }
   285  
   286  func (exprrcvr *exprParserImpl) Parse(exprlex exprLexer) int {
   287  	var exprn int
   288  	var exprVAL exprSymType
   289  	var exprDollar []exprSymType
   290  	_ = exprDollar // silence set and not used
   291  	exprS := exprrcvr.stack[:]
   292  
   293  	Nerrs := 0   /* number of errors */
   294  	Errflag := 0 /* error recovery flag */
   295  	exprstate := 0
   296  	exprrcvr.char = -1
   297  	exprtoken := -1 // exprrcvr.char translated into internal numbering
   298  	defer func() {
   299  		// Make sure we report no lookahead when not parsing.
   300  		exprstate = -1
   301  		exprrcvr.char = -1
   302  		exprtoken = -1
   303  	}()
   304  	exprp := -1
   305  	goto exprstack
   306  
   307  ret0:
   308  	return 0
   309  
   310  ret1:
   311  	return 1
   312  
   313  exprstack:
   314  	/* put a state and value onto the stack */
   315  	if exprDebug >= 4 {
   316  		__yyfmt__.Printf("char %v in %v\n", exprTokname(exprtoken), exprStatname(exprstate))
   317  	}
   318  
   319  	exprp++
   320  	if exprp >= len(exprS) {
   321  		nyys := make([]exprSymType, len(exprS)*2)
   322  		copy(nyys, exprS)
   323  		exprS = nyys
   324  	}
   325  	exprS[exprp] = exprVAL
   326  	exprS[exprp].yys = exprstate
   327  
   328  exprnewstate:
   329  	exprn = exprPact[exprstate]
   330  	if exprn <= exprFlag {
   331  		goto exprdefault /* simple state */
   332  	}
   333  	if exprrcvr.char < 0 {
   334  		exprrcvr.char, exprtoken = exprlex1(exprlex, &exprrcvr.lval)
   335  	}
   336  	exprn += exprtoken
   337  	if exprn < 0 || exprn >= exprLast {
   338  		goto exprdefault
   339  	}
   340  	exprn = exprAct[exprn]
   341  	if exprChk[exprn] == exprtoken { /* valid shift */
   342  		exprrcvr.char = -1
   343  		exprtoken = -1
   344  		exprVAL = exprrcvr.lval
   345  		exprstate = exprn
   346  		if Errflag > 0 {
   347  			Errflag--
   348  		}
   349  		goto exprstack
   350  	}
   351  
   352  exprdefault:
   353  	/* default state action */
   354  	exprn = exprDef[exprstate]
   355  	if exprn == -2 {
   356  		if exprrcvr.char < 0 {
   357  			exprrcvr.char, exprtoken = exprlex1(exprlex, &exprrcvr.lval)
   358  		}
   359  
   360  		/* look through exception table */
   361  		xi := 0
   362  		for {
   363  			if exprExca[xi+0] == -1 && exprExca[xi+1] == exprstate {
   364  				break
   365  			}
   366  			xi += 2
   367  		}
   368  		for xi += 2; ; xi += 2 {
   369  			exprn = exprExca[xi+0]
   370  			if exprn < 0 || exprn == exprtoken {
   371  				break
   372  			}
   373  		}
   374  		exprn = exprExca[xi+1]
   375  		if exprn < 0 {
   376  			goto ret0
   377  		}
   378  	}
   379  	if exprn == 0 {
   380  		/* error ... attempt to resume parsing */
   381  		switch Errflag {
   382  		case 0: /* brand new error */
   383  			exprlex.Error(exprErrorMessage(exprstate, exprtoken))
   384  			Nerrs++
   385  			if exprDebug >= 1 {
   386  				__yyfmt__.Printf("%s", exprStatname(exprstate))
   387  				__yyfmt__.Printf(" saw %s\n", exprTokname(exprtoken))
   388  			}
   389  			fallthrough
   390  
   391  		case 1, 2: /* incompletely recovered error ... try again */
   392  			Errflag = 3
   393  
   394  			/* find a state where "error" is a legal shift action */
   395  			for exprp >= 0 {
   396  				exprn = exprPact[exprS[exprp].yys] + exprErrCode
   397  				if exprn >= 0 && exprn < exprLast {
   398  					exprstate = exprAct[exprn] /* simulate a shift of "error" */
   399  					if exprChk[exprstate] == exprErrCode {
   400  						goto exprstack
   401  					}
   402  				}
   403  
   404  				/* the current p has no shift on "error", pop stack */
   405  				if exprDebug >= 2 {
   406  					__yyfmt__.Printf("error recovery pops state %d\n", exprS[exprp].yys)
   407  				}
   408  				exprp--
   409  			}
   410  			/* there is no state on the stack with an error shift ... abort */
   411  			goto ret1
   412  
   413  		case 3: /* no shift yet; clobber input char */
   414  			if exprDebug >= 2 {
   415  				__yyfmt__.Printf("error recovery discards %s\n", exprTokname(exprtoken))
   416  			}
   417  			if exprtoken == exprEofCode {
   418  				goto ret1
   419  			}
   420  			exprrcvr.char = -1
   421  			exprtoken = -1
   422  			goto exprnewstate /* try again in the same state */
   423  		}
   424  	}
   425  
   426  	/* reduction by production exprn */
   427  	if exprDebug >= 2 {
   428  		__yyfmt__.Printf("reduce %v in:\n\t%v\n", exprn, exprStatname(exprstate))
   429  	}
   430  
   431  	exprnt := exprn
   432  	exprpt := exprp
   433  	_ = exprpt // guard against "declared and not used"
   434  
   435  	exprp -= exprR2[exprn]
   436  	// exprp is now the index of $0. Perform the default action. Iff the
   437  	// reduced production is ε, $1 is possibly out of range.
   438  	if exprp+1 >= len(exprS) {
   439  		nyys := make([]exprSymType, len(exprS)*2)
   440  		copy(nyys, exprS)
   441  		exprS = nyys
   442  	}
   443  	exprVAL = exprS[exprp+1]
   444  
   445  	/* consult goto table to find next state */
   446  	exprn = exprR1[exprn]
   447  	exprg := exprPgo[exprn]
   448  	exprj := exprg + exprS[exprp].yys + 1
   449  
   450  	if exprj >= exprLast {
   451  		exprstate = exprAct[exprg]
   452  	} else {
   453  		exprstate = exprAct[exprj]
   454  		if exprChk[exprstate] != -exprn {
   455  			exprstate = exprAct[exprg]
   456  		}
   457  	}
   458  	// dummy call; replaced with literal code
   459  	switch exprnt {
   460  
   461  	case 1:
   462  		exprDollar = exprS[exprpt-1 : exprpt+1]
   463  		{
   464  			exprlex.(*lexer).expr = exprDollar[1].Expr
   465  		}
   466  	case 2:
   467  		exprDollar = exprS[exprpt-1 : exprpt+1]
   468  		{
   469  			exprVAL.Expr = &matchersExpr{matchers: exprDollar[1].Selector}
   470  		}
   471  	case 3:
   472  		exprDollar = exprS[exprpt-3 : exprpt+1]
   473  		{
   474  			exprVAL.Expr = NewFilterExpr(exprDollar[1].Expr, exprDollar[2].Filter, exprDollar[3].str)
   475  		}
   476  	case 6:
   477  		exprDollar = exprS[exprpt-1 : exprpt+1]
   478  		{
   479  			exprVAL.Filter = labels.MatchRegexp
   480  		}
   481  	case 7:
   482  		exprDollar = exprS[exprpt-1 : exprpt+1]
   483  		{
   484  			exprVAL.Filter = labels.MatchEqual
   485  		}
   486  	case 8:
   487  		exprDollar = exprS[exprpt-1 : exprpt+1]
   488  		{
   489  			exprVAL.Filter = labels.MatchNotRegexp
   490  		}
   491  	case 9:
   492  		exprDollar = exprS[exprpt-1 : exprpt+1]
   493  		{
   494  			exprVAL.Filter = labels.MatchNotEqual
   495  		}
   496  	case 10:
   497  		exprDollar = exprS[exprpt-3 : exprpt+1]
   498  		{
   499  			exprVAL.Selector = exprDollar[2].Matchers
   500  		}
   501  	case 11:
   502  		exprDollar = exprS[exprpt-3 : exprpt+1]
   503  		{
   504  			exprVAL.Selector = exprDollar[2].Matchers
   505  		}
   506  	case 12:
   507  		exprDollar = exprS[exprpt-3 : exprpt+1]
   508  		{
   509  		}
   510  	case 13:
   511  		exprDollar = exprS[exprpt-1 : exprpt+1]
   512  		{
   513  			exprVAL.Matchers = []*labels.Matcher{exprDollar[1].Matcher}
   514  		}
   515  	case 14:
   516  		exprDollar = exprS[exprpt-3 : exprpt+1]
   517  		{
   518  			exprVAL.Matchers = append(exprDollar[1].Matchers, exprDollar[3].Matcher)
   519  		}
   520  	case 15:
   521  		exprDollar = exprS[exprpt-3 : exprpt+1]
   522  		{
   523  			exprVAL.Matcher = mustNewMatcher(labels.MatchEqual, exprDollar[1].str, exprDollar[3].str)
   524  		}
   525  	case 16:
   526  		exprDollar = exprS[exprpt-3 : exprpt+1]
   527  		{
   528  			exprVAL.Matcher = mustNewMatcher(labels.MatchNotEqual, exprDollar[1].str, exprDollar[3].str)
   529  		}
   530  	case 17:
   531  		exprDollar = exprS[exprpt-3 : exprpt+1]
   532  		{
   533  			exprVAL.Matcher = mustNewMatcher(labels.MatchRegexp, exprDollar[1].str, exprDollar[3].str)
   534  		}
   535  	case 18:
   536  		exprDollar = exprS[exprpt-3 : exprpt+1]
   537  		{
   538  			exprVAL.Matcher = mustNewMatcher(labels.MatchNotRegexp, exprDollar[1].str, exprDollar[3].str)
   539  		}
   540  	}
   541  	goto exprstack /* stack new state and value */
   542  }