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

Refactor helpers in Parser #21

Closed
quephird opened this issue Mar 17, 2024 · 1 comment
Closed

Refactor helpers in Parser #21

quephird opened this issue Mar 17, 2024 · 1 comment

Comments

@quephird
Copy link
Owner

quephird commented Mar 17, 2024

Each parse helper called byparseStatement() should "know" the full grammar of the statement type it's attempting to parse. For example, parseForStatement() should actually be checking for the existence of the for token, not parseStatment(). That means all of the parse helps will need to return Statement? and the call site should have an if let to grab the return value, like so:

In parseStatement():

        if let forStmt = try parseForStatement() {
            return forStmt
        }
        .
        .
        . 

... then in parseForStatement():

        guard currentTokenMatchesAny(types: [.for]) else {
            return nil
        }
        .
        .
        . 

Look for other places in the parser where there is a similar splintering of knowledge.

@quephird quephird changed the title Refactor parseStatement() Refactor helpers in Parser Mar 20, 2024
@quephird
Copy link
Owner Author

Addressed in #23!

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

1 participant