ITADN

[Question] Is it possible to define custom infix notation macros?

#939OpenTargaseer 创建于 2026-02-05
T
Targaseercommented
Hello, Is it possible in CEL Java to create custom macro/function with infix notation (\_!=\_) and special symbols in name similar to built-in operators "!=", "&&", etc. and "in" function? I want to implement the Elvis operator https://en.wikipedia.org/wiki/Elvis_operator as a shortcut to default conditional "\_?\_:\_" with some custom checks for left operand. I've made a custom macro with desired logic and provided it to the CelCompiler using [addMacros](https://github.com/google/cel-java/blob/026cae62c0dcfe2afbbc61fb4475fc3f867ed662/compiler/src/main/java/dev/cel/compiler/CelCompilerBuilder.java#L58) method in builder, but it currently looks like a function call: `elvis(base.dict.param, "default")`. And it transforms the AST to this: `base.dict.param !=null ? base.dict.param : "default"`. I want to make it look like that: `base.dict.param ?: "default"` instead of `elvis(..., ...)`. Is it possible to do? Thanks.
0 条评论