uliwitness / Stacksmith

An intuitive software erector kit targeted at people new to programming, but with enough potential to stay useful once they've learned, inspired by HyperCard.
http://stacksmith.org
131 stars 13 forks source link

Wrap token iterators in an abstraction #100

Open uliwitness opened 5 years ago

uliwitness commented 5 years ago

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