scanner

package
v0.1.1-beta Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package scanner provides low-level scanning utilities for Go source code. These primitives handle string literals, comments, and bracket balancing while properly skipping over nested constructs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBlockCommentStart

func IsBlockCommentStart(b []byte, i int) bool

IsBlockCommentStart returns true if position i starts a /* comment.

func IsLineCommentStart

func IsLineCommentStart(b []byte, i int) bool

IsLineCommentStart returns true if position i starts a // comment.

func IsStringStart

func IsStringStart(b []byte, i int) bool

IsStringStart returns true if position i starts a string literal (either double-quoted or backtick raw string).

func ScanBalanced

func ScanBalanced(src []byte, open int, openChar, closeChar byte) int

ScanBalanced finds the matching close bracket for the open bracket at position. Generic version supporting any bracket pair. Returns -1 if not found.

func ScanBalancedParen

func ScanBalancedParen(src []byte, open int) int

ScanBalancedParen finds the matching ')' for '(' at position open. Skips over strings and comments. Returns the position of the closing ')', or -1 if not found.

func ScanBlockComment

func ScanBlockComment(src []byte, i int) int

ScanBlockComment advances past a /* */ comment starting at position i. Returns the position after the closing */, or len(src) if unterminated.

func ScanLineComment

func ScanLineComment(src []byte, i int) int

ScanLineComment advances past a // comment starting at position i. Returns the position after the newline (or end of input).

func ScanString

func ScanString(src []byte, i int) int

ScanString advances past a string literal starting at position i. Handles both double-quoted strings (with escape sequences) and backtick raw strings. Returns the position after the closing quote, or len(src) if unterminated.

func SplitTopLevel

func SplitTopLevel(s string) []string

SplitTopLevel splits a string by commas at depth 0, respecting parentheses only. Used for function argument lists where brackets and braces are not relevant.

func SplitTopLevelAny

func SplitTopLevelAny(s string) []string

SplitTopLevelAny splits by commas at depth 0, respecting (), [], and {}. Used when arguments may contain composite literals or array indexing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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