Skip to content
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

Cleanup Tokenizer #3

Open
mhsdesign opened this issue Nov 10, 2022 · 1 comment
Open

Cleanup Tokenizer #3

mhsdesign opened this issue Nov 10, 2022 · 1 comment
Assignees

Comments

@mhsdesign
Copy link
Contributor

No description provided.

@mhsdesign
Copy link
Contributor Author

mhsdesign commented Nov 10, 2022

1

i dislike those three methods:

public static function tryBracketOpenFromFragment(Fragment $fragment): ?self
{
return match ($fragment->value) {
'{' => self::BRACKET_CURLY_OPEN,
'(' => self::BRACKET_ROUND_OPEN,
'[' => self::BRACKET_SQUARE_OPEN,
default => null
};
}
public function closingBracket(): TokenType
{
return match ($this) {
self::BRACKET_CURLY_OPEN => self::BRACKET_CURLY_CLOSE,
self::BRACKET_ROUND_OPEN => self::BRACKET_ROUND_CLOSE,
self::BRACKET_SQUARE_OPEN => self::BRACKET_SQUARE_CLOSE,
default => throw new \Exception('@TODO: Not a bracket.')
};
}
public function matchesString(string $string): bool
they are hard to make sense out of...
At first i didnt even understand what closingBracket was doing, i though it would return self::BRACKET_CURLY_OPEN => self::BRACKET_CURLY_OPEN, but it gives the closing bracket for the opening bracket - my eyes didnt catch that.

so my take would be to have better method naming, or as those methods are only called at one place - inside

$bracket = TokenType::tryBracketOpenFromFragment($fragments->current());
$buffer = Buffer::empty();
if ($bracket) {
yield from $buffer->append($fragments->current())->flush($bracket);
$fragments->next();
}
while ($fragments->valid()) {
/** @var Fragment $fragment */
$fragment = $fragments->current();
if ($bracket) {
$closingBracket = $bracket->closingBracket();
if ($closingBracket->matchesString($fragment->value)) {
put them inline or sth. They do feel like an anomaly ...

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

No branches or pull requests

2 participants