From c6c72273c963b594f2e164c17e83f230fed2e3a1 Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Sat, 18 May 2024 23:41:49 +0200 Subject: [PATCH] Return tree on parse errors --- ast/visitor.go | 3 +++ checker/checker.go | 2 +- parser/parser.go | 12 +++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ast/visitor.go b/ast/visitor.go index 287a75589..90bc9f1d0 100644 --- a/ast/visitor.go +++ b/ast/visitor.go @@ -7,6 +7,9 @@ type Visitor interface { } func Walk(node *Node, v Visitor) { + if *node == nil { + return + } switch n := (*node).(type) { case *NilNode: case *IdentifierNode: diff --git a/checker/checker.go b/checker/checker.go index 5e20e5e89..a2c86c208 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -18,7 +18,7 @@ import ( func ParseCheck(input string, config *conf.Config) (*parser.Tree, error) { tree, err := parser.ParseWithConfig(input, config) if err != nil { - return nil, err + return tree, err } if len(config.Visitors) > 0 { diff --git a/parser/parser.go b/parser/parser.go index fd1b3c043..77b2a700a 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -84,14 +84,16 @@ func ParseWithConfig(input string, config *conf.Config) (*Tree, error) { p.error("unexpected token %v", p.current) } + tree := &Tree{ + Node: node, + Source: source, + } + if p.err != nil { - return nil, p.err.Bind(source) + return tree, p.err.Bind(source) } - return &Tree{ - Node: node, - Source: source, - }, nil + return tree, nil } func (p *parser) error(format string, args ...any) {