fix: panic when there is any lexer error

This commit is contained in:
mzz2017 2023-01-28 18:51:21 +08:00
parent 83a303d786
commit 49afec8079
2 changed files with 10 additions and 1 deletions

View File

@ -98,7 +98,7 @@ func readConfig() (params *config.Params, err error) {
}
sections, err := config_parser.Parse(string(b))
if err != nil {
return nil, err
return nil, fmt.Errorf("\n%w", err)
}
if params, err = config.New(sections); err != nil {
return nil, err

View File

@ -18,6 +18,8 @@ type Walker struct {
parser antlr.Parser
Sections []*Section
hasLexerError bool
}
func NewWalker(parser antlr.Parser) *Walker {
@ -249,7 +251,14 @@ func (w *Walker) parseExpression(exp dae_config.IExpressionContext) *Section {
}
}
func (w *Walker) VisitErrorNode(node antlr.ErrorNode) {
w.hasLexerError = true
}
func (w *Walker) EnterProgramStructureBlcok(ctx *dae_config.ProgramStructureBlcokContext) {
if w.hasLexerError {
return
}
section := w.parseExpression(ctx.Expression())
if section == nil {
return