neos / flow-development-collection

The unified repository containing the Flow core packages, used for Flow development.
https://flow.neos.io/
MIT License
137 stars 189 forks source link

Eel Null Coalescing Operator #2723

Open mhsdesign opened 2 years ago

mhsdesign commented 2 years ago

Description

Currently one often needs to write the following code in fusion eel:

{foo != null ? foo : bar}

in php this could be better written like

$foo ?? $bar;

im proposing to implement this Null Coalescing Operator in eel:

{foo ?? bar}

The eel parser https://github.com/neos/flow-development-collection/blob/68321067e83dc82702d266f6b27b4f4afad54186/Neos.Eel/Resources/Private/Grammar/Eel.peg.inc#L43 and the CompilingEelParser https://github.com/neos/flow-development-collection/blob/68321067e83dc82702d266f6b27b4f4afad54186/Neos.Eel/Classes/CompilingEelParser.php#L293 should be extended. (Those snippets show the ternary eel)

I would not implement this in the InterpretedEelParser.php as this one is not used and should probably be removed.

jonnitto commented 2 years ago

I think you mean {foo != null ? foo : bar} in your example

mhsdesign commented 2 years ago

btw concerning fusion woulndt this be cool?

path ??= 'hello'

->

path.@process.nullCoalescing = ${value ?? 'hello'}

edit: this was more of a Schnapsidee as it makes things less transparent and harder to learn