Documentation ¶
Overview ¶
Package driver contains all the logic to build a driver.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DriverBinary default location of the driver binary. Should not // override this variable unless you know what are you doing. DriverBinary = "/opt/driver/bin/driver" // NativeBinary default location of the native driver binary. Should not // override this variable unless you know what are you doing. NativeBinary = "/opt/driver/bin/native" // ManifestLocation location of the manifest file. Should not override // this variable unless you know what are you doing. ManifestLocation = "/opt/driver/etc/" + manifest.Filename )
var ( ErrUnsupportedLanguage = errors.NewKind("unsupported language got %q, expected %q") ErrNativeNotRunning = errors.NewKind("native driver is not running") )
var ErrInvalidLogger = errors.NewKind("invalid logger configuration")
Functions ¶
func Run ¶ added in v1.10.0
func Run(o *uast.ObjectToNode, t []transformer.Tranformer)
Run is a common main function used as an entry point for drivers. It panics in case of an error.
Types ¶
type Driver ¶
type Driver struct { NativeDriver // contains filtered or unexported fields }
Driver implements a bblfsh driver, a driver is on charge of transforming a source code into an AST and a UAST. To transform the AST into a UAST, a `uast.ObjectToNode“ and a series of `tranformer.Transformer` are used.
The `Parse` and `NativeParse` requests block the driver until the request is done, since the communication with the native driver is a single-channel synchronous communication over stdin/stdout.
func NewDriver ¶
func NewDriver(o *uast.ObjectToNode, t []transformer.Tranformer) (*Driver, error)
NewDriver returns a new Driver instance based on the given ObjectToNode and list of transformers.
func (*Driver) NativeParse ¶
func (d *Driver) NativeParse(req *protocol.NativeParseRequest) *protocol.NativeParseResponse
NativeParse sends a request to the native driver and returns its response.
func (*Driver) Parse ¶
func (d *Driver) Parse(req *protocol.ParseRequest) *protocol.ParseResponse
Parse process a protocol.ParseRequest, calling to the native driver. It a parser request is done to the internal native driver and the the returned native AST is transform to UAST.
func (*Driver) Version ¶
func (d *Driver) Version(req *protocol.VersionRequest) *protocol.VersionResponse
Version handles a VersionRequest including information from the manifest.
type Encoding ¶
func (Encoding) MarshalJSON ¶
func (*Encoding) UnmarshalJSON ¶
type InternalParseRequest ¶
type InternalParseRequest struct { Content string `json:"content"` Encoding Encoding `json:"encoding"` }
InternalParseRequest is the request used to communicate the driver with the native driver via json.
type InternalParseResponse ¶
type InternalParseResponse struct { Status Status `json:"status"` Errors []string `json:"errors"` AST interface{} `json:"ast"` }
InternalParseResponse is the reply to InternalParseRequest by the native parser.
type NativeDriver ¶
type NativeDriver struct {
// contains filtered or unexported fields
}
NativeDriver is a wrapper of the native command. The operations with the driver are synchronous by design, this is controlled by a mutex. This means that only one parse request can attend at the same time.
func (*NativeDriver) Parse ¶
func (d *NativeDriver) Parse(req *InternalParseRequest) *InternalParseResponse
Parse sends a request to the native driver and returns its response.
func (*NativeDriver) Start ¶
func (d *NativeDriver) Start() error
Start executes the given native driver and prepares it to parse code.
func (*NativeDriver) Stop ¶
func (d *NativeDriver) Stop() error
Stop stops the execution of the native driver.