Documentation
¶
Overview ¶
Package astflat provides flat-AST navigation primitives that are general across rule and analyzer packages: call/navigation/argument decomposition, scope-walk helpers, condition-operand iteration. It depends only on the scanner package.
This is the foundation tier between scanner (raw flat AST) and the higher-level analyzers (nullflow, future control/dataflow packages, etc.). Helpers that operate purely on AST shape — without semantic interpretation — belong here.
Helpers that need rule-package context (config, metadata, registries) do NOT belong here. Helpers that interpret AST shape semantically (e.g. "is this a logging call?", "is this a Compose modifier?") belong in their own analyzer packages, not in astflat.
Index ¶
- func AllConditionOperands(file *scanner.File, idx uint32, predicate func(uint32) bool) bool
- func AnyConditionOperand(file *scanner.File, idx uint32, predicate func(uint32) bool) bool
- func CallExpressionName(file *scanner.File, idx uint32) string
- func CallExpressionParts(file *scanner.File, idx uint32) (navExpr uint32, args uint32)
- func CallNameAny(file *scanner.File, idx uint32) string
- func CallSuffixValueArgs(file *scanner.File, suffix uint32) uint32
- func EnclosingAncestor(file *scanner.File, idx uint32, types ...string) (uint32, bool)
- func ExtractIdentifier(file *scanner.File, idx uint32) string
- func FinalSimpleIdentifier(file *scanner.File, idx uint32) string
- func HasValueArgumentLabel(file *scanner.File, arg uint32) bool
- func IfConditionThenElseBodies(file *scanner.File, node uint32) (condition, thenBody, elseBody uint32)
- func IsNullLiteral(file *scanner.File, idx uint32) bool
- func LastNamedChild(file *scanner.File, idx uint32) uint32
- func NavigationExpressionLastIdentifier(file *scanner.File, idx uint32) string
- func NavigationExpressionReceiver(file *scanner.File, nav uint32) uint32
- func NavigationLastSuffixHasSafeAccess(file *scanner.File, nav uint32) bool
- func NodeWithin(file *scanner.File, container, node uint32) bool
- func PositionalValueArgument(file *scanner.File, args uint32, index int) uint32
- func PrefixExpressionIsNot(file *scanner.File, idx uint32) bool
- func SingleValueArgumentExpression(file *scanner.File, args uint32) (uint32, bool)
- func UnwrapParenExpr(file *scanner.File, idx uint32) uint32
- func ValueArgumentExpression(file *scanner.File, arg uint32) uint32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllConditionOperands ¶
AllConditionOperands returns true if at least one named child exists and every named child satisfies the predicate.
func AnyConditionOperand ¶
AnyConditionOperand returns true if any named child of idx satisfies the predicate.
func CallExpressionName ¶
CallExpressionName returns the rightmost identifier name of a call_expression's callee — either the simple_identifier or, for navigation callees, the last identifier in the chain.
func CallExpressionParts ¶
CallExpressionParts splits a call_expression into its navigation_expression (the callee) and value_arguments (the args). Either return value may be 0 when absent or when the call uses a trailing-lambda only.
func CallNameAny ¶
CallNameAny is like CallExpressionName but also handles the trailing-lambda idiom where tree-sitter wraps `name(args) { body }` in an outer call_expression whose first child is the inner `name(args)` call.
func CallSuffixValueArgs ¶
CallSuffixValueArgs returns the value_arguments child of a call_suffix node, or 0.
func EnclosingAncestor ¶
EnclosingAncestor returns the closest ancestor of idx whose type matches any of the given types, or (0, false) if none exists.
func ExtractIdentifier ¶
ExtractIdentifier returns the identifier of a declaration node — function, class, parameter, property, or variable_declaration — by finding its first named simple_identifier / type_identifier child. Returns "" when no such child exists.
func FinalSimpleIdentifier ¶
FinalSimpleIdentifier returns the identifier text at the end of a navigation chain or directly_assignable_expression — the rightmost simple_identifier reachable by walking named children. For `w.settings.javaScriptEnabled` this returns `javaScriptEnabled`.
func HasValueArgumentLabel ¶
HasValueArgumentLabel reports whether a value_argument has a named label (either via value_argument_label child or `name = ...` shape).
func IfConditionThenElseBodies ¶
func IfConditionThenElseBodies(file *scanner.File, node uint32) (condition, thenBody, elseBody uint32)
IfConditionThenElseBodies decomposes an if_expression into its condition, then-body, and (optional) else-body nodes. Tolerates the various brace / keyword shapes the tree-sitter Kotlin grammar emits.
func IsNullLiteral ¶
IsNullLiteral reports whether the (parenthesis-unwrapped) idx is the `null` literal.
func LastNamedChild ¶
LastNamedChild returns the last named child of idx, or 0.
func NavigationExpressionLastIdentifier ¶
NavigationExpressionLastIdentifier returns the rightmost simple_identifier reachable inside a navigation_expression. For `a.b.c` this returns "c". Skips over value-arguments / lambda-literal / string-literal subtrees so argument identifiers don't shadow the actual callee name.
func NavigationExpressionReceiver ¶
NavigationExpressionReceiver returns the receiver (first named child) of a navigation_expression, or 0 if the node is malformed.
func NavigationLastSuffixHasSafeAccess ¶
NavigationLastSuffixHasSafeAccess reports whether the trailing navigation_suffix uses safe-call (`?.`) rather than `.`.
func NodeWithin ¶
NodeWithin reports whether `node` is a descendant of `container` (or the same node).
func PositionalValueArgument ¶
PositionalValueArgument returns the index-th positional (unlabeled) argument from a value_arguments list, or 0 if absent.
func PrefixExpressionIsNot ¶
PrefixExpressionIsNot reports whether a prefix_expression has the `!` operator (logical not).
func SingleValueArgumentExpression ¶
SingleValueArgumentExpression returns the lone value_argument expression in args, or (0, false) if the args list contains zero or more than one argument.
func UnwrapParenExpr ¶
UnwrapParenExpr peels parenthesized_expression layers off idx, returning the innermost wrapped expression (or idx itself when not parenthesized).
Types ¶
This section is empty.