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

Commit

Permalink
Merge pull request #111 from creachadair/example
Browse files Browse the repository at this point in the history
Document how to serialize nodes to protobuf.
  • Loading branch information
creachadair authored Feb 13, 2019
2 parents f1bb423 + 9fe8295 commit 22d4c7a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ go get -u gopkg.in/bblfsh/client-go.v3/...
## Example
### CLI

Allthough *clinet-go* is a library, this codebase also includes an example of `bblfsh-cli` application at [`./cmd/bblfsh-cli`](/cmd/bblfsh-cli). When [installed](#Installation), it allows to parse a single file, query it with XPath and print the resulting UAST structure immediatly.
Although *client-go* is a library, this codebase also includes an example of `bblfsh-cli` application at [`./cmd/bblfsh-cli`](/cmd/bblfsh-cli). When [installed](#Installation), it allows to parse a single file, query it with XPath and print the resulting UAST structure immediately.
See `$ bblfsh-cli -h` for list of all available CLI options.

### Code
Expand Down Expand Up @@ -58,8 +58,19 @@ func main() {
nodeAr = append(nodeAr, it.Node().(nodes.Node))
}

//alternative: encode UAST nodes to JSON (instead of YAML example below)
//data, err := json.MarshalIndent(nodeAr, "", " ")
// The example below emits YAML.
//
// Alternative 1: encode UAST nodes to JSON.
// data, err := json.MarshalIndent(nodeAr, "", " ")
//
// Alternative 2: encode UAST nodes to protobuf.
// import "gopkg.in/bblfsh/sdk.v2/uast/nodes/nodesproto"
// ...
// for _, node := range nodesAr {
// err := nodesproto.WriteTo(os.Stdout, nodeAr) // check
// ...
// }
//
data, err := uastyml.Marshal(nodeAr)
if err != nil {
panic(err)
Expand Down

0 comments on commit 22d4c7a

Please sign in to comment.