Documentation
¶
Index ¶
- func Compile(config CompileConfig) (*Pattern, PatternInfo, error)
- func IsEmptyNodeSlice(n ast.Node) bool
- func Walk(root ast.Node, fn func(n ast.Node) bool)
- type CapturedNode
- type CompileConfig
- type MatchData
- type MatcherState
- type NodeSlice
- func (s *NodeSlice) At(i int) ast.Node
- func (s *NodeSlice) End() token.Pos
- func (s *NodeSlice) GetDeclSlice() []ast.Decl
- func (s *NodeSlice) GetExprSlice() []ast.Expr
- func (s *NodeSlice) GetFieldSlice() []*ast.Field
- func (s *NodeSlice) GetIdentSlice() []*ast.Ident
- func (s *NodeSlice) GetSpecSlice() []ast.Spec
- func (s *NodeSlice) GetStmtSlice() []ast.Stmt
- func (s *NodeSlice) Len() int
- func (s *NodeSlice) Pos() token.Pos
- func (s *NodeSlice) SliceInto(dst *NodeSlice, i, j int)
- type NodeSliceKind
- type PartialNode
- type Pattern
- type PatternInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
func Compile(config CompileConfig) (*Pattern, PatternInfo, error)
func IsEmptyNodeSlice ¶
Types ¶
type CapturedNode ¶
type CompileConfig ¶
type CompileConfig struct {
Fset *token.FileSet
// Src is a gogrep pattern expression string.
Src string
// When strict is false, gogrep may consider 0xA and 10 to be identical.
// If true, a compiled pattern will require a full syntax match.
Strict bool
// WithTypes controls whether gogrep would have types.Info during the pattern execution.
// If set to true, it will compile a pattern to a potentially more precise form, where
// fmt.Printf maps to the stdlib function call but not Printf method call on some
// random fmt variable.
WithTypes bool
// Imports specifies packages that should be recognized for the type-aware matching.
// It maps a package name to a package path.
// Only used if WithTypes is true.
Imports map[string]string
}
type MatchData ¶
type MatchData struct {
Node ast.Node
Capture []CapturedNode
}
MatchData describes a successful pattern match.
type MatcherState ¶
type MatcherState struct {
Types *types.Info
// CapturePreset is a key-value pairs to use in the next match calls
// as predefined variables.
// For example, if the pattern is `$x = f()` and CapturePreset contains
// a pair with Name=x and value of `obj.x`, then the above mentioned
// pattern will only match `obj.x = f()` statements.
//
// If nil, the default behavior will be used. A first syntax element
// matching the matcher var will be captured.
CapturePreset []CapturedNode
// contains filtered or unexported fields
}
func NewMatcherState ¶
func NewMatcherState() MatcherState
type NodeSlice ¶
type NodeSlice struct {
Kind NodeSliceKind
// contains filtered or unexported fields
}
func (*NodeSlice) GetDeclSlice ¶
func (*NodeSlice) GetExprSlice ¶
func (*NodeSlice) GetFieldSlice ¶
func (*NodeSlice) GetIdentSlice ¶
func (*NodeSlice) GetSpecSlice ¶
func (*NodeSlice) GetStmtSlice ¶
type NodeSliceKind ¶
type NodeSliceKind uint32
const ( ExprNodeSlice NodeSliceKind = iota StmtNodeSlice FieldNodeSlice IdentNodeSlice SpecNodeSlice DeclNodeSlice )
type PartialNode ¶
func (*PartialNode) End ¶
func (p *PartialNode) End() token.Pos
func (*PartialNode) Pos ¶
func (p *PartialNode) Pos() token.Pos
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
type PatternInfo ¶
type PatternInfo struct {
Vars map[string]struct{}
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.
