cel-rust icon indicating copy to clipboard operation
cel-rust copied to clipboard

The library cannot handle "3-1"?

Open leojay opened this issue 1 year ago • 1 comments

My code:

use cel_interpreter::Program;


fn main() {
    Program::compile("3-1").unwrap();
}

I expect this code to run without any issue, but the actual result:

$ cargo run
   Compiling pubsub v0.1.0 (/home/user/test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.48s
     Running `target/debug/test`
thread 'main' panicked at src/main.rs:5:29:
called `Result::unwrap()` on an `Err` value: ParseError { msg: "unrecognized token: '-1'", expected: ["\"!=\"", "\"%\"", "\"&&\"", "\"*\"", "\"+\"", "\"-\"", "\".\"", "\"/\"", "\"<\"", "\"<=\"", "\"==\"", "\">\"", "\">=\"", "\"?\"", "\"[\"", "\"in\"", "\"{\"", "\"||\""], span: Span { start: Some(Location { line: 0, column: 1, absolute: 1 }), end: Some(Location { line: 0, column: 3, absolute: 3 }) } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

leojay avatar Dec 23 '24 20:12 leojay

Yes, it might be that the CEL parser is not handling the '-' sign properly.

Masterlvng avatar Dec 25 '24 07:12 Masterlvng

Should be resolved by #136

clarkmcc avatar Jun 10 '25 23:06 clarkmcc

#136 does indeed fix this. Looks like a parser issue indeed, now the resulting AST:

_-_(
    3^#1:*expr.Constant_Int64Value#,
    1^#3:*expr.Constant_Int64Value#
)^#2:*expr.Expr_CallExpr#

alexsnaps avatar Jun 11 '25 09:06 alexsnaps