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

Commit

Permalink
drop v1 support and don't bind to libuast; use v2 xpath
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 25, 2018
1 parent 47a750b commit 1169333
Show file tree
Hide file tree
Showing 31 changed files with 464 additions and 2,877 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "{build}"
platform: x64
image: Visual Studio 2017

clone_folder: c:\gopath\src\gopkg.in\bblfsh\client-go.v2
clone_folder: c:\gopath\src\gopkg.in\bblfsh\client-go.v3

environment:
GOPATH: c:\gopath
Expand Down
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
language: go
go_import_path: gopkg.in/bblfsh/client-go.v2
go_import_path: gopkg.in/bblfsh/client-go.v3

env:
- BBLFSHD_VERSION=v2.6.1 BBLFSH_PYTHON_VERSION=v2.2.1
install:
- |
if [[ $TRAVIS_OS_NAME = linux ]]; then
sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
sudo -E apt-get -yq update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-6 g++-6
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 90
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 90
docker run --privileged -d -p 9432:9432 --name bblfshd bblfsh/bblfshd:$BBLFSHD_VERSION
docker exec bblfshd bblfshctl driver install bblfsh/python-driver:$BBLFSH_PYTHON_VERSION
fi
- make dependencies
- go get -v -t ./...

script:
- |
Expand Down
3 changes: 1 addition & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
name = "google.golang.org/grpc"
version = "1.14.x"

[[constraint]]
name = "gopkg.in/bblfsh/sdk.v1"
version = "1.16.x"

[[constraint]]
name = "gopkg.in/bblfsh/sdk.v2"
version = "2.2.x"
Expand Down
57 changes: 0 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Package configuration
PROJECT = client-go
LIBUAST_VERSION ?= 2.0.1

TOOLS_FOLDER = tools

# Including ci Makefile
CI_REPOSITORY ?= https://github.com/src-d/ci.git
Expand All @@ -12,57 +9,3 @@ MAKEFILE := $(CI_PATH)/Makefile.main
$(MAKEFILE):
git clone --quiet --depth 1 -b $(CI_BRANCH) $(CI_REPOSITORY) $(CI_PATH)
-include $(MAKEFILE)

clean: clean-libuast
clean-libuast:
find ./ -regex '.*\.[h,c]c?' ! -name 'bindings.h' -exec rm -f {} +

ifeq ($(OS),Windows_NT)
GOOS := windows
else
GOOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
endif

# 'Makefile::cgo-dependencies' target must be run before 'Makefile.main::dependencies' or 'go-get' will fail
dependencies: cgo-dependencies
go get -v -t ./...
.PHONY: dependencies cgo-dependencies

ifeq ($(GOOS),windows)
cgo-dependencies:
$(MAKE) clean-libuast && \
cd $(TOOLS_FOLDER) && \
curl -SLko archiver.exe https://github.com/mholt/archiver/releases/download/v2.0/archiver_windows_amd64.exe && \
curl -SLko binaries.win64.mingw.zip https://github.com/bblfsh/libuast/releases/download/v$(LIBUAST_VERSION)/binaries.win64.mingw.zip && \
./archiver.exe open binaries.win64.mingw.zip && \
rm binaries.win64.mingw.zip && \
rm archiver.exe && \
echo done
else
ifeq ($(GOOS),darwin)
cgo-dependencies: unix-dependencies
else
cgo-dependencies: | check-gcc unix-dependencies
endif
endif
.PHONY: cgo-dependencies

check-gcc:
@if \
[[ -z `which gcc` ]] || \
[[ -z `which g++` ]] || \
[[ 5 -gt `gcc -dumpversion | sed 's/^[^0-9]*\([0-9][0-9]*\).*/\1/g'` ]] || \
[[ 5 -gt `g++ -dumpversion | sed 's/^[^0-9]*\([0-9][0-9]*\).*/\1/g'` ]]; \
then \
echo -e "error; GCC and G++ v5 or greater are required \n"; \
echo -e "- GCC: `gcc --version` \n"; \
echo -e "- G++: `g++ --version` \n"; \
exit 1; \
fi;
.PHONY: check-gcc

