zeroSteiner / rule-engine

A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
https://zerosteiner.github.io/rule-engine/
BSD 3-Clause "New" or "Revised" License
433 stars 54 forks source link

How to join strings? #34

Closed rwspielman closed 2 years ago

rwspielman commented 2 years ago

Hey Spencer (and community),

Is it possible to join strings? I've tried the obvious method of 'a'+'b' but that results in datatype mismatch from this func https://github.com/zeroSteiner/rule-engine/blob/1d84d5599fe5ab34bc8d6fc00bbe00f847352428/lib/rule_engine/ast.py#L373-L378

Couldn't find any custom operators for text joining. Happy to submit a PR if there is no way to do this currently. Strategy would be to remove operator.add from this class into its own, changing the validation method to either combination of string and string or num and num https://github.com/zeroSteiner/rule-engine/blob/1d84d5599fe5ab34bc8d6fc00bbe00f847352428/lib/rule_engine/ast.py#L369-L386

zeroSteiner commented 2 years ago

Yeah I don't think string concatenation is supported now or ever has been (as in this isn't a regression). You're right about the way it'd be implemented would involve creating an AddExpression that inherits from LeftOperatorRightExpressionBase then handling strings and numbers together.

rwspielman commented 2 years ago

@zeroSteiner thanks for the quick reply. I'm gonna work on it this morning and submit a PR shortly