parser.go: added recover from panic in parser.Parse()

This commit is contained in:
Celestino Amoroso 2026-05-01 07:23:27 +02:00
parent 610e2df5f5
commit edd90054d7

View File

@ -382,6 +382,16 @@ func (parser *parser) parseItem(scanner *scanner, ctx parserContext, termSymbols
}
func (parser *parser) Parse(scanner *scanner, termSymbols ...Symbol) (tree *ast, err error) {
defer func() {
if r := recover(); r != nil {
if errVal, ok := r.(error); ok {
err = errVal
}
}
if err == nil {
err = errors.New("unexpected error while parsing the expression")
}
}()
termSymbols = append(termSymbols, SymEos)
return parser.parseGeneral(scanner, allowMultiExpr, termSymbols...)
}