diff --git a/ast/visitor.go b/ast/visitor.go index 287a7558..90bc9f1d 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 5e20e5e8..a2c86c20 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 fd1b3c04..77b2a700 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) {