astp

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: MIT Imports: 1 Imported by: 6

README

astp

build-img pkg-img reportcard-img version-img

Package astp provides AST predicates.

Installation:

Go version 1.16+

go get github.com/go-toolsmith/astp

Example

package main

import (
	"fmt"

	"github.com/go-toolsmith/astp"
	"github.com/go-toolsmith/strparse"
)

func main() {
	if astp.IsIdent(strparse.Expr(`x`)) {
		fmt.Println("ident")
	}
	if astp.IsBlockStmt(strparse.Stmt(`{f()}`)) {
		fmt.Println("block stmt")
	}
	if astp.IsGenDecl(strparse.Decl(`var x int = 10`)) {
		fmt.Println("gen decl")
	}
}

License

MIT License.

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/go-toolsmith/astp"
	"github.com/go-toolsmith/strparse"
)

func main() {
	if astp.IsIdent(strparse.Expr(`x`)) {
		fmt.Println("ident")
	}
	if astp.IsBlockStmt(strparse.Stmt(`{f()}`)) {
		fmt.Println("block stmt")
	}
	if astp.IsGenDecl(strparse.Decl(`var x int = 10`)) {
		fmt.Println("gen decl")
	}

}
Output:

ident
block stmt
gen decl

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsArrayType

func IsArrayType(node ast.Node) bool

IsArrayType reports whether a given ast.Node is an array or slice type (*ast.IsArrayType).

func IsAssignStmt

func IsAssignStmt(node ast.Node) bool

IsAssignStmt reports whether a given ast.Node is an assignment statement(*ast.AssignStmt)

func IsBadExpr

func IsBadExpr(node ast.Node) bool

IsBadExpr reports whether a given ast.Node is a bad expression (*ast.IsBadExpr).

func IsBadStmt

func IsBadStmt(node ast.Node) bool

IsBadStmt reports whether a given ast.Node is a bad statement(*ast.BadStmt)

func IsBasicLit

func IsBasicLit(node ast.Node) bool

IsBasicLit reports whether a given ast.Node is a literal of basic type (*ast.IsBasicLit).

func IsBinaryExpr

func IsBinaryExpr(node ast.Node) bool

IsBinaryExpr reports whether a given ast.Node is a binary expression (*ast.IsBinaryExpr).

func IsBlockStmt

func IsBlockStmt(node ast.Node) bool

IsBlockStmt reports whether a given ast.Node is a block statement(*ast.BlockStmt)

func IsBranchStmt

func IsBranchStmt(node ast.Node) bool

IsBranchStmt reports whether a given ast.Node is a branch(goto/continue/break/fallthrough)statement(*ast.BranchStmt)

func IsCallExpr

func IsCallExpr(node ast.Node) bool

IsCallExpr reports whether a given ast.Node is an expression followed by an argument list (*ast.IsCallExpr).

func IsCaseClause

func IsCaseClause(node ast.Node) bool

IsCaseClause reports whether a given ast.Node is a case statement(*ast.CaseClause)

func IsChanType

func IsChanType(node ast.Node) bool

IsChanType reports whether a given ast.Node is a channel type (*ast.IsChanType).

func IsCommClause

func IsCommClause(node ast.Node) bool

IsCommClause reports whether a given ast.Node is a select statement(*ast.CommClause)

func IsCompositeLit

func IsCompositeLit(node ast.Node) bool

IsCompositeLit reports whether a given ast.Node is a composite literal (*ast.IsCompositeLit).

func IsDecl

func IsDecl(node ast.Node) bool

IsDecl reports whether a node is a ast.Decl.

func IsDeclStmt

func IsDeclStmt(node ast.Node) bool

IsDeclStmt reports whether a given ast.Node is a declaration statement(*ast.DeclStmt)

func IsDeferStmt

func IsDeferStmt(node ast.Node) bool

IsDeferStmt reports whether a given ast.Node is a defer statement(*ast.DeferStmt)

func IsEllipsis

func IsEllipsis(node ast.Node) bool

IsEllipsis reports whether a given ast.Node is an `...` (ellipsis) (*ast.IsEllipsis).

func IsEmptyStmt

func IsEmptyStmt(node ast.Node) bool

IsEmptyStmt reports whether a given ast.Node is an empty statement(*ast.EmptyStmt)

func IsExpr

func IsExpr(node ast.Node) bool

IsExpr reports whether a given ast.Node is an expression(ast.Expr).

func IsExprStmt

func IsExprStmt(node ast.Node) bool

IsExprStmt reports whether a given ast.Node is an expression statement(*ast.ExprStmt)

func IsForStmt

func IsForStmt(node ast.Node) bool

IsForStmt reports whether a given ast.Node is a for statement(*ast.ForStmt)

func IsFuncDecl

func IsFuncDecl(node ast.Node) bool

IsFuncDecl reports whether a given ast.Node is a function declaration (*ast.FuncDecl).

func IsFuncLit

func IsFuncLit(node ast.Node) bool

