-
-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow empty strings and numbers as metadata type parameters #1019
Conversation
0a80f3d
to
93eecd5
Compare
@@ -72,14 +92,6 @@ public function validTypesProvider(): iterable | |||
'Foo<"asdf asdf">', | |||
$type('Foo', ['asdf asdf']), | |||
]; | |||
yield [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed this as it will not allow ''
(empty strings syntax) and was not available in the 1.x parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can guess, what you were trying to do here was handled by YAML
@@ -2,22 +2,28 @@ | |||
|
|||
%token parenthesis_ < | |||
%token _parenthesis > | |||
%token empty_string ""|'' | |||
%token number (\+|\-)?(0|[1-9]\d*)(\.\d+)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't allow floats in the following form: .123
Should be written as something similar:
[+-]?(?:(?:0|[1-9]\d*(?:\.0*[1-9]\d*)?)|\.0*\d*[1-9])
https://regex101.com/r/Nadose/1
Also this doesn't handle exponential floats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. My goal was to solve the reported bug. A more complete implementation is welcome
@@ -2,22 +2,28 @@ | |||
|
|||
%token parenthesis_ < | |||
%token _parenthesis > | |||
%token empty_string ""|'' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks weird, I think this should be handled as part of strings themselves, meaning that they will no longer be a single token but a node instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the only way I found to make it work with empty strings.
Better solutions are welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make the inner token optional in simple_type (<quoted_string>?
and <apostrophed_string>?
), it will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried right now,
1) JMS\Serializer\Tests\Serializer\Type\ParserTest::testParse with data set #7 ('Foo<'a',''>', array('Foo', array('a', '')))
Error: Call to a member function getValueToken() on null
/home/goetas/projects/serializer/src/Type/TypeVisitor.php:36
/home/goetas/projects/serializer/src/Type/TypeVisitor.php:22
/home/goetas/projects/serializer/vendor/hoa/compiler/Llk/TreeNode.php:333
/home/goetas/projects/serializer/src/Type/TypeVisitor.php:69
/home/goetas/projects/serializer/src/Type/TypeVisitor.php:71
/home/goetas/projects/serializer/src/Type/TypeVisitor.php:24
/home/goetas/projects/serializer/src/Type/Parser.php:30
/home/goetas/projects/serializer/tests/Serializer/Type/ParserTest.php:29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, you made the token optional (nullable), so the visitor needs to be updated accordingly. :)
@Majkl578 do you mind having a look at this?