From 5caac47b38240aaabd9cab2534dfd45c648cb849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Varl=C4=B1?= Date: Wed, 14 May 2025 16:28:18 +0200 Subject: [PATCH] Default to Rego v1 in `regorus parse` (#407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Burak Varlı --- README.md | 1 + examples/regorus.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d8c1f5..6aae5f2 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ $ regorus Usage: regorus Commands: + ast Parse a Rego policy and dump AST eval Evaluate a Rego Query lex Tokenize a Rego policy parse Parse a Rego policy diff --git a/examples/regorus.rs b/examples/regorus.rs index 17e8b8e..10bb306 100644 --- a/examples/regorus.rs +++ b/examples/regorus.rs @@ -156,7 +156,7 @@ fn rego_lex(file: String, verbose: bool) -> Result<()> { Ok(()) } -fn rego_parse(file: String) -> Result<()> { +fn rego_parse(file: String, v0: bool) -> Result<()> { use regorus::unstable::*; // Create source. @@ -168,6 +168,11 @@ fn rego_parse(file: String) -> Result<()> { // Create a parser and parse the source. let mut parser = Parser::new(&source)?; + + if !v0 { + parser.enable_rego_v1()?; + } + let ast = parser.parse()?; println!("{ast:#?}"); @@ -257,6 +262,10 @@ enum RegorusCommand { Parse { /// Rego policy file. file: String, + + /// Turn on Rego language v0. + #[arg(long)] + v0: bool, }, } @@ -295,7 +304,7 @@ fn main() -> Result<()> { v0, ), RegorusCommand::Lex { file, verbose } => rego_lex(file, verbose), - RegorusCommand::Parse { file } => rego_parse(file), + RegorusCommand::Parse { file, v0 } => rego_parse(file, v0), RegorusCommand::Ast { file } => rego_ast(file), } }