mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
Fix state cleanup bug between rule/config parser runs.
This fixes a bug that has been annoying me minorly for some time now: sometimes, after parse errors, a subsequent parser run would fail. The reason is that yylex() modifies some global variables (yytext, yydata) during its run to keep state. To make subsequent parser runs correct, these have to be reset before each run. Also, close files after reading them.
This commit is contained in:
parent
ab746d068e
commit
cb6eb30182
|
@ -35,6 +35,8 @@ func LoadFromReader(configReader io.Reader) (*Config, error) {
|
|||
yyin = configReader
|
||||
yypos = 1
|
||||
yyline = 1
|
||||
yydata = ""
|
||||
yytext = ""
|
||||
|
||||
lexer := &ConfigLexer{}
|
||||
yyParse(lexer)
|
||||
|
@ -54,6 +56,7 @@ func LoadFromString(configString string) (*Config, error) {
|
|||
|
||||
func LoadFromFile(fileName string) (*Config, error) {
|
||||
configReader, err := os.Open(fileName)
|
||||
defer configReader.Close()
|
||||
if err != nil {
|
||||
return &Config{}, err
|
||||
}
|
||||
|
|
|
@ -48,9 +48,10 @@ func LoadFromReader(rulesReader io.Reader, singleExpr bool) (interface{}, error)
|
|||
yyin = rulesReader
|
||||
yypos = 1
|
||||
yyline = 1
|
||||
yydata = ""
|
||||
yytext = ""
|
||||
|
||||
lexer := &RulesLexer{
|
||||
parsedRules: []*Rule{},
|
||||
startToken: START_RULES,
|
||||
}
|
||||
|
||||
|
@ -91,6 +92,7 @@ func LoadRulesFromString(rulesString string) ([]*Rule, error) {
|
|||
|
||||
func LoadRulesFromFile(fileName string) ([]*Rule, error) {
|
||||
rulesReader, err := os.Open(fileName)
|
||||
defer rulesReader.Close()
|
||||
if err != nil {
|
||||
return []*Rule{}, err
|
||||
}
|
||||
|
@ -112,6 +114,7 @@ func LoadExprFromString(exprString string) (ast.Node, error) {
|
|||
|
||||
func LoadExprFromFile(fileName string) (ast.Node, error) {
|
||||
exprReader, err := os.Open(fileName)
|
||||
defer exprReader.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue