From 60380f8cf9d20d8381c1fed7f635c5f156ee6711 Mon Sep 17 00:00:00 2001 From: Tony Holdstock-Brown Date: Thu, 4 Jan 2024 18:51:34 -0800 Subject: [PATCH] Comments --- caching_parser.go | 2 -- lift.go | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/caching_parser.go b/caching_parser.go index a833c31..54d65bf 100644 --- a/caching_parser.go +++ b/caching_parser.go @@ -10,8 +10,6 @@ import ( var ( CacheTime = time.Hour - - replace = []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"} ) // NewCachingParser returns a CELParser which lifts quoted literals out of the expression diff --git a/lift.go b/lift.go index 47e18f0..ba594f4 100644 --- a/lift.go +++ b/lift.go @@ -6,11 +6,25 @@ import ( "strings" ) +const ( + // VarPrefix is the lifted variable name used when extracting idents from an + // expression. + VarPrefix = "vars." +) + +var ( + // replace is truly hack city. these are 20 variable names for values that are + // lifted out of expressions via liftLiterals. + replace = []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"} +) + // LiftedArgs represents a set of variables that have been lifted from expressions and // replaced with identifiers, eg `id == "foo"` becomes `id == vars.a`, with "foo" lifted // as "vars.a". type LiftedArgs interface { + // Get a lifted variable argument from the parsed expression. Get(val string) (any, bool) + // Return all lifted variables as a map. Map() map[string]any }