Skip to content

Commit

Permalink
Return tree on parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed May 18, 2024
1 parent 65c7bc9 commit c6c7227
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ast/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c6c7227

Please sign in to comment.