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 #216 from juanjux/clients_cmdline
Browse files Browse the repository at this point in the history
Add info about the cmdline clients
  • Loading branch information
juanjux committed Oct 9, 2018
2 parents ee5ec55 + ce66e04 commit cbe5eba
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions using-babelfish/clients.md
Expand Up @@ -2,7 +2,7 @@

There are some clients in different languages that provide a higher level API, built on top of [gRPC](https://grpc.io) and [`libuast`](https://github.com/bblfsh/libuast).

These clients make it easier to both parse and analyze the resulting UAST, abstracting from network communication and providing a query language to filter UASTs.
These clients make it easier to both parse and analyze the resulting UAST, abstracting from network communication and providing a query language to filter UASTs and can be used both as a library or as command line programs.

## Existing clients

Expand All @@ -20,6 +20,14 @@ The client API's differ to adapt to their language specific idioms, the followin

### Go example

As a command:

```bash
bblfsh-cli -q [XPath query] -m semantic [file.ext]
```

As a library:

```go
package main

Expand Down Expand Up @@ -47,7 +55,7 @@ func main() {
panic("Parsing failed")
}

query := "//*[@roleIdentifier and not(@roleQualified)]"
query := "//*[@role='Identifier' and not(@role='Qualified')]"
nodes, _ := tools.Filter(res.UAST, query)
for _, n := range nodes {
fmt.Println(n)
Expand All @@ -57,6 +65,14 @@ func main() {

### Python example

As a command:

```bash
python -m bblfsh -q [XPath query] -f [file.ext]
```

As a library:

```python
import bblfsh

Expand All @@ -69,14 +85,22 @@ if __name__ == "__main__":
if response.status != 0:
raise Exception('Some error happened: ' + str(response.errors))

query = "//*[@roleIdentifier and not(@roleQualified)]"
query = "//*[@role='Identifier' and not(@role='Qualified')]"
nodes = filter_uast(response.uast, query)
for n in nodes:
print(n)
```

### Scala example

As a command:

```bash
java -jar bblfsh-client-assembly-1.0.1.jar -q [XPath query] -f file.py
```

As a library:

```scala
import org.bblfsh.client.BblfshClient._

Expand All @@ -93,7 +117,7 @@ class BblfshClientParseTest {

if (resp.uast.isDefined) {
rootNode = resp.uast.get
val filtered = client.filter(rootNode, "//*[@roleIdentifier and not(@roleQualified)]")
val filtered = client.filter(rootNode, "//*[@role='Identifier' and not(@role='Qualified')]")
filtered.foreach{ println }
} else {
// ... handle resp.uast.errors
Expand Down

0 comments on commit cbe5eba

Please sign in to comment.