filter

package
v0.0.0-...-ebade47 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: GPL-3.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package filter provides generic attribute-based filtering of requirements using expr-lang/expr as the evaluation engine.

A filter expression is compiled once at startup into bytecode, then evaluated against each requirement's attribute map. The evaluation context exposes every attribute from the req's attr block plus the built-in variables `id` and `title` (and the RFC built-in attributes `status`, `disposition`, `trace`, `version`, which resolve to nil when a requirement does not declare them).

Compile-time validation rejects expressions that reference attribute names not declared in any document's schema.yaml (a global typo check), and reports expr syntax errors once before any requirement is evaluated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFoundAttrs

func BuildFoundAttrs(docs []model.Document) map[string]struct{}

BuildFoundAttrs computes the union of every attribute key actually present on some requirement in the tree, whether or not it is declared in a schema.yaml. Relaxed filtering unions this with BuildValidAttrs so undeclared-but-present attributes can be filtered.

func BuildValidAttrs

func BuildValidAttrs(docs []model.Document) map[string]struct{}

BuildValidAttrs computes the union of all schema property names across every document plus the built-in variable names. The result is used by Compile for strict attribute validation.

func WriteWarnings

func WriteWarnings(w io.Writer, warnings []string)

WriteWarnings writes relaxed-mode filter warnings to w, one per line, prefixed with "reqmd: warning: ". It is a no-op when warnings is empty so callers can invoke it unconditionally.

Types

type Filter

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

Filter is a compiled attribute filter expression. It is safe for concurrent use after construction — the underlying vm.Program is read-only.

func Compile

func Compile(exprStr string, validAttrs map[string]struct{}) (*Filter, error)

Compile parses, validates, and compiles a filter expression (strict mode).

validAttrs is the union of all schema property names (plus built-in variable names) across every document in the tree. Referencing a name not in this set is a compile-time ERROR — this catches typos and references to attributes that no document declares.

The expression is compiled with AllowUndefinedVariables so that a requirement whose document does not declare a referenced attribute evaluates that variable to nil (the req is excluded unless the expression handles absence, e.g. `variant == null`).

func CompileForDocs

func CompileForDocs(docs []model.Document, expr string, allowUndeclared bool) (*Filter, []string, error)

CompileForDocs compiles an expression against the attribute union of the given documents. It is the shared entry point for every CLI command that accepts a --filter flag: Compile + BuildValidAttrs in one call.

When allowUndeclared is false the strict typo check applies and any reference to an attribute not declared in a schema.yaml is an error. When true, references to attributes found on any requirement are allowed (undeclared-but-present) and every out-of-schema reference is returned as a warning instead of an error. Returns (nil, nil, nil) when expr is empty.

func CompileRelaxed

func CompileRelaxed(exprStr string, validAttrs, declaredAttrs map[string]struct{}) (*Filter, []string, error)

CompileRelaxed compiles a filter expression without hard-failing on attribute names that are not declared in any schema.yaml. validAttrs is the expanded allowed set (schema-declared names plus every attribute actually found on a requirement); declaredAttrs is the schema-declared set plus built-ins and drives which references produce a warning. Every referenced name outside declaredAttrs yields a warning instead of an error, so undeclared-but-present attributes become filterable while true typos no longer abort the run.

func (*Filter) Expr

func (f *Filter) Expr() string

Expr returns the original expression string.

func (*Filter) FilterDocs

func (f *Filter) FilterDocs(docs []model.Document) ([]model.Document, error)

FilterDocs returns a new []model.Document containing only matching requirements per document. Non-requirement nodes (containers and info items) are always kept, so document structure and content survive filtering. Documents with all requirements filtered out are kept (with only items) so document-level structure is preserved for list/stats/ export output.

func (*Filter) Match

func (f *Filter) Match(node *model.Node) (bool, error)

Match evaluates the compiled expression against a single requirement. Returns (true, nil) if the requirement matches, (false, nil) if not, and (false, err) if evaluation fails (e.g. type mismatch).

func (*Filter) MatchingIDs

func (f *Filter) MatchingIDs(docs []model.Document) (map[string]struct{}, error)

MatchingIDs returns a set of requirement IDs that match the filter. Used by check/serve for filter-aware graph checks — the graph is built from the full tree, but only matching reqs are checked/reported.

func (*Filter) Refs

func (f *Filter) Refs() []string

Refs returns the sorted, deduplicated list of variable names referenced in the expression (excluding expr built-in functions).

Jump to

Keyboard shortcuts

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