IsFuncLit reports whether a given ast.Node is a function literal (*ast.IsFuncLit).

func IsFuncType

func IsFuncType(node ast.Node) bool

IsFuncType reports whether a given ast.Node is a function type (*ast.IsFuncType).

func IsGenDecl

func IsGenDecl(node ast.Node) bool

IsGenDecl reports whether a given ast.Node is a generic declaration (*ast.GenDecl).

func IsGoStmt

func IsGoStmt(node ast.Node) bool

IsGoStmt reports whether a given ast.Node is a go statement(*ast.GoStmt)

func IsIdent

func IsIdent(node ast.Node) bool

IsIdent reports whether a given ast.Node is an identifier (*ast.IsIdent).

func IsIfStmt

func IsIfStmt(node ast.Node) bool

IsIfStmt reports whether a given ast.Node is an if statement(*ast.IfStmt)

func IsImportSpec

func IsImportSpec(node ast.Node) bool

IsImportSpec reports whether a given ast.Node is an import declaration (*ast.ImportSpec).

func IsIncDecStmt

func IsIncDecStmt(node ast.Node) bool

IsIncDecStmt reports whether a given ast.Node is a increment/decrement statement(*ast.IncDecStmt)

func IsIndexExpr

func IsIndexExpr(node ast.Node) bool

IsIndexExpr reports whether a given ast.Node is an index expression (*ast.IsIndexExpr).

func IsInterfaceType

func IsInterfaceType(node ast.Node) bool

IsInterfaceType reports whether a given ast.Node is an interface type (*ast.IsInterfaceType).

func IsKeyValueExpr

func IsKeyValueExpr(node ast.Node) bool

IsKeyValueExpr reports whether a given ast.Node is a (key:value) pair (*ast.IsKeyValueExpr).

func IsLabeledStmt

func IsLabeledStmt(node ast.Node) bool

IsLabeledStmt reports whether a given ast.Node is a label statement(*ast.LabeledStmt)

func IsMapType

func IsMapType(node ast.Node) bool

IsMapType reports whether a given ast.Node is a map type (*ast.IsMapType).

func IsParenExpr

func IsParenExpr(node ast.Node) bool

IsParenExpr reports whether a given ast.Node is a parenthesized expression (*ast.IsParenExpr).

func IsRangeStmt

func IsRangeStmt(node ast.Node) bool

IsRangeStmt reports whether a given ast.Node is a range statement(*ast.RangeStmt)

func IsReturnStmt

func IsReturnStmt(node ast.Node) bool

IsReturnStmt reports whether a given ast.Node is a return statement(*ast.ReturnStmt)

func IsSelectStmt

func IsSelectStmt(node ast.Node) bool

IsSelectStmt reports whether a given ast.Node is a selection statement(*ast.SelectStmt)

func IsSelectorExpr

func IsSelectorExpr(node ast.Node) bool

IsSelectorExpr reports whether a given ast.Node is a selector expression (*ast.IsSelectorExpr).

func IsSendStmt

func IsSendStmt(node ast.Node) bool

IsSendStmt reports whether a given ast.Node is a send to chan statement(*ast.SendStmt)

func IsSliceExpr

func IsSliceExpr(node ast.Node) bool

IsSliceExpr reports whether a given ast.Node is a slice expression (*ast.IsSliceExpr).

func IsStarExpr

func IsStarExpr(node ast.Node) bool

IsStarExpr reports whether a given ast.Node is a star expression(unary "*" or apointer) (*ast.IsStarExpr)

func IsStmt

func IsStmt(node ast.Node) bool

IsStmt reports whether a given ast.Node is a statement(ast.Stmt).

func IsStructType

func IsStructType(node ast.Node) bool

IsStructType reports whether a given ast.Node is a struct type (*ast.IsStructType).

func IsSwitchStmt

func IsSwitchStmt(node ast.Node) bool

IsSwitchStmt reports whether a given ast.Node is a switch statement(*ast.SwitchStmt)

func IsTypeAssertExpr

func IsTypeAssertExpr(node ast.Node) bool

IsTypeAssertExpr reports whether a given ast.Node is a type assert expression (*ast.IsTypeAssertExpr).

func IsTypeSpec

func IsTypeSpec(node ast.Node) bool

IsTypeSpec reports whether a given ast.Node is a type declaration (*ast.TypeSpec).

func IsTypeSwitchStmt

func IsTypeSwitchStmt(node ast.Node) bool

IsTypeSwitchStmt reports whether a given ast.Node is a type switch statement(*ast.TypeSwitchStmt)

func IsUnaryExpr

func IsUnaryExpr(node ast.Node) bool

IsUnaryExpr reports whether a given ast.Node is a unary expression (*ast.IsUnaryExpr).

func IsValueSpec

func IsValueSpec(node ast.Node) bool

IsValueSpec reports whether a given ast.Node is a value declaration (*ast.ValueSpec).

Types

This section is empty.

Jump to

Keyboard shortcuts

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