compiler

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownType = iota
	ArrayType
	BoolType
	FunctionType
	NumberType
	ObjectType
	StringType
)

Variables

This section is empty.

Functions

func Pretty added in v0.2.0

func Pretty(pretty bool) func(*Grammar) error

func Size added in v0.2.0

func Size(size int) func(*Grammar) error

Types

type ArrayExpr added in v0.2.0

type ArrayExpr []*ValueExpr

func (ArrayExpr) ToGoAST added in v0.2.0

func (a ArrayExpr) ToGoAST() dst.Expr

func (ArrayExpr) ToGoValue added in v0.2.0

func (a ArrayExpr) ToGoValue() []interface{}

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

func NewCompiler added in v0.2.0

func NewCompiler(file string) *Compiler

func (*Compiler) Compile

func (c *Compiler) Compile() *dst.File

Compile returns a `*dst.File` which can be formatted into Go using `go/format` or `go/printer`. The Load() method must be called before this.

func (*Compiler) Load

func (c *Compiler) Load() error

Load the compiler's playbook file and parse it into the Unobin AST or return an error.

func (*Compiler) PackageResources added in v0.3.0

func (c *Compiler) PackageResources() error

PackageResources bundles files from a playbook's resources directory into a file called resources.go using github.com/go-bindata/go-bindata.

func (*Compiler) Validate added in v0.2.0

func (c *Compiler) Validate() error

Validate checks for errors not caught by the parser. For example, the parser only knows that attributes should be pairs of string -> value, but does not enforce the underlying type required for the value. This function ensures that:

  • Required attributes are present: name, description, imports, and input-schema, and that they are the correct type.
  • Imports are defined as an object with string keys and string values, and that the import paths are correctly formatted. TODO: check that module exists on the given path.
  • The input schema is a valid JSON schema.
  • Tasks refer only to modules that are defined in imports.

type FunctionExpr added in v0.2.0

type FunctionExpr struct {
	Name string
	Args ArrayExpr
}

func (*FunctionExpr) ToGoAST added in v0.2.0

func (f *FunctionExpr) ToGoAST() dst.Expr

func (*FunctionExpr) ToGoValue added in v0.2.0

func (f *FunctionExpr) ToGoValue() []interface{}

type Grammar added in v0.2.0

type Grammar struct {
	Buffer string

	Pretty bool
	// contains filtered or unexported fields
}

func (*Grammar) AST added in v0.2.0

func (t *Grammar) AST() *node32

func (*Grammar) Add added in v0.2.0

func (t *Grammar) Add(rule pegRule, begin, end, index uint32)

func (*Grammar) Init added in v0.2.0

func (p *Grammar) Init(options ...func(*Grammar) error) error

func (*Grammar) LoadUAST added in v0.2.0

func (g *Grammar) LoadUAST()

func (*Grammar) Parse added in v0.2.0

func (p *Grammar) Parse(rule ...int) error

func (*Grammar) PrettyPrintSyntaxTree added in v0.2.0

func (t *Grammar) PrettyPrintSyntaxTree(buffer string)

func (*Grammar) Print added in v0.2.0

func (t *Grammar) Print()

func (*Grammar) PrintSyntaxTree added in v0.2.0

func (p *Grammar) PrintSyntaxTree()

func (*Grammar) Reset added in v0.2.0

func (p *Grammar) Reset()

func (*Grammar) SprintSyntaxTree added in v0.2.0

func (p *Grammar) SprintSyntaxTree() string

func (*Grammar) Tokens added in v0.2.0

func (t *Grammar) Tokens() []token32

func (*Grammar) Trim added in v0.2.0

func (t *Grammar) Trim(length uint32)

func (*Grammar) WriteSyntaxTree added in v0.2.0

func (p *Grammar) WriteSyntaxTree(w io.Writer)

type NumberExpr added in v0.2.0

type NumberExpr struct {
	Int   *int64
	Float *float64
}

func (*NumberExpr) ToGoAST added in v0.2.0

func (n *NumberExpr) ToGoAST() dst.Expr

func (*NumberExpr) ToGoValue added in v0.2.0

func (n *NumberExpr) ToGoValue() interface{}

type ObjectExpr added in v0.2.0

type ObjectExpr map[string]*ValueExpr

func (ObjectExpr) ToGoAST added in v0.2.0

func (o ObjectExpr) ToGoAST() dst.Expr

func (ObjectExpr) ToGoValue added in v0.2.0

func (o ObjectExpr) ToGoValue() map[string]interface{}

type PairExpr added in v0.2.0

type PairExpr struct {
	Name  string
	Value *ValueExpr
}

type TaskExpr added in v0.2.0

type TaskExpr struct {
	Description string
	Module      string
	When        *FunctionExpr
	Args        ObjectExpr
	Body        []*TaskExpr
	Rescue      []*TaskExpr
	Always      []*TaskExpr
}

type Type added in v0.2.0

type Type int

type UAST added in v0.2.0

type UAST struct {
	Attributes ObjectExpr
	Tasks      []*TaskExpr
}

UAST is the Unobin AST, so named to avoid confusion with the Go AST, which is generated during compilation.

func NewUAST added in v0.2.0

func NewUAST() *UAST

type ValueExpr added in v0.2.0

type ValueExpr struct {
	Array    ArrayExpr
	Bool     *bool
	Function *FunctionExpr
	Number   *NumberExpr
	Object   ObjectExpr
	String   *string
}

func (*ValueExpr) Equal added in v0.2.0

func (v *ValueExpr) Equal(other *ValueExpr) bool

func (*ValueExpr) ToGoAST added in v0.2.0

func (v *ValueExpr) ToGoAST() dst.Expr

func (*ValueExpr) ToGoValue added in v0.2.0

func (v *ValueExpr) ToGoValue() interface{}

func (*ValueExpr) Type added in v0.2.0

func (v *ValueExpr) Type() Type

Jump to

Keyboard shortcuts

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