# 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


from pycell.peekablestream import PeekableStream
    def next_expression(self, prev):
        self.fail_if_at_end(";")
        typ, value = self.tokens.next
        if typ in self.stop_at:
            return prev
        self.tokens.move_next()
        if typ in ("number", "string", "symbol") and prev is None:
            return self.next_expression((typ, value))
        elif typ == "operation":
            nxt = self.next_expression(None)
            return self.next_expression(("operation", value, prev, nxt))
        elif typ == "(":
            args = self.multiple_expressions(",", ")")
            return self.next_expression(("call", prev, args))
        elif typ == "{":
            params = self.parameters_list()
            body = self.multiple_expressions(";", "}")
            return self.next_expression(("function", params, body))
        elif typ == "=":
            if prev[0] != "symbol":
                raise Exception("You can't assign to anything except a symbol.")
            nxt = self.next_expression(None)
            return self.next_expression(("assignment", prev, nxt))
        else:
            raise Exception("Unexpected token: " + str((typ, value)))

    def parameters_list(self):
        if self.tokens.next[0] != ":":
            return []  # If there's no colon, this function takes no args
        self.tokens.move_next()

# 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/parser.py
from pycell.peekablestream import PeekableStream

    def next_expression(self, prev):
        self.fail_if_at_end(";")
        typ, value = self.tokens.next
        if typ in self.stop_at:
            return prev
        self.tokens.move_next()
        if typ in ("number", "string", "symbol") and prev is None:
            return self.next_expression((typ, value))
        elif typ == "operation":
            nxt = self.next_expression(None)
            return self.next_expression(("operation", value, prev, nxt))
        elif typ == "(":
            args = self.multiple_expressions(",", ")")
            return self.next_expression(("call", prev, args))
        elif typ == "{":
            params = self.parameters_list()
            body = self.multiple_expressions(";", "}")
            return self.next_expression(("function", params, body))
        elif typ == "=":
            if prev[0] != "symbol":
                raise Exception("You can't assign to anything except a symbol.")
            nxt = self.next_expression(None)
            return self.next_expression(("assignment", prev, nxt))
        else:
            raise Exception("Unexpected token: " + str((typ, value)))

    def parameters_list(self):
        if self.tokens.next[0] != ":":
            return []  # If there's no colon, this function takes no args
        self.tokens.move_next()

        typ = self.tokens.next[0]