Skip to content

Commit

Permalink
evaluator: replace Function.Syntax method with accessors (google#92)
Browse files Browse the repository at this point in the history
* evaluator: replace Function.Syntax method with accessors

Future versions of Function may not have a syntax tree.

This is a breaking API change.
  • Loading branch information
adonovan authored Mar 23, 2018
1 parent 7f065b6 commit f11011f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,18 @@ func (fn *Function) String() string { return toString(fn) }
func (fn *Function) Type() string { return "function" }
func (fn *Function) Truth() Bool { return true }

func (fn *Function) Syntax() *syntax.Function { return fn.syntax }
// syntax accessors
//
// We do not expose the syntax tree; future versions of Function may dispense with it.

func (fn *Function) Position() syntax.Position { return fn.position }
func (fn *Function) NumParams() int { return len(fn.syntax.Params) }
func (fn *Function) Param(i int) (string, syntax.Position) {
id := fn.syntax.Locals[i]
return id.Name, id.NamePos
}
func (fn *Function) HasVarargs() bool { return fn.syntax.HasVarargs }
func (fn *Function) HasKwargs() bool { return fn.syntax.HasKwargs }

// A Builtin is a function implemented in Go.
type Builtin struct {
Expand Down

0 comments on commit f11011f

Please sign in to comment.