edit

package
v0.58.1-0...-af594cf Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(node ast.Node, pattern ast.Node, matchSlicesFuzzy bool) []ast.Node

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

func Option(node ast.Node, optionIdentifier string, fn OptionFn) (bool, error)

`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`.

Jump to

Keyboard shortcuts

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