rstudio/rstudio — pull request #251 by kevinushey (2014-12-10 17:44:20+00:00)
Title: Audit + clean up token walking code in the R code model

This is an attempt to audit + clean up some of the token walking code we have.

Quick outline -- there are a small number of 'very hot' code paths which other functions rely on. These are member functions of the `TokenCursor` object.

1. `moveToPreviousToken()`
2. `moveToNextToken()`
3. `bwdToMatchingToken()`
4. `fwdToMatchingToken()`

On success, they move the token cursor as named and return `true`; on failure they don't touch the token cursor and return `false`.

Most other functions are built on top of these 4 in the form of `while (cursor.moveToPreviousToken())`, so it is essential that they stop either at the start, or end, of the document.

The pre-existing code was a bit cluttered, so I've re-written and commented my steps here and I think it should at least be a step in the right direction.

@jmcphers, can we do a quick review of this?