Skip to content

Tokenizer rewrite#175

Merged
TRPB merged 16 commits intomasterfrom
Tokenizer-Rewrite
Dec 9, 2017
Merged

Tokenizer rewrite#175
TRPB merged 16 commits intomasterfrom
Tokenizer-Rewrite

Conversation

@TRPB
Copy link
Copy Markdown
Member

@TRPB TRPB commented Dec 8, 2017

I've completely rewritten the way the tokenizer works to make it significantly easier to follow. Each type is now its own class, e.g. comments, brackets, etc.

There is a new class TokenizedString which now tracks the current position/line number.

The basic premise is this:

$str = new TokenizedString($tss);
while ($str->next()) {
 //Identify strings


   if ($str->identifyCharacter() == Tokenizer::QUOTE) {
     //It's a string...
     $extractedString = $str->extractString();
     $tokens->add(['type' => Tokenizer::STRING, $extractedString]);
     
      //now move the pointer on to the end of the string which was extracted (the pointer will now be at the closing quote)
     $str->move(strlen($extractedString));

    //When the loop iterates next it will move on to the character following the identified string
    }
   else if (/* it's a comment, or a literal, or a bracket*/) {
    //handle the next type
   }
}

This is essentially how it works but each block of the if/else statement is its own class.

@TRPB
Copy link
Copy Markdown
Member Author

TRPB commented Dec 8, 2017

@solleer would appreciate your thoughts/comments on this approach. If you're happy I'll merge the changes and draft a release.

Copy link
Copy Markdown
Collaborator

@solleer solleer left a comment

Choose a reason for hiding this comment

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

It looks great and definitely feels a lot easier to follow. Thanks for all the work.

@TRPB TRPB merged commit a9e060e into master Dec 9, 2017
@TRPB TRPB deleted the Tokenizer-Rewrite branch December 9, 2017 19:48
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.

2 participants