November 2016
Intermediate to advanced
480 pages
14h 42m
English
The error messages printed out by evaluate(_:) are useful, but not as useful as they could be. Here are a couple of erroneous inputs and the error messages they produce:
evaluate("1 + 3 + 7a + 8")
> Input contained an invalid character: a
evaluate("10 + 3 3 + 7")
> Invalid token during parsing: .number(3)
Make these messages more helpful by including the character position where the error occurred. After completing this challenge, you should see error messages like this:
evaluate("1 + 3 + 7a + 8")
> Input contained an invalid character at index 9: a
evaluate("10 + 3 3 + 7")
> Invalid token during parsing at index 7: 3
Hint: You will need to associate error positions with your existing error cases. To convert ...
Read now
Unlock full access