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 ¶
View Source
var ( // ErrDriverFailure is returned when the driver is malfunctioning. ErrDriverFailure = derrors.ErrDriverFailure // ErrSyntax is returned when driver cannot parse the source file. // Can be omitted for native driver implementations. ErrSyntax = derrors.ErrSyntax // ErrTransformFailure is returned if one of the UAST transformations fails. ErrTransformFailure = errors.NewKind("transform failed") // ErrModeNotSupported is returned if a UAST transformation mode is not supported by the driver. ErrModeNotSupported = errors.NewKind("transform mode not supported") )
Functions ¶
func JoinErrors ¶
Join multiple errors into a single error value.
Types ¶
type Driver ¶
type Driver interface { // Parse reads the input string and constructs an AST representation of it. // // Language can be specified by providing ParseOptions. If the language is not set, // it will be set during the Parse call if implementation supports language detection. // // Depending on the mode, AST may be transformed to different UAST variants. // ErrModeNotSupported is returned for unsupported transformation modes. // // Syntax errors are indicated by returning ErrSyntax. // In this case a non-empty UAST may be returned, if driver supports partial parsing. // // Native driver failures are indicated by ErrDriverFailure and UAST transformation are indicated by ErrTransformFailure. // All other errors indicate a protocol or server failure. Parse(ctx context.Context, src string, opts *ParseOptions) (nodes.Node, error) }
Driver is an interface for a language driver that returns UAST.
type DriverModule ¶
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 Native ¶
type Native interface { Module // Parse reads the input string and constructs an AST representation of it. // All errors are considered ErrSyntax, unless they are wrapped into ErrDriverFailure. Parse(ctx context.Context, src string) (nodes.Node, error) }
Native is a base interface of a language driver that returns a native AST.
type ParseOptions ¶
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.
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. |
Click to show internal directories.
Click to hide internal directories.