3 ms·
The idea of representing an expression as an abstract syntax tree for interchange is not an inherently bad idea. Trying to shoehorn a general purpose data inter
by bww 5y ago
The idea of representing an expression as an abstract syntax tree for interchange is not an inherently bad idea. Trying to shoehorn a general purpose data interchange format into a highly specialized application like that is a common anti-pattern, however.
When I see this sort of thing (which I assume was inspired by MongoDB's own atrocious "query language") I'm always surprised by the fact that many engineers don't seem to be aware of how easy it is to write a parser that is actually designed for the data you're trying to represent. At least "easy" in the context of undertaking a project that is attempting to generalize this exact problem.
JSON is a fine interchange format until you need a specialized runtime to evaluate the data, which is what is happening here. At that point there's zero benefit to using a general purpose interchange format just because it already exists: just write a DSL.
A good place to start: https://www.antlr.org/ https://www.antlr.org/