Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
cli: allow to query UASTv2
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <denys@sourced.tech>
  • Loading branch information
Denys Smirnov authored and dennwc committed Sep 20, 2018
1 parent 9db8a9e commit c85aa1e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/bblfsh-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
bblfsh "gopkg.in/bblfsh/client-go.v2"
"gopkg.in/bblfsh/client-go.v2/tools"
"gopkg.in/bblfsh/sdk.v1/uast"
"gopkg.in/bblfsh/sdk.v2/uast/nodes"
)

func main() {
Expand All @@ -39,8 +40,6 @@ func main() {
fatalf("missing file to parse")
} else if len(args) > 1 {
fatalf("couldn't parse more than a file at a time")
} else if opts.V2 && opts.Query != "" {
fatalf("queries are not supported for v2 yet")
}
filename := args[0]

Expand All @@ -62,11 +61,22 @@ func main() {
}
req = req.Mode(m)
}
nodes, _, err := req.UAST()
root, _, err := req.UAST()
if err != nil {
fatalf("couldn't parse %s: %v", args[0], err)
}
ast = nodes
if opts.Query != "" {
var arr nodes.Array
it, err := tools.FilterXPath(root, opts.Query)
if err != nil {
fatalf("couldn't apply query %q: %v", opts.Query, err)
}
for it.Next() {
arr = append(arr, it.Node().(nodes.Node))
}
root = arr
}
ast = root
} else {
req := client.NewParseRequest().
Language(opts.Language).
Expand Down

0 comments on commit c85aa1e

Please sign in to comment.