Skip to content

feat: add named filter arguments and allow_false for default filter#143

Open
osteele wants to merge 1 commit intomainfrom
named-filter-args
Open

feat: add named filter arguments and allow_false for default filter#143
osteele wants to merge 1 commit intomainfrom
named-filter-args

Conversation

@osteele
Copy link
Owner

@osteele osteele commented Feb 27, 2026

Summary

  • Add support for keyword arguments in filter expressions (e.g., {{ val | default: "fallback", allow_false: true }})
  • Keyword arguments are parsed by the yacc grammar and collected into a map[string]any passed as a variadic trailing parameter to filter functions
  • The default filter now accepts allow_false: true to preserve false values instead of replacing them with the default

Closes #42, closes #75

Changes

  • expressions/builders.go: Added filterArgs and keywordArg types
  • expressions/expressions.y: Extended filter_params grammar rule to accept KEYWORD expr pairs; changed union type from []valueFn to *filterArgs
  • expressions/y.go: Regenerated from expressions.y
  • expressions/context.go: Updated Context interface signature for ApplyFilter
  • expressions/filters.go: Updated ApplyFilter to evaluate keyword args into a map[string]any and append as trailing argument
  • expressions/filters_test.go: Updated tests for new filterArgs type; added keyword args test
  • filters/standard_filters.go: Updated default filter to accept variadic kwargs and check for allow_false
  • filters/standard_filters_test.go: Added test cases for allow_false behavior

Test plan

  • All existing tests pass
  • New tests for allow_false: true with false, nil, empty string values
  • New test for keyword arg passthrough via ApplyFilter
  • Existing filter tests updated for new filterArgs type

Add support for keyword arguments in filter expressions (e.g.,
`{{ val | default: "fallback", allow_false: true }}`). Keyword
arguments are collected into a map[string]any and passed as a
variadic trailing parameter to the filter function.

The default filter now accepts an `allow_false` keyword argument
that, when true, preserves false values instead of replacing them
with the default.

Closes #42, closes #75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please support allow_false feature Add support for named filter arguments

1 participant