Jemt / SitemagicCMS

Sitemagic CMS - world's most beautiful Content Management System
http://sitemagic.org
Other
16 stars 12 forks source link

Expressions - JS vs PHP evaluator - incompatibility #118

Open Jemt opened 5 years ago

Jemt commented 5 years ago

Expressions in JSShop must be compatible with both JS and PHP.

Currently we have a problem with string concat. PHP: $val = $str1 . $str2 for strings, $val = $int1 + $int2 for numeric values. vs JS val = str1 + str2 for strings AND numeric values.

The expression engine takes care of "transpiling" from JS syntax to PHP which is fairly easy for identifiers (str1 => $str1), but determining whether to use . (dot) or + (plus) is more difficult.

Also, JS' ternary operator is right-associative (like all sane languages) while PHP's is left-associative: https://stackoverflow.com/questions/20559150/ternary-operator-left-associativity

image

While we can construct the short-hand conditional expression in a way that works with both JS and PHP, inconsistency is not acceptable.

We might have to disable support for generic expressions, and enforce use of functions to do even simple things - e.g.:

JSShop.Add(a:numeric, b:numeric)
JSShop.Substract(a:numeric, b:numeric)
JSShop.Multiply(a:numeric, b:numeric)
JSShop.Concat(str1:object, str2:object)

JSShop.Concat("Result: ", JSShop.Multiply(JSShop.Add(a, b), 3.14))