This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
Summary
- Lifts, from
libuast
library, format types:BblfshClient.UastBinary
: our custom binary format to store a tree. We provide the guarantee thatencode ∘ decode
in this format is the identity.BblfshClient.UastYaml
: directly readable from standard output. We do not provide the gurantee thatencode ∘ decode
in this format is the identity. Should only be used for debugging purposes.
- Lifts, from
libuast
library, tree orders (for iteration):BblfshClient.AnyOrder
,BblfshClient.PreOrder
,BblfshClient.PostOrder
,BblfshClient.LevelOrder
,BblfshClient.ChildrenOrder
andBblfshClient.PositionOrder
.AnyOrder
only provides the guarantee that all nodes will be iterated. - Adds more tests for
iterator
andencode ∘ decode
. - Solves
sbt
dying from incorrect bytes passed todecode
method #130. - Adds 60 seconds default timeout to get a (U)AST and makes
timeout
parameter work inBblfshClient
corresponding parsing methods:parseWithOptions
andparseWithTimeout
. - Removes terminal CLI
org.bblfsh.client.cli.ScalaClientCLI
. This client did not work with an XPath query from several releases ago. If you need a CLI, check out ourgo-client
. - Improves OSX support (macOS 10.7 onward should work correctly) and adds Windows support. Note since
bblfshd
does not include support for Windows, you could use this client on a Windows, butbblfshd
should be mounted on a virtual machine or be accesible through a URL. - Adds cache for methods and classes in JNI layer. This should slightly speed up native part of the library.
- Adds filter flavours based on return value:
BblfshClient.filterBool
,BblfshClient.filterString
,BblfshClient.filterInt
,BblfshClient.filterUint
andBblfshClient.filterFloat
. These methods work similarly tofilter
, but they only output nodes ofBool
,String
, etc type (respectively). - Bumps
sdk
andlibuast
versions. - Reduces size of the library: native shared libraries stripped from symbols.
- Cleans compilation of JNI from warnings: this could produce an overflow in older versions due to accumulation of local references if the file being parsed was big.
- Compilation of the project locally now has to be done with
build.sh
script.
Examples
UastFormat
and TreeOrder
import scala.io.Source
import org.bblfsh.client.v2.BblfshClient, BblfshClient._
import org.bblfsh.client.v2.Context, Context._
import gopkg.in.bblfsh.sdk.v2.protocol.driver.Mode
val client = BblfshClient("localhost", 9432)
val filename = "/path/to/file.py" // client responsible for encoding it to utf-8
val fileContent = Source.fromFile(filename).getLines.mkString("\n")
val resp = client.parse(filename, fileContent, Mode.SEMANTIC)
val root = resp.get()
val ctx = Context()
// Get encoding in binary format
val buffer = ctx.encode(root, fmt = UastBinary)
// Old API passing an integer also works
val buffer = ctx.encode(root, fmt = 0)
// Binary by default
val buffer = ctx.encode(root)
// Yaml format
val buffer = ctx.encode(root, fmt = UastYaml)
// Same result: yaml format
val buffer = ctx.encode(fmt = 1)
// Iterator with AnyOrder traversing
val it = iterator(root, AnyOrder)
// Also uses AnyOrder
val it = iterator(root, 0)
Timeout to get the (U)AST
import scala.io.Source
import org.bblfsh.client.v2.BblfshClient, BblfshClient._
import gopkg.in.bblfsh.sdk.v2.protocol.driver.Mode
val client = BblfshClient("localhost", 9432)
val filename = "/path/to/file.py" // client responsible for encoding it to utf-8
val fileContent = Source.fromFile(filename).getLines.mkString("\n")
// 30 seconds timeout to get the UAST
val resp = client.parseWithOptions(filename, fileContent, "python", 30, Mode.SEMANTIC)
// Same as
val resp = client.parseWithOptions(filename, fileContent, lang = "", 30, Mode.SEMANTIC)
// and
val resp = client.parseWithTimeout(filename, fileContent, 30)
// Get annotated AST with 30 seconds timeout to get a response
val resp = client.parseWithOptions(filename, fileContent, "python", 30, Mode.ANNOTATED)
val ctx = resp.get()
// Get default timeout (in seconds)
println(client.DEFAULT_TIMEOUT_SEC)
Compilation of the project locally
chmod +x ./build.sh
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
./build.sh --clean --get-dependencies --all
After that, the following command can be used to execute the interpreter in interactive mode:
./sbt console