Re: An iterator with look-ahead

2007-01-10 Thread Paddy
Neil Cerutti wrote: > On 2007-01-10, Steven Bethard <[EMAIL PROTECTED]> wrote: > > Neil Cerutti wrote: > >> For use in a hand-coded parser I wrote the following simple > >> iterator with look-ahead. > > > > There's a recipe for this: > > > >http://aspn.activestate.com/ASPN/Cookbook/Python/Rec

Re: An iterator with look-ahead

2007-01-10 Thread Neil Cerutti
On 2007-01-10, Steven Bethard <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> For use in a hand-coded parser I wrote the following simple >> iterator with look-ahead. > > There's a recipe for this: > >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373 > > Note that the recipe ef

Re: An iterator with look-ahead

2007-01-10 Thread Steven Bethard
Neil Cerutti wrote: > For use in a hand-coded parser I wrote the following simple > iterator with look-ahead. There's a recipe for this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304373 Note that the recipe efficiently supports an arbitrary look-ahead, not just a single item.

Re: An iterator with look-ahead

2007-01-10 Thread George Sakkis
Neil Cerutti wrote: > For use in a hand-coded parser I wrote the following simple > iterator with look-ahead. I haven't thought too deeply about what > peek ought to return when the iterator is exhausted. Suggestions > are respectfully requested. As it is, you can't be sure what a > peek() => None

Re: An iterator with look-ahead

2007-01-10 Thread Neil Cerutti
On 2007-01-10, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > if you're doing simple parsing on an iterable, it's easier and > more efficient to pass around the current token and the > iterator's next method: > > http://online.effbot.org/2005_11_01_archive.htm#simple-parser-1 Thank you. Much better.

Re: An iterator with look-ahead

2007-01-10 Thread Fredrik Lundh
Neil Cerutti wrote: > For use in a hand-coded parser I wrote the following simple > iterator with look-ahead. I haven't thought too deeply about what > peek ought to return when the iterator is exhausted. Suggestions > are respectfully requested. As it is, you can't be sure what a > peek() => None

An iterator with look-ahead

2007-01-10 Thread Neil Cerutti
For use in a hand-coded parser I wrote the following simple iterator with look-ahead. I haven't thought too deeply about what peek ought to return when the iterator is exhausted. Suggestions are respectfully requested. As it is, you can't be sure what a peek() => None signifies until the next itera