nhsevidence/ScreeningMathParser — pull request #2 by claresudbery (2014-10-13 11:39:21+00:00)
Title: ScreeningMathParser - from contract candidate

The code went through a few incarnations... I've committed some major change points.
Initially it was a more complex solution which evolved organically, test-first. This was followed by a few refactoring passes.
The main result of the refactoring was to simplify the code and make it more readable, for instance:
- no longer creating temporary "MathsToken" objects
- not reading ahead; processing each character as it appears in the input
- not passing nextIndex around as a function parameter
- increasing clean code via well-named sub methods
Another result was to introduce more validation, for instance:
- checking for empty strings
- checking for expressions that terminate unexpectedly
Another result was the introduction of more tests to explicitly cover more complex bracket-nesting scenarios, for instance:
- non-functional nested brackets - eg "(((3 + 4)))"
- the first term of a sub-expression is itself a sub-expression within brackets - eg "2 - ((3 + 4) * 2)"
- the second term of a sub-expression is itself a sub-expression within brackets - eg "2 - (3 + (4 * 2))"
The final version is (hopefully) simpler, more comprehensive and easier to read.
This was an enjoyable exercise. :)