# Path: pycell/peekablestream.py
# class PeekableStream:
# 
#     def __init__(self, iterator):
#         self.iterator = iter(iterator)
#         self._fill()
# 
#     def _fill(self):
#         try:
#             self.next = next(self.iterator)
#         except StopIteration:
#             self.next = None
# 
#     def move_next(self):
#         ret = self.next
#         self._fill()
#         return ret


import re
from pycell.peekablestream import PeekableStream



def _scan(first_char, chars, allowed):
    ret = first_char
    p = chars.next
    while p is not None and re.match(allowed, p):
        ret += chars.move_next()
        p = chars.next
    return ret


def _scan_string(delim, chars):
    ret = ""
    while chars.next != delim:
        c = chars.move_next()
        if c is None:
            raise Exception("A string ran off the end of the program.")
        ret += c
    chars.move_next()
    return ret


def lex(chars_iter):

# Path: pycell/peekablestream.py
# class PeekableStream:
# 
#     def __init__(self, iterator):
#         self.iterator = iter(iterator)
#         self._fill()
# 
#     def _fill(self):
#         try:
#             self.next = next(self.iterator)
#         except StopIteration:
#             self.next = None
# 
#     def move_next(self):
#         ret = self.next
#         self._fill()
#         return ret


# Path: pycell/lexer.py
import re
from pycell.peekablestream import PeekableStream




def _scan(first_char, chars, allowed):
    ret = first_char
    p = chars.next
    while p is not None and re.match(allowed, p):
        ret += chars.move_next()
        p = chars.next
    return ret


def _scan_string(delim, chars):
    ret = ""
    while chars.next != delim:
        c = chars.move_next()
        if c is None:
            raise Exception("A string ran off the end of the program.")
        ret += c
    chars.move_next()
    return ret


def lex(chars_iter):

    chars = PeekableStream(chars_iter)