Proposal for SentinelInputRange

Walter Bright newshound2 at digitalmars.com
Thu Feb 28 08:52:45 PST 2013


On 2/28/2013 3:29 AM, Jonathan M Davis wrote:
> And you were just claiming that the lexer checked the sentinel type in only
> one place. If that's indeed the case (and I think that it's quite close to
> being true if it isn't true), then you _wouldn't_ need to use static ifs like
> this in many places. So, which is it? If you need to check the sentinel often
> enough that using static ifs is a problem, then it's probably not buying you
> much of anything over checking empty anyway.

Please, again, examine lexer.c.

For example, look at what happens after line 719. Try 794 in particular.

Now look at line 996 and what follows. Note that there is not a single null 
check there, yet the code is correct and does not run off the end of the data.


> But my point is that outside of strings or arrays, you're almost certainly
> stuck with that.

I've given you two examples (lexer and regexp) where you are certainly not stuck 
with that, and those two cases matter.


> Pure input ranges fail utterly as you can't save them, so you get _zero_
> lookahead [...]

Yet the lexer will work efficiently and correctly with a SentinelInputRange that 
is also a ForwardRange. It fits in nicely with the range concepts.



More information about the Digitalmars-d mailing list