Documentation ¶
Overview ¶
Package ann provides a DSL to annotate UAST.
Index ¶
- Variables
- type Action
- type Predicate
- func And(ps ...Predicate) Predicate
- func HasChild(pred Predicate) Predicate
- func HasInternalRole(r string) Predicate
- func HasInternalType(it string) Predicate
- func HasProperty(k, v string) Predicate
- func HasToken(tk string) Predicate
- func Not(p Predicate) Predicate
- func Or(ps ...Predicate) Predicate
- type Rule
- func (r *Rule) Apply(n *uast.Node) error
- func (r *Rule) Children(rules ...*Rule) *Rule
- func (r *Rule) Descendants(rules ...*Rule) *Rule
- func (r *Rule) DescendantsOrSelf(rules ...*Rule) *Rule
- func (r *Rule) Do(actions ...Action) *Rule
- func (r *Rule) Error(err error) *Rule
- func (r *Rule) Roles(roles ...uast.Role) *Rule
- func (r *Rule) Self(rules ...*Rule) *Rule
- func (r *Rule) String() string
- type RuleError
Constants ¶
This section is empty.
Variables ¶
var Any = &any{}
Any matches any path.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action is the interface that wraps an operation to be made on a uast.Node, possibly mutatin it. The Do function applies the operation to the provided node and returns an optional error. The string method returns a string describing the operation.
func ReturnError ¶
ReturnError creates an action that always returns a RuleError wrapping the given error with the offending node information.
type Predicate ¶
Predicate is the interface that wraps boolean tests for uast.Nodes.
The Eval function evaluates the test over a node and returns its boolean output. The String function returns a description of the predicate in a syntax similar to XPath.
func HasInternalRole ¶
HasInternalRole is a convenience shortcut for:
HasProperty(uast.InternalRoleKey, r)
func HasInternalType ¶
HasInternalType matches a node if its internal type matches the given one.
func HasProperty ¶
HasProperty matches a node if it has a property matching the given key and value.
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule is a conversion rule that can visit a tree, match nodes against path matchers and apply actions to the matching node.
func On ¶
On is the *Rule constructor. It takes a list of predicates and returns a new *Rule that matches all of them.
func (*Rule) Children ¶
Children applies the given rules to children of nodes matched by the current rule.
func (*Rule) Descendants ¶
Descendants applies the given rules to any descendant matched of nodes matched by the current rule.
func (*Rule) DescendantsOrSelf ¶
DescendantsOrSelf applies the given rules to self and any descendant matched of nodes matched by the current rule.
type RuleError ¶
type RuleError interface { // Error implements the error interface. Error() string // Inner returns the wrapped error. Inner() error // Node returns the offending node. Node() *uast.Node }
RuleError values are returned by the annotation process when a rule created by the Error function is activated. A RuleError wraps the desired error and carries the node that provoke the error.