-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This won't allow floats in the following form:
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 commentThe 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 |
||
%token null null | ||
%token comma , | ||
%token name (?:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\\)*[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* | ||
|
||
%token quote_ " -> quoted_string | ||
%token quoted_string:quoted_string (?:[^"]|"")+ | ||
%token quoted_string:quoted_string [^"]+ | ||
%token quoted_string:_quote " -> default | ||
|
||
%token apostrophe_ ' -> apostrophed_string | ||
%token apostrophed_string:apostrophed_string (?:[^']|'')+ | ||
%token apostrophed_string:apostrophed_string [^']+ | ||
%token apostrophed_string:_apostrophe ' -> default | ||
|
||
type: | ||
simple_type() | compound_type() | ||
|
||
#simple_type: | ||
<name> | ||
| <number> | ||
| <null> | ||
| <empty_string> | ||
| ::quote_:: <quoted_string> ::_quote:: | ||
| ::apostrophe_:: <apostrophed_string> ::_apostrophe:: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,30 @@ public function validTypesProvider(): iterable | |
'array<Foo>', | ||
$type('array', [['name' => 'Foo', 'params' => []]]), | ||
]; | ||
yield [ | ||
'Foo<\'a\'>', | ||
$type('Foo', ['a']), | ||
]; | ||
yield [ | ||
'Foo<5>', | ||
$type('Foo', [5]), | ||
]; | ||
yield [ | ||
'Foo<5.5>', | ||
$type('Foo', [5.5]), | ||
]; | ||
yield [ | ||
'Foo<null>', | ||
$type('Foo', [null]), | ||
]; | ||
yield [ | ||
'Foo<\'a\',\'b\',\'c\'>', | ||
$type('Foo', ['a', 'b', 'c']), | ||
]; | ||
yield [ | ||
'Foo<\'a\',\'\'>', | ||
$type('Foo', ['a', '']), | ||
]; | ||
yield [ | ||
'array<Foo,Bar>', | ||
$type('array', [['name' => 'Foo', 'params' => []], ['name' => 'Bar', 'params' => []]]), | ||
|
@@ -72,14 +96,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 commentThe reason will be displayed to describe this comment to others. Learn more. removed this as it will not allow There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
'Foo<"""bar""">', | ||
$type('Foo', ['"bar"']), | ||
]; | ||
yield [ | ||
"Foo<'a''b'>", | ||
$type('Foo', ["a'b"]), | ||
]; | ||
} | ||
|
||
public function testEmptyString(): void | ||
|
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,
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. :)