RFC: Short array synthax for Fusion

Question about kind of “short array synthax” for Fusion. We use a lots of RawArray to transport values in our Fusion prototype, but the current synthax with the RawArray is a bit to verbose, what about:

prototype(Your.Package:Foo) {
	label = {
		english = 'foo'
		french = 'bar'
		german = 'bla'
	}
}

and

prototype(Your.Package:Foo) {
       label = [ 'foo', 'bar', 'bla']
}

I know we can use EEL for this, but I think it should be a responsability of Fusion, to have support for things like bellow and better readability for multi level arrays:

prototype(Your.Package:Foo) {
        label = [ Your.Package:FooLabel, Your.Package:BarLabel, Your.Package:BlaLabel ]
}

What do you think about this ?

And if you agree, how to implement this:

  • By extending the parser ?
  • By introducing kind of preprocessor ?
2 Likes

I’m pretty sure this was discussed in the past, but can’t find any issue, PR, Slack message or Discourse post. Hm.

Whatever, the syntax using curly braces you propose leaves no distinction between “an array” and “some Fusion object”. I might be wrong, but I think that was one of the blockers for adding such syntax in the discussion I remember…

Yes I also found nothing

// Fusion object
prototype(Your.Package:Foo) {
    label {
            english = 'foo'
            french = 'bar'
            german = 'bla'
    }
    // or
    label = Neos.Fusion:RawArray {
		english = 'foo'
		french = 'bar'
		german = 'bla'
    }
}

// Array declaration
prototype(Your.Package:Foo) {
	label = {
		english = 'foo'
		french = 'bar'
		german = 'bla'
	}
}

So the equal clearly define it’s a assignment

What would be the internal parsing result of your suggestion? A RawArray fusion-object that is implied by shorthand syntax? I would like that.

I fear that adjusting the FusionParser will not be easy. And with not easy i mean you will likely end up creating a new parser based on PEG like EEL and Fizzle. The existing fusion parser is a glorious bunch of regex expressions and is kind of due for a rewrite. The good thing is that the resulting fusion-ast is quite well defined so it is absolutely possible but far from easy.

1 Like

Yes RawArray

prototype(Your.Package:Foo) {
	label = {
		english = 'foo'
		french = 'bar'
		german = 'bla'
	}
}

Can be done is a pretty ugly way: `label = { is not a valid fusion synthax a nice regex powered replace before parsing the file can make it work.

I agree a rewritte can be nice :wink: but this feature can simplify a lots many fusion files …

1 Like

With really good test coverage i would like this. I consider it important that we do nothing that makes refactoring the fusion parser harder at this time.

i just stubled by by accidently through the search - its a bit late - but you could alias a prototype with prototype(array) < prototype(Neos.Fusion:DataStructure)

value = array {

}

or indeed build a fusion preprocessor by modifying the sourceCode input of fusion/Parser.php at master · neos/fusion (github.com) via AOP (@Flow\Before(“method(Neos\Fusion\Core\Parser->parse())”))

… i saw that here atomic-fusion-constants/ConstantsAspect.php at master · PackageFactory/atomic-fusion-constants (github.com)

The feature already is in Fusion, only slightly modified.

All nested keys inside of Neos.Fusion:DataStructure are interpreted as DataStructure automatically.

See: Neos 5.1 »White Knight« and Flow 6.1 released - Blog - Neos.io → Section Fusion & AFX

1 Like