Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

Cleanup Tokenizer #3

Description

@mhsdesign
No description provided.

Activity

  1. mhsdesign commented on Nov 10, 2022

    @mhsdesign
    ContributorAuthor

    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 ...

  2. self-assigned this
    on Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions