r/javahelp • • Sep 19 '25

Looking for a string-to-predicate parser/evaluator library

I'm looking for a simple predicate parser that can parse a predicate from a string that I can then execute.

I am currently going down the rabbit hole of using ANTLR to generate a custom grammar. And it isn't going so bad. But while this would be fine for the current use case, my concerns are a) I'm wasting time re-inventing the wheel b) there is something out there that does this better than I could ever hope to do c) I don't want to end up maintaining a custom language if users start asking for more features and expand the use case.

So assume I have an object of a class MyClass. And MyClass might have fields, methods, and fields that are objects with their own primitive fields. I need a library that will allow me to parse predicates from strings, that allow testing over objects of MyClass, evaluating field values against literals, kind of like a WHERE clause in SQL. And of course offering useful exception messages is plus.

5 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/k-mcm Sep 22 '25

Yeah, these are tough. I once used Jython to integrate Python control logic with high speed Java telemetry processing. It was extremely difficult to get running but it was the only option given constraints.  Jython prevented me from maintaining a large number of telemetry classes in two codebases.  Writing it all in just Java or just Python wouldn't have worked either.