RFC: Short array synthax for Fusion


(Dominique Feyer) #1

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 ?

(Karsten Dambekalns) #2

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…


(Dominique Feyer) #3

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


(Martin Ficzel) #4

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.


(Dominique Feyer) #5

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 …


(Martin Ficzel) #6

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.