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.go

564 lines
12 KiB

// Code generated by goyacc -p expr -o pkg/logql/expr.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
Matchers []*labels.Matcher
Matcher *labels.Matcher
str string
int int64
Identifier string
}
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:58
//line yacctab:1
var exprExca = [...]int{
-1, 1,
1, -1,
-2, 0,
}
const exprPrivate = 57344
const exprLast = 29
var exprAct = [...]int{
8, 10, 17, 18, 7, 3, 6, 19, 20, 21,
22, 4, 5, 28, 23, 27, 26, 25, 16, 15,
24, 14, 13, 29, 12, 11, 9, 2, 1,
}
var exprPact = [...]int{
-7, -1000, -5, 20, 17, 16, 14, 13, -1000, -11,
-1000, -1, -1000, -1000, -1000, -1000, -1000, -1000, 20, 12,
11, 10, 8, 19, -1000, -1000, -1000, -1000, -1000, -1000,
}
var exprPgo = [...]int{
0, 28, 27, 26, 1, 25,
}
var exprR1 = [...]int{
0, 1, 2, 2, 2, 2, 2, 2, 2, 3,
3, 4, 4, 4, 4, 5, 5,
}
var exprR2 = [...]int{
0, 1, 3, 3, 3, 3, 3, 2, 2, 1,
3, 3, 3, 3, 3, 1, 3,
}
var exprChk = [...]int{
-1000, -1, -2, 12, 16, 17, 11, 9, 5, -3,
-4, -5, 4, 5, 5, 5, 5, 13, 14, 8,
9, 10, 11, 15, -4, 5, 5, 5, 5, 4,
}
var exprDef = [...]int{
0, -2, 1, 0, 7, 0, 0, 0, 8, 0,
9, 0, 15, 3, 4, 5, 6, 2, 0, 0,
0, 0, 0, 0, 10, 11, 12, 13, 14, 16,
}
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:30
{
exprlex.(*lexer).expr = exprDollar[1].Expr
}
case 2:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:33
{
exprVAL.Expr = &matchersExpr{matchers: exprDollar[2].Matchers}
}
case 3:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:34
{
exprVAL.Expr = &matchExpr{exprDollar[1].Expr, labels.MatchRegexp, exprDollar[3].str}
}
case 4:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:35
{
exprVAL.Expr = &matchExpr{exprDollar[1].Expr, labels.MatchEqual, exprDollar[3].str}
}
case 5:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:36
{
exprVAL.Expr = &matchExpr{exprDollar[1].Expr, labels.MatchNotRegexp, exprDollar[3].str}
}
case 6:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:37
{
exprVAL.Expr = &matchExpr{exprDollar[1].Expr, labels.MatchNotEqual, exprDollar[3].str}
}
case 7:
exprDollar = exprS[exprpt-2 : exprpt+1]
//line pkg/logql/expr.y:38
{
exprlex.(*lexer).Error("unexpected end of query, expected string")
}
case 8:
exprDollar = exprS[exprpt-2 : exprpt+1]
//line pkg/logql/expr.y:39
{
exprlex.(*lexer).Error("unexpected string, expected pipe")
}
case 9:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:43
{
exprVAL.Matchers = []*labels.Matcher{exprDollar[1].Matcher}
}
case 10:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:44
{
exprVAL.Matchers = append(exprDollar[1].Matchers, exprDollar[3].Matcher)
}
case 11:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:48
{
exprVAL.Matcher = mustNewMatcher(labels.MatchEqual, exprDollar[1].Identifier, exprDollar[3].str)
}
case 12:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:49
{
exprVAL.Matcher = mustNewMatcher(labels.MatchNotEqual, exprDollar[1].Identifier, exprDollar[3].str)
}
case 13:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:50
{
exprVAL.Matcher = mustNewMatcher(labels.MatchRegexp, exprDollar[1].Identifier, exprDollar[3].str)
}
case 14:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:51
{
exprVAL.Matcher = mustNewMatcher(labels.MatchNotRegexp, exprDollar[1].Identifier, exprDollar[3].str)
}
case 15:
exprDollar = exprS[exprpt-1 : exprpt+1]
//line pkg/logql/expr.y:55
{
exprVAL.Identifier = exprDollar[1].str
}
case 16:
exprDollar = exprS[exprpt-3 : exprpt+1]
//line pkg/logql/expr.y:56
{
exprVAL.Identifier = exprDollar[1].Identifier + "." + exprDollar[3].str
}
}
goto exprstack /* stack new state and value */
}