1818
1919import com .google .common .base .Ascii ;
2020import com .google .common .collect .ImmutableList ;
21+ import com .google .common .collect .ImmutableSet ;
22+ import com .google .protobuf .Descriptors .FileDescriptor ;
2123import dev .cel .common .CelValidationException ;
2224import dev .cel .common .types .CelType ;
2325import dev .cel .common .types .CelTypes ;
4345/** Interactive REPL shell for CEL formal verification. */
4446final class CelVerifierRepl {
4547
46- private static final VerificationOptions DEFAULT_OPTIONS = VerificationOptions .builder ().build ();
47-
4848 private CelVerifierRepl () {}
4949
50- static int runInteractiveRepl () {
50+ static int runInteractiveRepl (ImmutableSet < FileDescriptor > fileDescriptors ) {
5151 LineReader lineReader = null ;
5252 BufferedReader fallbackReader = null ;
5353 try {
@@ -60,15 +60,25 @@ static int runInteractiveRepl() {
6060 } catch (Exception e ) {
6161 fallbackReader = new BufferedReader (new InputStreamReader (System .in , UTF_8 ));
6262 }
63- return runReplInternal (lineReader , fallbackReader , System .out , System .err );
63+ return runReplInternal (fileDescriptors , lineReader , fallbackReader , System .out , System .err );
6464 }
6565
66- static int runRepl (BufferedReader reader , PrintStream out , PrintStream err ) {
67- return runReplInternal (null , reader , out , err );
66+ static int runRepl (
67+ ImmutableSet <FileDescriptor > fileDescriptors ,
68+ BufferedReader reader ,
69+ PrintStream out ,
70+ PrintStream err ) {
71+ return runReplInternal (fileDescriptors , null , reader , out , err );
6872 }
6973
7074 private static int runReplInternal (
71- LineReader lineReader , BufferedReader fallbackReader , PrintStream out , PrintStream err ) {
75+ ImmutableSet <FileDescriptor > fileDescriptors ,
76+ LineReader lineReader ,
77+ BufferedReader fallbackReader ,
78+ PrintStream out ,
79+ PrintStream err ) {
80+ VerificationOptions typeOptions =
81+ VerificationOptions .builder ().setFileDescriptors (fileDescriptors ).build ();
7282 out .println ("============================================================" );
7383 out .println (" CEL Verification REPL" );
7484 out .println (" Type :help for commands, :quit to exit." );
@@ -140,7 +150,7 @@ private static int runReplInternal(
140150 err .println (
141151 "Usage: :var <name> <type> (e.g. :var role string, :var scores map<string,int>)" );
142152 } else {
143- handleVarCommand (arg , sessionVars , out , err );
153+ handleVarCommand (arg , typeOptions , sessionVars , out , err );
144154 }
145155 continue ;
146156 }
@@ -209,6 +219,7 @@ private static int runReplInternal(
209219 .setTimeout (Duration .ofSeconds (timeoutSeconds ))
210220 .setComprehensionUnrollLimit (unrollLimit )
211221 .setUnknownIdentifiers (unknownIdentifiers )
222+ .setFileDescriptors (fileDescriptors )
212223 .build ();
213224
214225 try {
@@ -275,15 +286,19 @@ private static int runReplInternal(
275286 }
276287
277288 private static void handleVarCommand (
278- String arg , Map <String , CelType > sessionVars , PrintStream out , PrintStream err ) {
289+ String arg ,
290+ VerificationOptions typeOptions ,
291+ Map <String , CelType > sessionVars ,
292+ PrintStream out ,
293+ PrintStream err ) {
279294 String [] parts = arg .split ("\\ s+" , 2 );
280295 if (parts .length != 2 ) {
281296 err .println ("Usage: :var <name> <type> (e.g. :var role string, :var scores map<string,int>)" );
282297 return ;
283298 }
284299 String name = parts [0 ].trim ();
285300 try {
286- CelType type = DEFAULT_OPTIONS .parseCelType (parts [1 ]);
301+ CelType type = typeOptions .parseCelType (parts [1 ]);
287302 sessionVars .put (name , type );
288303 out .println ("Variable declared: " + name + " : " + CelTypes .format (type ));
289304 } catch (IllegalArgumentException | IllegalStateException e ) {
@@ -324,7 +339,9 @@ private static void printHelp(String topic, PrintStream out) {
324339 out .println (
325340 " - Optional types: optional_type<T> (e.g., optional_type<string>,"
326341 + " optional_type<int>)" );
327- out .println (" - Protobuf types: coming soon" );
342+ out .println (
343+ " - Protobuf types: message and enum names from repl --file_descriptor_set"
344+ + " (enums are int)" );
328345 out .println ();
329346 out .println ("Examples:" );
330347 out .println (" cel-verifier> :var role string" );
0 commit comments