09-Jan-2014 13:23, Brian Schott пишет:
My experimental lexer generator now uses the buffer range.
https://github.com/Hackerpilot/Dscanner/tree/NewLexer/stdx


Cool!

A minor note:
https://github.com/Hackerpilot/Dscanner/blob/NewLexer/stdx/d/lexer.d#L487

lookahead(n) should always give a slice of length n,
or 0 so you may as well test for != 0.

In general you should avoid marking too often, it takes a bit of .

I'm currently in favor of my 2nd design where marking is replaced by .save returning an independent view of buffer, making Buffer a normal forward range that is cheap to copy.

https://github.com/blackwhale/datapicked/blob/fwd-buffer-range/dpick/buffer/

Sadly it segfaults with LDC so I can't quite assess its performance :(

The problem that I have with it right now is that
range.lookbehind(1).length != range.lookahead(1).length. This was
confusing.

That indeed may look confusing at start but keep in mind that range.front is in fact a lookahead of 1. Thus all algorithms that can work with lookahead of 1 LL(1), LALR(1) etc. would easily work any forward/input range (though any practical parser need to slice or copy parts of input aside).

--
Dmitry Olshansky

Reply via email to