unix-dependencies:
curl -SL https://github.com/bblfsh/libuast/archive/v$(LIBUAST_VERSION).tar.gz | tar xz
mv libuast-$(LIBUAST_VERSION)/src/* $(TOOLS_FOLDER)/.
rm -rf libuast-$(LIBUAST_VERSION)
.PHONY: unix-dependencies
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# client-go [![GoDoc](https://godoc.org/gopkg.in/bblfsh/client-go.v2?status.svg)](https://godoc.org/gopkg.in/bblfsh/client-go.v2) [![Build Status](https://travis-ci.org/bblfsh/client-go.svg?branch=master)](https://travis-ci.org/bblfsh/client-go) [![Build status](https://ci.appveyor.com/api/projects/status/github/bblfsh/client-go?svg=true)](https://ci.appveyor.com/project/mcuadros/client-go) [![codecov](https://codecov.io/gh/bblfsh/client-go/branch/master/graph/badge.svg)](https://codecov.io/gh/bblfsh/client-go)
# client-go [![GoDoc](https://godoc.org/gopkg.in/bblfsh/client-go.v3?status.svg)](https://godoc.org/gopkg.in/bblfsh/client-go.v3) [![Build Status](https://travis-ci.org/bblfsh/client-go.svg?branch=master)](https://travis-ci.org/bblfsh/client-go) [![Build status](https://ci.appveyor.com/api/projects/status/github/bblfsh/client-go?svg=true)](https://ci.appveyor.com/project/mcuadros/client-go) [![codecov](https://codecov.io/gh/bblfsh/client-go/branch/master/graph/badge.svg)](https://codecov.io/gh/bblfsh/client-go)

[Babelfish](https://doc.bblf.sh) Go client library provides functionality to both
connecting to the Babelfish server for parsing code
Expand All @@ -10,12 +10,9 @@ and for analysing UASTs with the functionality provided by [libuast](https://git
The recommended way to install *client-go* is:

```sh
go get -u gopkg.in/bblfsh/client-go.v2/...
go get -u gopkg.in/bblfsh/client-go.v3/...
```

Windows build is supported, provided by you have `make` and `curl` in your `%PATH%`.
It is also possible to link against custom `libuast` on Windows, read [WINDOWS.md](WINDOWS.md).

## Example

This small example illustrates how to retrieve the [UAST](https://doc.bblf.sh/uast/specification.html) from a small Python script.
Expand All @@ -32,12 +29,12 @@ if err != nil {

python := "import foo"

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

query := "//*[@roleImport]"
query := "//*[@role='Import']"
nodes, _ := tools.Filter(res.UAST, query)
for _, n := range nodes {
fmt.Println(n)
Expand Down Expand Up @@ -80,16 +77,15 @@ iter, err := tools.NewIterator(res.UAST)
if err != nil {
panic(err)
}
defer iter.Dispose()
for node := range iter.Iterate() {
for node := range tools.Iterate(iter) {
fmt.Println(node)
}
// For XPath expressions returning a boolean/numeric/string value, you must
// use the right typed Filter function:
boolres, err := FilterBool(res.UAST, "boolean(//*[@strtOffset or @endOffset])")
boolres, err := FilterBool(res.UAST, "boolean(//*[@start-offset or @end-offset])")
strres, err := FilterString(res.UAST, "name(//*[1])")
numres, err := FilterNumber(res.UAST, "count(//*)")
```
Expand Down
46 changes: 0 additions & 46 deletions WINDOWS.md

This file was deleted.

39 changes: 0 additions & 39 deletions _example/main.go

This file was deleted.

16 changes: 3 additions & 13 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,17 @@ func NewClientWithConnection(conn *grpc.ClientConn) (*Client, error) {
}, nil
}

// NewParseRequestV2 is a parsing request to get the UAST.
func (c *Client) NewParseRequestV2() *ParseRequestV2 {
return &ParseRequestV2{client: c}
}

// NewParseRequest is a parsing request to get the UAST.
func (c *Client) NewParseRequest() *ParseRequest {
return &ParseRequest{client: c}
}

// NewNativeParseRequest is a parsing request to get the AST.
func (c *Client) NewNativeParseRequest() *NativeParseRequest {
return &NativeParseRequest{client: c}
return &ParseRequest{ctx: context.Background(), client: c}
}

// NewVersionRequest is a parsing request to get the version of the server.
func (c *Client) NewVersionRequest() *VersionRequest {
return &VersionRequest{client: c}
return &VersionRequest{ctx: context.Background(), client: c}
}

// NewSupportedLanguagesRequest is a parsing request to get the supported languages.
func (c *Client) NewSupportedLanguagesRequest() *SupportedLanguagesRequest {
return &SupportedLanguagesRequest{client: c}
return &SupportedLanguagesRequest{ctx: context.Background(), client: c}
}
25 changes: 6 additions & 19 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var clientTests = []struct {
{name: "ParseRequest", test: testParseRequest},
{name: "ParseRequestMode", test: testParseRequestMode},
{name: "NativeParseRequest", test: testNativeParseRequest},
{name: "ParseRequestV2", test: testParseRequestV2},
{name: "VersionRequest", test: testVersionRequest},
{name: "SupportedLanguagesRequest", test: testSupportedLanguagesRequest},
}
Expand All @@ -49,52 +48,40 @@ func testParseRequest(t *testing.T, cli *Client) {
require.NoError(t, err)

require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res.UAST)
require.NotNil(t, res)
}

func testParseRequestMode(t *testing.T, cli *Client) {
res, err := cli.NewParseRequest().Language("python").Content("import foo").Mode(Semantic).Do()
require.NoError(t, err)

require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res.UAST)
require.NotNil(t, res)

res, err = cli.NewParseRequest().Language("python").Content("import foo").Mode(Annotated).Do()
require.NoError(t, err)

require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res.UAST)
t.Log(res.UAST)
require.NotNil(t, res)
t.Log(res)
}

func testNativeParseRequest(t *testing.T, cli *Client) {
res, err := cli.NewNativeParseRequest().Language("python").Content("import foo").Do()
res, err := cli.NewParseRequest().Mode(Native).Language("python").Content("import foo").Do()
require.NoError(t, err)

require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res.AST)
}

func testParseRequestV2(t *testing.T, cli *Client) {
res, lang, err := cli.NewParseRequestV2().Language("python").Content("import foo").UAST()
require.NoError(t, err)

require.Equal(t, "python", lang)
require.NotNil(t, res)
}

func testVersionRequest(t *testing.T, cli *Client) {
res, err := cli.NewVersionRequest().Do()
require.NoError(t, err)

require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res.Version)
}

func testSupportedLanguagesRequest(t *testing.T, cli *Client) {
res, err := cli.NewSupportedLanguagesRequest().Do()
require.NoError(t, err)

require.Equal(t, 0, len(res.Errors))
require.NotEmpty(t, res.Languages)
require.NotEmpty(t, res)
}
Loading

0 comments on commit 1169333

Please sign in to comment.