Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Match ¶ added in v0.20.0
Match takes an AST and a pattern and returns the nodes of the AST that match the given pattern. The pattern is an AST in turn, but it is partially specified, i.e. nil nodes are ignored while matching. In the case of slices (e.g. ast.File.Body, ast.CallExpression.Arguments) the matching mode can be "exact" or "fuzzy". Let ps be a slice of nodes in the pattern and ns in node. In "exact" mode, slices match iff len(ps) == len(ns) and every non-nil node ps[i] matches ns[i]. In "fuzzy" mode, slices match iff ns is a superset of ps; e.g. if ps is empty, it matches every slice.
func Option ¶
`Option` passes the `OptionStatement` in the AST rooted at `node` that has the specified identifier to `fn`. The function can have side effects on the option statement and/or return a non-nil `Expression` that is set as value for the option. If the value returned by the edit function is `nil` (or an error is returned) no new value is set for the option statement (but any, maybe partial, side effect is applied). `Option` returns whether it could find and edit the option (possibly with errors) or not.
Types ¶
type OptionFn ¶
type OptionFn func(opt *ast.OptionStatement) (ast.Expression, error)
`OptionFn` is a function that, provided with an `OptionStatement`, returns an `Expression` or an error. It is used by `Option` functions to edit AST's options statements.
func OptionObjectFn ¶
func OptionObjectFn(keyMap map[string]ast.Expression) OptionFn
Creates an `OptionFn` for updating the values of an `OptionStatement` that has an `ObjectExpression` as value. Returns error if the child of the option statement is not an object expression. If some key is not a property of the object it is added.
func OptionValueFn ¶
func OptionValueFn(expr ast.Expression) OptionFn
Creates an `OptionFn` for setting the value of an `OptionStatement`.