/ skylark / resolve

Index | Files | Exmaples | Directories
go get

Package resolve defines a name-resolution pass for Skylark abstract syntax trees.

The resolver sets the Locals and FreeVars arrays of each DefStmt and the LocalIndex field of each syntax.Ident that refers to a local or free variable. It also sets the Locals array of a File for locals bound by comprehensions outside any function. Identifiers for global variables do not get an index.


Package Files



var (
    AllowNestedDef      = false // allow def statements within function bodies
    AllowLambda         = false // allow lambda expressions
    AllowFloat          = false // allow floating point literals, the 'float' built-in, and x / y
    AllowFreeze         = false // allow the 'freeze' built-in
    AllowSet            = false // allow the 'set' built-in
    AllowGlobalReassign = false // allow reassignment to globals declared in same file (deprecated)

global options These features are either not standard Skylark (yet), or deprecated features of the BUILD language, so we put them behind flags.

func Expr

func Expr(expr syntax.Expr, isPredeclaredGlobal, isBuiltin func(name string) bool) ([]*syntax.Ident, error)

Expr resolves the specified expression. It returns the local variables bound within the expression.

func File

func File(file *syntax.File, isPredeclaredGlobal, isBuiltin func(name string) bool) error

File resolves the specified file.

type Error

type Error struct {
    Pos syntax.Position
    Msg string

An Error describes the nature and position of a resolver error.

func (Error) Error

func (e Error) Error() string

type ErrorList

type ErrorList []Error // len > 0

An ErrorList is a non-empty list of resolver error messages.

func (ErrorList) Error

func (e ErrorList) Error() string

type Scope

type Scope uint8

The Scope of a syntax.Ident indicates what kind of scope it has.

const (
    Undefined Scope = iota // name is not defined
    Local                  // name is local to its function
    Free                   // name is local to some enclosing function
    Global                 // name is global to module
    Builtin                // name is universal (e.g. len)

func (Scope) String

func (scope Scope) String() string