Description
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_ptr
s?).