Repository navigation
Parse template strings correctly - #168
Conversation
| $postfixExpression->parent = $subscriptExpression; | ||
|
|
||
| $subscriptExpression->postfixExpression = $postfixExpression; | ||
| $subscriptExpression->openBracketOrBrace = $this->eat(TokenKind::OpenBracketToken); // Only [] syntax is supported, not {} |
There was a problem hiding this comment.
What do you mean with the comment?
<?php
echo "{$myFancyArray[5]}"is valid too, and will output the sixth element of the array called myFancyArray,
There was a problem hiding this comment.
I mean, "$a[0]" works, but "$a{0}" doesn't.
There was a problem hiding this comment.
Ah, okay. Now I got that. Thanks!
| const TemplateStringEnd = 313; | ||
| const NoSubstitutionTemplateLiteral = 314; | ||
| const UnterminatedNoSubstitutionTemplateLiteral = 315; | ||
| const UnterminatedTemplateStringEnd = 316; |
There was a problem hiding this comment.
breaking changes here?
There was a problem hiding this comment.
These were never really used.
| if ( | ||
| $this->name instanceof Token && | ||
| $name = substr($this->name->getText($this->getFileContents()), 1) | ||
| $name = ltrim($this->name->getText($this->getFileContents()), '$') |
There was a problem hiding this comment.
So this trims all $ from the left - what about variable variables? e.g. $$var
There was a problem hiding this comment.
getName wouldn't work on $$var, because of the check above - name is a Variable node here. You would have to use $var->name->getName().
I made this change for "${x}". x is a variable that doesn't have a dollar sign, so I only want to remove a dollar sign if it exists.
Fixes #12
Removes the old template string implementation, adds a new one.
There's probably more that could be done to make the string representation more sophisticated, per #11, but I'm not sure what that should be. This is simple and works quite well.