MCPcopy
hub / github.com/grafana/tempo / yyErrorMessage

Function yyErrorMessage

pkg/traceql/expr.y.go:704–766  ·  view source on GitHub ↗
(state, lookAhead int)

Source from the content-addressed store, hash-verified

702}
703
704func yyErrorMessage(state, lookAhead int) string {
705 const TOKSTART = 4
706
707 if !yyErrorVerbose {
708 return "syntax error"
709 }
710
711 for _, e := range yyErrorMessages {
712 if e.state == state && e.token == lookAhead {
713 return "syntax error: " + e.msg
714 }
715 }
716
717 res := "syntax error: unexpected " + yyTokname(lookAhead)
718
719 // To match Bison, suggest at most four expected tokens.
720 expected := make([]int, 0, 4)
721
722 // Look for shiftable tokens.
723 base := int(yyPact[state])
724 for tok := TOKSTART; tok-1 < len(yyToknames); tok++ {
725 if n := base + tok; n >= 0 && n < yyLast && int(yyChk[int(yyAct[n])]) == tok {
726 if len(expected) == cap(expected) {
727 return res
728 }
729 expected = append(expected, tok)
730 }
731 }
732
733 if yyDef[state] == -2 {
734 i := 0
735 for yyExca[i] != -1 || int(yyExca[i+1]) != state {
736 i += 2
737 }
738
739 // Look for tokens that we accept or reduce.
740 for i += 2; yyExca[i] >= 0; i += 2 {
741 tok := int(yyExca[i])
742 if tok < TOKSTART || yyExca[i+1] == 0 {
743 continue
744 }
745 if len(expected) == cap(expected) {
746 return res
747 }
748 expected = append(expected, tok)
749 }
750
751 // If the default action is to accept or reduce, give up.
752 if yyExca[i+1] != 0 {
753 return res
754 }
755 }
756
757 for i, tok := range expected {
758 if i == 0 {
759 res += ", expecting "
760 } else {
761 res += " or "

Callers 1

ParseMethod · 0.85

Calls 1

yyToknameFunction · 0.85

Tested by

no test coverage detected