pathpat

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pathpat compiles and expands sqletch's query-file patterns: project-relative globs with recursive `**` segments and capture groups whose matched text is substituted into a target's output path (docs/design/19-multi-target-output.md §3).

It replaces filepath.Glob for `targets[].queries` for two reasons: filepath.Glob has no `**` (its `**` is just `*` inside one segment, so design 07's advertised `queries/**/*.sql` never worked), and no glob library returns CAPTURES — which would force two engines, one to enumerate and one to capture, that could disagree. One engine both enumerates and captures, so it cannot drift from itself.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxRef

func MaxRef(s string) (int, error)

MaxRef returns the highest $n referenced in s, and 0 when it references none. A malformed reference is an error so a typo (`$x`, a trailing `$`) is not silently emitted as a literal.

func Substitute

func Substitute(s string, captures []string) (string, error)

Substitute replaces $n / ${n} in s with captures[n-1]. It is only called after MaxRef validated the references against the pattern's capture count, so an out-of-range reference here is a programming error and reported as one.

Types

type Match

type Match struct {
	// Path is project-relative and always slash-separated, so a
	// substituted output path is byte-identical on every platform.
	Path string
	// Captures holds one entry per capture group, in order.
	Captures []string
}

Match is one file the pattern matched.

type Pattern

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

Pattern is a compiled query-file pattern.

func Compile

func Compile(pat string) (*Pattern, error)

Compile parses a pattern. Errors are user-facing config messages: the caller wraps them in SQLETCH301 without rephrasing.

func (*Pattern) NumCaptures

func (p *Pattern) NumCaptures() int

NumCaptures reports how many capture groups the pattern declares.

func (*Pattern) String

func (p *Pattern) String() string

String returns the pattern as written.

func (*Pattern) Walk

func (p *Pattern) Walk(root string) (Result, error)

Walk expands the pattern against root, returning matches sorted by path. Directory symlinks are followed at most once each (a resolved path visited set), so a symlink cycle terminates; whether a matched path is ACCEPTABLE — inside the project, not reached through an escaping symlink — is the caller's SQLETCH306 check, not this package's.

type Result

type Result struct {
	// Matches is sorted by Path.
	Matches []Match
	// Dirs lists every directory the walk consulted, project-relative
	// and slash-separated. It is the LSP's memo signature (§6): a
	// directory's mtime changes when an entry is added or removed, so
	// re-stating these detects a file appearing or disappearing
	// without re-walking the tree.
	Dirs []string
}

Result is one expansion of a pattern against a project directory.

Jump to

Keyboard shortcuts

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