Categorygithub.com/dennwc/client-go
modulepackage
0.2.1
Repository: https://github.com/dennwc/client-go.git
Documentation: pkg.go.dev

# README

client-go GoDoc Build Status codecov

Babelfish Go client library provides functionality to both connect to the Babelfish server to parse code (obtaining an UAST as a result) and to analyse UASTs with the functionality provided by libuast.

Installation

The recommended way to install client-go is:

go get -u gopkg.in/bblfsh/client-go.v0/...
cd $GOPATH/src/gopkg.in/bblfsh/client-go.v0
make dependencies

Example

This small example illustrates how to retrieve the UAST from a small Python script.

If you don't have a bblfsh server running you can execute it using the following command:

docker run --privileged --rm -it -p 9432:9432 --name bblfsh bblfsh/server

Please read the getting started guide, to learn more about how to use and deploy a bblfsh server.

client, err := bblfsh.NewBblfshClient("0.0.0.0:9432")
if err != nil {
    panic(err)
}

python := "import foo"

res, err := client.NewParseRequest().Language("python").Content(python).Do()
if err != nil {
    panic(err)
}

fmt.Println(res.UAST)
Module {
.  Roles: File
.  Children: {
.  .  0: Import {
.  .  .  Roles: ImportDeclaration,Statement
.  .  .  StartPosition: {
.  .  .  .  Offset: 0
.  .  .  .  Line: 1
.  .  .  .  Col: 1
.  .  .  }
.  .  .  Properties: {
.  .  .  .  internalRole: body
.  .  .  }
.  .  .  Children: {
.  .  .  .  0: alias {
.  .  .  .  .  Roles: ImportPath,SimpleIdentifier
.  .  .  .  .  TOKEN "foo"
.  .  .  .  .  Properties: {
.  .  .  .  .  .  asname: <nil>
.  .  .  .  .  .  internalRole: names
.  .  .  .  .  }
.  .  .  .  }
.  .  .  }
.  .  }
.  }
}

License

Apache License 2.0, see LICENSE

# Functions

NewBblfshClient returns a new babelfish client given a server endpoint.

# Structs

BblfshClient holds the public client API to interact with the babelfish server.
ParseRequest is a placeholder for the parse requests performed by the library.