driver

package
v2.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package driver contains all the logic to build a driver.

Index

Constants

View Source
const (
	ModeNative = Mode(1 << iota)
	ModePreprocessed
	ModeAnnotated
	ModeSemantic
)
View Source
const ModeDefault = ModeSemantic

Variables

This section is empty.

Functions

func MultiError

func MultiError(errs []string) error

func PartialParse

func PartialParse(ast nodes.Node, errs []string) error

Types

type Driver

type Driver interface {
	Parse(ctx context.Context, mode Mode, src string) (nodes.Node, error)
}

Driver is an interface for a language driver that returns UAST.

type DriverModule

type DriverModule interface {
	Module
	Driver
	Manifest() (manifest.Manifest, error)
}

DriverModule is an interface for a driver instance.

func NewDriverFrom

func NewDriverFrom(d Native, m *manifest.Manifest, t Transforms) (DriverModule, error)

NewDriver returns a new Driver instance based on the given ObjectToNode and list of transformers.

type ErrMulti

type ErrMulti struct {
	Header string
	Errors []string
}

ErrMulti joins multiple errors.

func (ErrMulti) Error

func (e ErrMulti) Error() string

type ErrPartialParse

type ErrPartialParse struct {
	ErrMulti
	AST nodes.Node
}

ErrPartialParse is returned when driver was not able to parse the whole source file.

type Mode

type Mode int

type Module

type Module interface {
	Start() error
	Close() error
}

Module is an interface for a generic module instance.

type Native

type Native interface {
	Module
	Parse(ctx context.Context, src string) (nodes.Node, error)
}

Native is a base interface of a language driver that returns a native AST.

type Transforms

type Transforms struct {
	// Namespace for this language driver
	Namespace string
	// Preprocess transforms normalizes native AST.
	// It usually includes:
	//	* changing type key to uast.KeyType
	//	* changing token key to uast.KeyToken
	//	* restructure positional information
	Preprocess []transformer.Transformer
	// Normalize converts known AST structures to high-level AST representation (UAST).
	Normalize []transformer.Transformer
	// Annotations transforms annotates the tree with roles.
	Annotations []transformer.Transformer
	// Code transforms are applied directly after Native and provide a way
	// to extract more information from source files, fix positional info, etc.
	Code []transformer.CodeTransformer
}

Transforms describes a set of AST transformations this driver requires.

func (Transforms) Do

func (t Transforms) Do(mode Mode, code string, nd nodes.Node) (nodes.Node, error)

Do applies AST transformation pipeline for specified nodes.

Directories

Path Synopsis
discovery
Package discovery package implements helpers for clients to discover language drivers supported by Babelfish.
Package discovery package implements helpers for clients to discover language drivers supported by Babelfish.
jsonlines
Package json lines mimicks standard library json Encoder and Decoder, but to encode and decode one JSON per line.
Package json lines mimicks standard library json Encoder and Decoder, but to encode and decode one JSON per line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL