Skip to content

TokenStream.eat() #20

@jg-rp

Description

@jg-rp

When parsing tokens with an instance of TokenStream, it is common to assert the token type then consume it. Currently that requires two method calls.

stream.expect(TokenType.IF)
stream.next()  # move past `if`

If we introduce TokenStream.eat(), which asserts the token type an consumes it, we can reduce that to one method call and be more efficient in its implementations.

const token = stream.eat(TokenType.IF)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions