On Saturday, 7 July 2012 at 22:54:15 UTC, Timon Gehr wrote:
On 07/08/2012 12:23 AM, Mehrdad wrote:

You could go like this:

switch(input.front) {
    case '0'..'9':
        bool consumedtrailingdot;
        output.put(parseNumber(input, consumedtrailingdot));
        if(!consumedtrailingdot) continue;
        if(input.front != '.') {
            output.put(Token("."));
            continue;
        }
        input.popFront();
        if(input.front != '.') {
            output.put(Token(".."));
            continue;
        }
        output.put(Token("..."));
        continue;
}

You kinda glossed over the crucial detail in parseNumber().  ;)

What happens if it sees   "2..3" ?

Then it /must/ have eaten the first period (it can't see the second period otherwise)... in which case now you have no idea that happened.

Of course, it's trivial to fix with an extra lookahead, but that would require using a forward range instead of an input range. (Which, again, is easy to do with an adapter -- what I ended up doing -- but the point is, it makes it harder to lex the code with just an input range.)

Reply via email to