Skip to content

DelimitedList method for Node only elements #104

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

Closed
wants to merge 1 commit into from

Conversation

runz0rd
Copy link
Contributor

@runz0rd runz0rd commented Feb 13, 2017

For #6

@msftclas
Copy link

Hi @runz0rd, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
We will now validate the agreement and then real humans will evaluate your PR.

TTYL, MSBOT;

Copy link
Contributor

@mousetraps mousetraps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Left some comments and +1 after that!

It would also be good to add a test for this behavior to NodeApiTest.php (mock object is probably the way to go.)

$listElements = [];
foreach ($this->children as $child) {
if($child instanceof Node) {
$listElements[] = $child;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach won't work for DelimitedList\QualifiedNameParts or DelimitedList\ExpressionList, which both have the possibility of producing a token instead of a for some constructs. Additionally, it probably makes sense to preserve empty elements (by producing null values in their place)

One approach might be to simply define the delimiter as a constant on DelimitedList. For most of them, TokenKind::CommaToken should suffice (TraitSelectOrAliasClauseList and QualifiedNameParts are the only exceptions). Additionally, in order to reduce duplication, we could refactor parseDelimitedList to replace the delimiter parameter with a constant access on the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense for DelimitedList to have a $delimiter prop instead, to keep them more flexible? We already have DelimiterLists that do not have a constant delimiter and there may be more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have DelimiterLists that do not have a constant delimiter and there may be more.

We do? Sounds like a bug 😃. Could you elaborate?

In general, we keep away from holding any "descriptor" properties on Nodes because the memory cost of additional properties is 12-16 bytes each (depending on 32 bit or 64 bit), which very quickly adds up on large code bases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #103 we should parse QualifiedNameList with TokenKind::BarToken delimiter, but in most cases its TokenKind::CommaToken.
But its probable I just misunderstood your suggestion ("simply define the delimiter as a constant on DelimitedList") 😄

Copy link
Contributor Author

@runz0rd runz0rd Feb 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a // TODO consider allowing empty delimiter to be more tolerant in parseDelimitedList, so if we allow insertion of empty delimiters (if there are none), the getListElements can return even key values of children.
If this does sound okay to you, how would you prefer to represent these empty delimiters?

@roblourens
Copy link
Member

It looks like getElements now fills this role. Please correct me if I'm wrong.

@roblourens roblourens closed this Aug 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants