Skip to content

Commit c6c7227

Browse files
committed
Return tree on parse errors
1 parent 65c7bc9 commit c6c7227

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

ast/visitor.go

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ type Visitor interface {
77
}
88

99
func Walk(node *Node, v Visitor) {
10+
if *node == nil {
11+
return
12+
}
1013
switch n := (*node).(type) {
1114
case *NilNode:
1215
case *IdentifierNode:

checker/checker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func ParseCheck(input string, config *conf.Config) (*parser.Tree, error) {
1919
tree, err := parser.ParseWithConfig(input, config)
2020
if err != nil {
21-
return nil, err
21+
return tree, err
2222
}
2323

2424
if len(config.Visitors) > 0 {

parser/parser.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ func ParseWithConfig(input string, config *conf.Config) (*Tree, error) {
8484
p.error("unexpected token %v", p.current)
8585
}
8686

87+
tree := &Tree{
88+
Node: node,
89+
Source: source,
90+
}
91+
8792
if p.err != nil {
88-
return nil, p.err.Bind(source)
93+
return tree, p.err.Bind(source)
8994
}
9095

91-
return &Tree{
92-
Node: node,
93-
Source: source,
94-
}, nil
96+
return tree, nil
9597
}
9698

9799
func (p *parser) error(format string, args ...any) {

0 commit comments

Comments
 (0)