ast

package
v0.0.0-...-af88cc4 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ast provides AST parsing and inspection utilities for Go source code.

Package ast provides AST parsing and inspection utilities for Go source code.

Package ast provides AST parsing and inspection utilities for Go source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenStringExprAST

func FlattenStringExprAST(e ast.Expr) (string, bool)

FlattenStringExprAST recursively extracts string content from an expression tree consisting of string literals and binary '+' operations. This is the AST version that takes an already-parsed expression.

func HasNestedCall

func HasNestedCall(s string) bool

HasNestedCall returns true if any argument of the call expression is itself a call expression or contains a call expression in parentheses.

func IsCallExpr

func IsCallExpr(s string) bool

IsCallExpr returns true if s parses as a function call expression. Also matches parenthesized call expressions like (fn()).

func IsCompositeLit

func IsCompositeLit(s string) bool

IsCompositeLit returns true if s parses as a composite literal. Also matches parenthesized composite literals like (T{}).

func ParseExpr

func ParseExpr(s string) ast.Expr

ParseExpr parses s as a Go expression. Returns nil if parsing fails.

Types

type OffsetSpan

type OffsetSpan struct {
	Start int
	End   int
}

OffsetSpan is a half-open interval [Start, End) in byte offsets.

type OffsetSpanSet

type OffsetSpanSet struct {
	// contains filtered or unexported fields
}

OffsetSpanSet is a sorted, non-overlapping set of spans.

func NewOffsetSpanSet

func NewOffsetSpanSet(spans []OffsetSpan) OffsetSpanSet

func OwnedSpansFromAST

func OwnedSpansFromAST(file *ast.File, fset *token.FileSet, src []byte,
	opts OwnedSpanOptions) OffsetSpanSet

func OwnedSpansFromSource

func OwnedSpansFromSource(src []byte, opts OwnedSpanOptions) OffsetSpanSet

func (OffsetSpanSet) Contains

func (s OffsetSpanSet) Contains(off int) bool

Contains returns true if off falls inside any span in the set.

func (OffsetSpanSet) Overlaps

func (s OffsetSpanSet) Overlaps(start, end int) bool

Overlaps reports whether any span in the set intersects the half-open interval [start, end). Intervals where end <= start are treated as empty and never overlap.

func (OffsetSpanSet) Union

func (s OffsetSpanSet) Union(other OffsetSpanSet) OffsetSpanSet

Union returns a new set that contains all spans from s and other.

type OwnedSpanOptions

type OwnedSpanOptions struct {
	IncludeCallArgLists    bool
	IncludeCallExprs       bool
	IncludeCompositeBodies bool
	IncludeFuncBodies      bool
}

Jump to

Keyboard shortcuts

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