-
Notifications
You must be signed in to change notification settings - Fork 24
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
Cursor based tokenizer #48
Conversation
2f95fc3
to
da33754
Compare
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.
I absolutely love what you did here, it's beautiful 👌
if (isset($originalTokens[$indexedToken['originalIndex']-1]) && | ||
! $originalTokens[$indexedToken['originalIndex']-1]->isOfType(Token::TOKEN_TYPE_WHITESPACE)) { | ||
$prevToken = $cursor->subCursor()->previous(); | ||
if ($prevToken && ! $prevToken->isOfType(Token::TOKEN_TYPE_WHITESPACE)) { |
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.
I'm not requiring you do it, but how would you feel about implementing the null object pattern to avoid all these checks?
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.
hmm. not sure about that. to do so i will have to introduce a TokenInterface
and also to use an instanceof
check in the while, or add one more method in the Cursor
class... do you have a suggestion on how to implement it?
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.
I would rather add a new type, and check it in most methods if needed (but isOfType
would not need to change, for instance). value()
would require throwing, so would withValue
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.
Ah drop it, this is probably just another bad design idea on my part 😓
I have marked the |
Please squash some of the commits together (for instance the one that removes the debugging variable) |
Co-Authored-By: Grégoire Paris <postmaster@greg0ire.fr>
Thanks @goetas ! |
No description provided.