Cleanup: Remove parser switching logic (#6583)
During the PromQL parser rewrite there was some logic put in place that allowed switching between the non generated and the generated parser. Since the parser is now fully generated this is not needed anymore. Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
This commit is contained in:
parent
2064abab40
commit
4aef43a9f5
|
@ -35,8 +35,6 @@ type parser struct {
|
|||
inject Item
|
||||
injecting bool
|
||||
|
||||
switchSymbols []ItemType
|
||||
|
||||
generatedParserResult interface{}
|
||||
}
|
||||
|
||||
|
@ -58,7 +56,7 @@ func ParseExpr(input string) (expr Expr, err error) {
|
|||
|
||||
defer p.recover(&err)
|
||||
|
||||
expr = p.parseGenerated(START_EXPRESSION, []ItemType{EOF}).(Expr)
|
||||
expr = p.parseGenerated(START_EXPRESSION).(Expr)
|
||||
err = p.typecheck(expr)
|
||||
|
||||
return expr, err
|
||||
|
@ -69,7 +67,7 @@ func ParseMetric(input string) (m labels.Labels, err error) {
|
|||
p := newParser(input)
|
||||
defer p.recover(&err)
|
||||
|
||||
return p.parseGenerated(START_METRIC, []ItemType{EOF}).(labels.Labels), nil
|
||||
return p.parseGenerated(START_METRIC).(labels.Labels), nil
|
||||
}
|
||||
|
||||
// ParseMetricSelector parses the provided textual metric selector into a list of
|
||||
|
@ -78,7 +76,7 @@ func ParseMetricSelector(input string) (m []*labels.Matcher, err error) {
|
|||
p := newParser(input)
|
||||
defer p.recover(&err)
|
||||
|
||||
return p.parseGenerated(START_METRIC_SELECTOR, []ItemType{EOF}).(*VectorSelector).LabelMatchers, nil
|
||||
return p.parseGenerated(START_METRIC_SELECTOR).(*VectorSelector).LabelMatchers, nil
|
||||
}
|
||||
|
||||
// newParser returns a new parser.
|
||||
|
@ -115,7 +113,7 @@ func parseSeriesDesc(input string) (labels labels.Labels, values []sequenceValue
|
|||
|
||||
defer p.recover(&err)
|
||||
|
||||
result := p.parseGenerated(START_SERIES_DESCRIPTION, []ItemType{EOF}).(*seriesDescription)
|
||||
result := p.parseGenerated(START_SERIES_DESCRIPTION).(*seriesDescription)
|
||||
|
||||
labels = result.labels
|
||||
values = result.values
|
||||
|
@ -222,10 +220,8 @@ func (p *parser) Lex(lval *yySymType) int {
|
|||
|
||||
typ := lval.item.Typ
|
||||
|
||||
for _, t := range p.switchSymbols {
|
||||
if t == typ {
|
||||
p.InjectItem(0)
|
||||
}
|
||||
if typ == EOF {
|
||||
p.InjectItem(0)
|
||||
}
|
||||
|
||||
return int(typ)
|
||||
|
@ -526,15 +522,9 @@ func parseDuration(ds string) (time.Duration, error) {
|
|||
// parseGenerated invokes the yacc generated parser.
|
||||
// The generated parser gets the provided startSymbol injected into
|
||||
// the lexer stream, based on which grammar will be used.
|
||||
//
|
||||
// The generated parser will consume the lexer Stream until one of the
|
||||
// tokens listed in switchSymbols is encountered. switchSymbols
|
||||
// should at least contain EOF
|
||||
func (p *parser) parseGenerated(startSymbol ItemType, switchSymbols []ItemType) interface{} {
|
||||
func (p *parser) parseGenerated(startSymbol ItemType) interface{} {
|
||||
p.InjectItem(startSymbol)
|
||||
|
||||
p.switchSymbols = switchSymbols
|
||||
|
||||
yyParse(p)
|
||||
|
||||
return p.generatedParserResult
|
||||
|
|
Loading…
Reference in New Issue