Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
loki/pkg/logql/expr.y.go

568 lines
12 KiB

// Code generated by goyacc -p expr -o pkg/logql/expr.y.go pkg/logql/expr.y. DO NOT EDIT.
//line pkg/logql/expr.y:2
package logql
import __yyfmt__ "fmt"
//line pkg/logql/expr.y:2
import (
"github.com/prometheus/prometheus/pkg/labels"
)
//line pkg/logql/expr.y:9
type exprSymType struct {
yys int
Expr Expr
Filter labels.MatchType
Selector []*labels.Matcher
Matchers []*labels.Matcher
Matcher *labels.Matcher
str string
int int64
}
const IDENTIFIER = 57346
const STRING = 57347
const MATCHERS = 57348
const LABELS = 57349
const EQ = 57350
const NEQ = 57351
const RE = 57352
const NRE = 57353
const OPEN_BRACE = 57354
const CLOSE_BRACE = 57355
const COMMA = 57356
const DOT = 57357
const PIPE_MATCH = 57358
const PIPE_EXACT = 57359
var exprToknames = [...]string{
"$end",
"error",
"$unk",
"IDENTIFIER",
"STRING",
"MATCHERS",
"LABELS",
"EQ",
"NEQ",
"RE",
"NRE",
"OPEN_BRACE",
"CLOSE_BRACE",
"COMMA",
"DOT",
"PIPE_MATCH",
"PIPE_EXACT",
}
var exprStatenames = [...]string{}
const exprEofCode = 1
const exprErrCode = 2
const exprInitialStackSize = 16
//line pkg/logql/expr.y:65
//line yacctab:1
var exprExca = [...]int{
-1, 1,
1, -1,
-2, 0,
-1, 2,
1, 1,
-2, 0,
}
const exprPrivate = 57344
const exprLast = 30
var exprAct = [...]int{
6, 13, 20, 4, 29, 18, 28, 10, 14, 9,
21, 22, 23, 24, 7, 8, 17, 19, 27, 16,
26, 25, 15, 12, 11, 14, 3, 5, 2, 1,
}
var exprPact = [...]int{
-9, -1000, -2, -1000, 21, 17, -1000, -1000, -1000, -1000,
-1000, 3, -11, -1000, 2, -1000, -1000, -1000, -1000, 4,
-1000, 15, 13, 1, -1, -1000, -1000, -1000, -1000, -1000,
}
var exprPgo = [...]int{
0, 29, 28, 27, 26, 24, 1,
}
var exprR1 = [...]int{
0, 1, 2, 2, 2, 2, 3, 3, 3, 3,
4, 4, 4, 5, 5, 6, 6, 6, 6,
}
var exprR2 = [...]int{
0, 1, 1, 3, 3, 2, 1, 1, 1, 1,
3, 3, 3, 1, 3, 3, 3, 3, 3,
}
var exprChk = [...]int{
-1000, -1, -2, -4, 12, -3, 2, 16, 17, 11,
9, -5, 2, -6, 4, 5, 2, 13, 2, 14,
13, 8, 9, 10, 11, -6, 5, 5, 5, 5,
}
var exprDef = [...]int{
0, -2, -2, 2, 0, 0, 5, 6, 7, 8,
9, 0, 0, 13, 0, 3, 4, 10, 11, 0,
12, 0, 0, 0, 0, 14, 15, 16, 17, 18,
}
var exprTok1 = [...]int{
1,
}
var exprTok2 = [...]int{
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17,
}
var exprTok3 = [...]int{
0,
}
var exprErrorMessages = [...]struct {
state int
token int
msg string
}{}
//line yaccpar:1
/* parser for yacc output */
var (
exprDebug = 0
exprErrorVerbose = false
)
type exprLexer interface {
Lex(lval *exprSymType) int
Error(s string)
}
type exprParser interface {
Parse(exprLexer) int
Lookahead() int
}
type exprParserImpl struct {
lval exprSymType
stack [exprInitialStackSize]exprSymType
char int
}
func (p *exprParserImpl) Lookahead() int {
return p.char
}
func exprNewParser() exprParser {
return &exprParserImpl{}
}
const exprFlag = -1000
func exprTokname(c int) string {
if c >= 1 && c-1 < len(exprToknames) {
if exprToknames[c-1] != "" {
return exprToknames[c-1]
}
}
return __yyfmt__.Sprintf("tok-%v", c)
}
func exprStatname(s int) string {
if s >= 0 && s < len(exprStatenames) {
if exprStatenames[s] != "" {
return exprStatenames[s]
}
}
return __yyfmt__.Sprintf("state-%v", s)
}
func exprErrorMessage(state, lookAhead int) string {
const TOKSTART = 4
if !exprErrorVerbose {
return "syntax error"
}
for _, e := range exprErrorMessages {
if e.state == state && e.token == lookAhead {
return "syntax error: " + e.msg
}
}
res := "syntax error: unexpected " + exprTokname(lookAhead)
// To match Bison, suggest at most four expected tokens.
expected := make([]int, 0, 4)
// Look for shiftable tokens.
base := exprPact[state]
for tok := TOKSTART; tok-1 < len(exprToknames); tok++ {
if n := base + tok; n >= 0 && n < exprLast && exprChk[exprAct[n]] == tok {
if len(expected) == cap(expected) {
return res
}
expected = append(expected, tok)
}
}
if exprDef[state] == -2 {
i := 0
for exprExca[i] != -1 || exprExca[i+1] != state {
i += 2
}
// Look for tokens that we accept or reduce.
for i += 2; exprExca[i] >= 0; i += 2 {
tok := exprExca[i]
if tok < TOKSTART || exprExca[i+1] == 0 {
continue
}
if len(expected) == cap(expected) {
return res
}
expected = append(expected, tok)
}
// If the default action is to accept or reduce, give up.
if exprExca[i+1] != 0 {
return res
}
}
for i, tok := range expected {
if i == 0 {
res += ", expecting "
} else {
res += " or "
}
res += exprTokname(tok)
}
return res
}
func exprlex1(lex exprLexer, lval *exprSymType) (char, token int) {
token = 0
char = lex.Lex(lval)
if char <= 0 {
token = exprTok1[0]
goto out
}
if char < len(exprTok1) {
token = exprTok1[char]
goto out
}
if char >= exprPrivate {
if char < exprPrivate+len(exprTok2) {
token = exprTok2[char-exprPrivate]
goto out
}
}
for i := 0; i < len(exprTok3); i += 2 {
token = exprTok3[i+0]
if token == char {
token = exprTok3[i+1]
goto out
}
}
out:
if token == 0 {
token = exprTok2[1] /* unknown char */
}
if exprDebug >= 3 {
__yyfmt__.Printf("lex %s(%d)\n", exprTokname(token), uint(char))
}
return char, token
}
func exprParse(exprlex exprLexer) int {
return exprNewParser().Parse(exprlex)
}
func (exprrcvr *exprParserImpl) Parse(exprlex exprLexer) int {
var exprn int
var exprVAL exprSymType
var exprDollar []exprSymType
_ = exprDollar // silence set and not used
exprS := exprrcvr.stack[:]
Nerrs := 0 /* number of errors */
Errflag := 0 /* error recovery flag */
exprstate := 0
exprrcvr.char = -1
exprtoken := -1 // exprrcvr.char translated into internal numbering
defer func() {
// Make sure we report no lookahead when not parsing.
exprstate = -1
exprrcvr.char = -1
exprtoken = -1
}()
exprp := -1
goto exprstack
ret0:
return 0
ret1:
return 1
exprstack:
/* put a state and value onto the stack */
if exprDebug >= 4 {
__yyfmt__.Printf("char %v in %v\n", exprTokname(exprtoken), exprStatname(exprstate))
}
exprp++
if exprp >= len(exprS) {
nyys := make([]exprSymType, len(exprS)*2)
copy(nyys, exprS)
exprS = nyys
}
exprS[exprp] = exprVAL
exprS[exprp].yys = exprstate
exprnewstate:
exprn = exprPact[exprstate]
if exprn <= exprFlag {
goto exprdefault /* simple state */
}
if exprrcvr.char < 0 {
exprrcvr.char, exprtoken = exprlex1(exprlex, &exprrcvr.lval)
}
exprn += exprtoken
if exprn < 0 || exprn >= exprLast {
goto exprdefault
}
exprn = exprAct[exprn]
if exprChk[exprn] == exprtoken { /* valid shift */
exprrcvr.char = -1
exprtoken = -1
exprVAL = exprrcvr.lval
exprstate = exprn
if Errflag > 0 {
Errflag--
}
goto exprstack
}
exprdefault:
/* default state action */
exprn = exprDef[exprstate]
if exprn == -2 {
if exprrcvr.char < 0 {
exprrcvr.char, exprtoken = exprlex1(exprlex, &exprrcvr.lval)
}
/* look through exception table */
xi := 0
for {
if exprExca[xi+0] == -1 && exprExca[xi+1] == exprstate {
break
}
xi += 2
}
for xi += 2; ; xi += 2 {
exprn = exprExca[xi+0]
if exprn < 0 || exprn == exprtoken {
break
}
}
exprn = exprExca[xi+1]
if exprn < 0 {
goto ret0
}
}
if exprn == 0 {
/* error ... attempt to resume parsing */
switch Errflag {
case 0: /* brand new error */
exprlex.Error(exprErrorMessage(exprstate, exprtoken))
Nerrs++
if exprDebug >= 1 {
__yyfmt__.Printf("%s", exprStatname(exprstate))
__yyfmt__.Printf(" saw %s\n", exprTokname(exprtoken))
}
fallthrough
case 1, 2: /* incompletely recovered error ... try again */
Errflag = 3
/* find a state where "error" is a legal shift action */
for exprp >= 0 {
exprn = exprPact[exprS[exprp].yys] + exprErrCode
if exprn >= 0 && exprn < exprLast {
exprstate = exprAct[exprn] /* simulate a shift of "error" */
if exprChk[exprstate] == exprErrCode {
goto exprstack
}
}
/* the current p has no shift on "error", pop stack */
if exprDebug >= 2 {
__yyfmt__.Printf("error recovery pops state %d\n", exprS[exprp].yys)
}
exprp--
}
/* there is no state on the stack with an error shift ... abort */
goto ret1
case 3: /* no shift yet; clobber input char */
if exprDebug >= 2 {
__yyfmt__.Printf("error recovery discards %s\n", exprTokname(exprtoken))
}
if exprtoken == exprEofCode {
goto ret1
}
exprrcvr.char = -1
exprtoken = -1
goto exprnewstate /* try again in the same state */
}
}
/* reduction by production exprn */
if exprDebug >= 2 {
__yyfmt__.Printf("reduce %v in:\n\t%v\n", exprn, exprStatname(exprstate))
}
exprnt := exprn
exprpt := exprp
_ = exprpt // guard against "declared and not used"
exprp -= exprR2[exprn]
// exprp is now the index of $0. Perform the default action. Iff the
// reduced production is ε, $1 is possibly out of range.
if exprp+1 >= len(exprS) {
nyys := make([]exprSymType, len(exprS)*2)
copy(nyys, exprS)
exprS = nyys
}
exprVAL = exprS[exprp+1]
/* consult goto table to find next state */
exprn = exprR1[exprn]
exprg := exprPgo[exprn]
exprj := exprg + exprS[exprp].yys + 1
if exprj >= exprLast {
exprstate = exprAct[exprg]
} else {
exprstate = exprAct[exprj]
if exprChk[exprstate] != -exprn {
exprstate = exprAct[exprg]
}
}
// dummy call; replaced with literal code
switch exprnt {
case 1:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:32
{
exprlex.(*lexer).expr = exprDollar[1].Expr
}
case 2:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:35
{
exprVAL.Expr = &matchersExpr{matchers: exprDollar[1].Selector}
}
case 3:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:36
{
exprVAL.Expr = NewFilterExpr(exprDollar[1].Expr, exprDollar[2].Filter, exprDollar[3].str)
}
case 6:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:42
{
exprVAL.Filter = labels.MatchRegexp
}
case 7:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:43
{
exprVAL.Filter = labels.MatchEqual
}
case 8:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:44
{
exprVAL.Filter = labels.MatchNotRegexp
}
case 9:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:45
{
exprVAL.Filter = labels.MatchNotEqual
}
case 10:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:49
{
exprVAL.Selector = exprDollar[2].Matchers
}
case 11:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:50
{
exprVAL.Selector = exprDollar[2].Matchers
}
case 12:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:51
{
}
case 13:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:55
{
exprVAL.Matchers = []*labels.Matcher{exprDollar[1].Matcher}
}
case 14:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:56
{
exprVAL.Matchers = append(exprDollar[1].Matchers, exprDollar[3].Matcher)
}
case 15:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:60
{
exprVAL.Matcher = mustNewMatcher(labels.MatchEqual, exprDollar[1].str, exprDollar[3].str)
}
case 16:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:61
{
exprVAL.Matcher = mustNewMatcher(labels.MatchNotEqual, exprDollar[1].str, exprDollar[3].str)
}
case 17:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:62
{
exprVAL.Matcher = mustNewMatcher(labels.MatchRegexp, exprDollar[1].str, exprDollar[3].str)
}
case 18:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:63
{
exprVAL.Matcher = mustNewMatcher(labels.MatchNotRegexp, exprDollar[1].str, exprDollar[3].str)
}
}
goto exprstack /* stack new state and value */
}