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

Wrap token iterators in an abstraction #100

Open
uliwitness opened this issue Mar 30, 2019 · 0 comments
Open

Wrap token iterators in an abstraction #100

uliwitness opened this issue Mar 30, 2019 · 0 comments
Labels
interpreter Hammer programming language: Parser, tokenizer, interpreter.

Comments

@uliwitness
Copy link
Owner

Right now, we have free GoNextToken()/GoPrevToken() functions and lots of if( tokenItty != tokens.end() ) checks in the parser.

If it wouldn't add much code/overhead, could we maybe change the parser to not directly use std::vector iterators and instead wrap them in an object that performs these checks and (instead of crashing) would just throw when someone tries to advance past the end. Similarly, it should provide a dummy token that doesn't match any other token type or identifier type when de-referenced while we're at tokens.end().

The idea behind this is to make the parser code easier to follow by being able to omit more code.

Of course this would mean we'd have to religiously follow RAII while parsing so we don't leak resources (Can we use std::unique_ptrs?).

@uliwitness uliwitness added the interpreter Hammer programming language: Parser, tokenizer, interpreter. label Mar 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter Hammer programming language: Parser, tokenizer, interpreter.
Projects
None yet
Development

No branches or pull requests

1 participant