annotations icon indicating copy to clipboard operation
annotations copied to clipboard

Parser does not distinguish between annotated arrays and repeated annotations

Open rwilczek opened this issue 9 years ago • 2 comments

The current version of the annotation-parser does not tell between a single JSON-array and multiple simple annotations. But it should!

$parser = new \Minime\Annotations\Parser;
$this->assertNotSame(
    $parser->parse('@foo 1 @foo 2 @foo 3'),
    $parser->parse('@foo [1, 2, 3]')
); // FAIL. Parser errorneously gives the same result for both strings

$this->assertSame(
    ['foo' => [1, 2, 3]],
    $parser->parse('@foo 1 @foo 2 @foo 3') 
); // PASS. Parser works correctly on this

$this->assertSame(
    ['foo' => [[1, 2, 3]]],
    $parser->parse('@foo [1, 2, 3]') 
); // FAIL. Parser fails to preserve the array annotated with @foo

rwilczek avatar Feb 20 '17 11:02 rwilczek

Hi!

That was actually intentional from the very beginning to consider, by default, that repeated annotations form an array of values and arrays are merged if identified with the same identifier.

It's totally possible to introduce a new Parser featuring the distinction, or even add an optional parameter into the existing default parser.

Pull requests are welcome!

marcioAlmada avatar Apr 20 '17 00:04 marcioAlmada

On v4 this could be adopted as a default behavior. I agree that it would be more intuitive and less ambiguous.

marcioAlmada avatar Apr 20 '17 00:04 marcioAlmada