4343import dev .cel .common .types .OptionalType ;
4444import dev .cel .common .types .SimpleType ;
4545import dev .cel .common .types .TypeParamType ;
46+ import dev .cel .common .types .TypeType ;
4647import dev .cel .compiler .CelCompiler ;
4748import dev .cel .compiler .CelCompilerBuilder ;
4849import dev .cel .compiler .CelCompilerLibrary ;
@@ -71,38 +72,37 @@ public abstract class CelEnvironment {
7172 "math" , CanonicalCelExtension .MATH ,
7273 "optional" , CanonicalCelExtension .OPTIONAL ,
7374 "protos" , CanonicalCelExtension .PROTOS ,
75+ "regex" , CanonicalCelExtension .REGEX ,
7476 "sets" , CanonicalCelExtension .SETS ,
7577 "strings" , CanonicalCelExtension .STRINGS ,
76- "comprehensions" , CanonicalCelExtension .COMPREHENSIONS );
78+ "two-var- comprehensions" , CanonicalCelExtension .COMPREHENSIONS );
7779
7880 private static final ImmutableMap <String , ObjIntConsumer <CelOptions .Builder >> LIMIT_HANDLERS =
7981 ImmutableMap .of (
8082 "cel.limit.expression_code_points" ,
81- ( options , value ) -> options . maxExpressionCodePointSize ( value ) ,
83+ CelOptions . Builder :: maxExpressionCodePointSize ,
8284 "cel.limit.parse_error_recovery" ,
83- ( options , value ) -> options . maxParseErrorRecoveryLimit ( value ) ,
85+ CelOptions . Builder :: maxParseErrorRecoveryLimit ,
8486 "cel.limit.parse_recursion_depth" ,
85- ( options , value ) -> options . maxParseRecursionDepth ( value ) );
87+ CelOptions . Builder :: maxParseRecursionDepth );
8688
8789 private static final ImmutableMap <String , BooleanOptionConsumer > FEATURE_HANDLERS =
8890 ImmutableMap .of (
8991 "cel.feature.macro_call_tracking" ,
90- ( options , enabled ) -> options . populateMacroCalls ( enabled ) ,
92+ CelOptions . Builder :: populateMacroCalls ,
9193 "cel.feature.backtick_escape_syntax" ,
92- ( options , enabled ) -> options . enableQuotedIdentifierSyntax ( enabled ) ,
94+ CelOptions . Builder :: enableQuotedIdentifierSyntax ,
9395 "cel.feature.cross_type_numeric_comparisons" ,
94- ( options , enabled ) -> options . enableHeterogeneousNumericComparisons ( enabled ) );
96+ CelOptions . Builder :: enableHeterogeneousNumericComparisons );
9597
9698 /** Environment source in textual format (ex: textproto, YAML). */
9799 public abstract Optional <Source > source ();
98100
99101 /** Name of the environment. */
100102 public abstract String name ();
101103
102- /**
103- * Container, which captures default namespace and aliases for value resolution.
104- */
105- public abstract CelContainer container ();
104+ /** Container, which captures default namespace and aliases for value resolution. */
105+ public abstract Optional <CelContainer > container ();
106106
107107 /**
108108 * An optional description of the environment (example: location of the file containing the config
@@ -226,7 +226,6 @@ public static Builder newBuilder() {
226226 return new AutoValue_CelEnvironment .Builder ()
227227 .setName ("" )
228228 .setDescription ("" )
229- .setContainer (CelContainer .ofName ("" ))
230229 .setVariables (ImmutableSet .of ())
231230 .setFunctions (ImmutableSet .of ())
232231 .setFeatures (ImmutableSet .of ())
@@ -242,7 +241,6 @@ public CelCompiler extend(CelCompiler celCompiler, CelOptions celOptions)
242241 CelCompilerBuilder compilerBuilder =
243242 celCompiler
244243 .toCompilerBuilder ()
245- .setContainer (container ())
246244 .setOptions (celOptions )
247245 .setTypeProvider (celTypeProvider )
248246 .addVarDeclarations (
@@ -254,6 +252,8 @@ public CelCompiler extend(CelCompiler celCompiler, CelOptions celOptions)
254252 .map (f -> f .toCelFunctionDecl (celTypeProvider ))
255253 .collect (toImmutableList ()));
256254
255+ container ().ifPresent (compilerBuilder ::setContainer );
256+
257257 addAllCompilerExtensions (compilerBuilder , celOptions );
258258
259259 applyStandardLibrarySubset (compilerBuilder );
@@ -416,6 +416,8 @@ public abstract static class VariableDecl {
416416 /** The type of the variable. */
417417 public abstract TypeDecl type ();
418418
419+ public abstract Optional <String > description ();
420+
419421 /** Builder for {@link VariableDecl}. */
420422 @ AutoValue .Builder
421423 public abstract static class Builder implements RequiredFieldsChecker {
@@ -428,6 +430,8 @@ public abstract static class Builder implements RequiredFieldsChecker {
428430
429431 public abstract VariableDecl .Builder setType (TypeDecl typeDecl );
430432
433+ public abstract VariableDecl .Builder setDescription (String name );
434+
431435 @ Override
432436 public ImmutableList <RequiredField > requiredFields () {
433437 return ImmutableList .of (
@@ -459,6 +463,8 @@ public abstract static class FunctionDecl {
459463
460464 public abstract String name ();
461465
466+ public abstract Optional <String > description ();
467+
462468 public abstract ImmutableSet <OverloadDecl > overloads ();
463469
464470 /** Builder for {@link FunctionDecl}. */
@@ -471,6 +477,8 @@ public abstract static class Builder implements RequiredFieldsChecker {
471477
472478 public abstract FunctionDecl .Builder setName (String name );
473479
480+ public abstract FunctionDecl .Builder setDescription (String description );
481+
474482 public abstract FunctionDecl .Builder setOverloads (ImmutableSet <OverloadDecl > overloads );
475483
476484 @ Override
@@ -519,6 +527,9 @@ public abstract static class OverloadDecl {
519527 /** List of function overload type values. */
520528 public abstract ImmutableList <TypeDecl > arguments ();
521529
530+ /** Examples for the overload. */
531+ public abstract ImmutableList <String > examples ();
532+
522533 /** Return type of the overload. Required. */
523534 public abstract TypeDecl returnType ();
524535
@@ -537,8 +548,21 @@ public abstract static class Builder implements RequiredFieldsChecker {
537548 // This should stay package-private to encourage add/set methods to be used instead.
538549 abstract ImmutableList .Builder <TypeDecl > argumentsBuilder ();
539550
551+ abstract ImmutableList .Builder <String > examplesBuilder ();
552+
540553 public abstract OverloadDecl .Builder setArguments (ImmutableList <TypeDecl > args );
541554
555+ @ CanIgnoreReturnValue
556+ public OverloadDecl .Builder addExamples (Iterable <String > examples ) {
557+ this .examplesBuilder ().addAll (checkNotNull (examples ));
558+ return this ;
559+ }
560+
561+ @ CanIgnoreReturnValue
562+ public OverloadDecl .Builder addExamples (String ... examples ) {
563+ return addExamples (Arrays .asList (examples ));
564+ }
565+
542566 @ CanIgnoreReturnValue
543567 public OverloadDecl .Builder addArguments (Iterable <TypeDecl > args ) {
544568 this .argumentsBuilder ().addAll (checkNotNull (args ));
@@ -667,6 +691,10 @@ public CelType toCelType(CelTypeProvider celTypeProvider) {
667691 CelType keyType = params ().get (0 ).toCelType (celTypeProvider );
668692 CelType valueType = params ().get (1 ).toCelType (celTypeProvider );
669693 return MapType .create (keyType , valueType );
694+ case "type" :
695+ checkState (
696+ params ().size () == 1 , "Expected 1 parameter for type, got %s" , params ().size ());
697+ return TypeType .create (params ().get (0 ).toCelType (celTypeProvider ));
670698 default :
671699 if (isTypeParam ()) {
672700 return TypeParamType .create (name ());
@@ -838,6 +866,7 @@ enum CanonicalCelExtension {
838866 SETS (
839867 (options , version ) -> CelExtensions .sets (options ),
840868 (options , version ) -> CelExtensions .sets (options )),
869+ REGEX ((options , version ) -> CelExtensions .regex (), (options , version ) -> CelExtensions .regex ()),
841870 LISTS ((options , version ) -> CelExtensions .lists (), (options , version ) -> CelExtensions .lists ()),
842871 COMPREHENSIONS (
843872 (options , version ) -> CelExtensions .comprehensions (),
@@ -1054,7 +1083,7 @@ public static OverloadSelector.Builder newBuilder() {
10541083 }
10551084
10561085 @ FunctionalInterface
1057- private static interface BooleanOptionConsumer {
1086+ private interface BooleanOptionConsumer {
10581087 void accept (CelOptions .Builder options , boolean value );
10591088 }
10601089}
0 commit comments