# Path: muninn/_compat.py
# PY3 = sys.version_info[0] == 3
#     def is_python2_unicode(x):
#     def dictkeys(d):
#     def dictvalues(d):
#     def path_utf8(path):
#     def encode(s):
#     def decode(s):
#     def is_python2_unicode(x):
#     def path_utf8(path):
#     def decode(s):
#     def encode(s):
# 
# Path: muninn/enum.py
# class MetaEnum(type):
#     def __new__(meta, name, bases, dct):
#     def count(cls):
#     def valid(cls, value):
#     def items(cls):
#     def to_string(cls, value):
#     def from_string(cls, value):
# 
# Path: muninn/function.py
# class Prototype(object):
#     def __init__(self, name, argument_types=(), return_type=None):
#         self.name = name
#         self.argument_types = argument_types
#         self.return_type = return_type
# 
#         self._id = "%s(%s)" % (self.name, ",".join(imap(lambda type: type.name(), self.argument_types)))
#         if self.return_type is not None:
#             self._id += " " + self.return_type.name()
# 
#     @property
#     def id(self):
#         return self._id
# 
#     @property
#     def arity(self):
#         return len(self.argument_types)
# 
#     def _argument_types_equal(self, other):
#         if self.arity != other.arity:
#             return False
# 
#         for type_self, type_other in izip(self.argument_types, other.argument_types):
#             if type_self is not type_other:
#                 return False
#         return True
# 
#     def __eq__(self, other):
#         return self.name == other.name and self._argument_types_equal(other) and self.return_type is other.return_type
# 
#     def __ne__(self, other):
#         return not self == other
# 
#     def __str__(self):
#         return self.id
# 
#     def __repr__(self):
#         return "Prototype(name=%r, argument_types=%r, return_type=%r)" % (self.name, self.argument_types,
#                                                                           self.return_type)
# 
#     def __hash__(self):
#         return hash(self.id)
# 
# class FunctionTable(MutableSet):
#     def __init__(self, prototypes=[], type_map=None):
#         self._prototypes = {}
#         self._type_map = type_map
#         for prototype in prototypes:
#             self.add(prototype)
# 
#     def __contains__(self, prototype):
#         try:
#             prototypes = self._prototypes[prototype.name]
#         except KeyError:
#             return False
#         else:
#             return prototype in prototypes
# 
#     def __iter__(self):
#         for prototypes in itervalues(self._prototypes):
#             for prototype in prototypes:
#                 yield prototype
# 
#     def __len__(self):
#         return sum(imap(len, itervalues(self._prototypes)))
# 
#     def add(self, prototype):
#         try:
#             self._prototypes[prototype.name].add(prototype)
#         except KeyError:
#             self._prototypes[prototype.name] = set((prototype,))
# 
#     def discard(self, prototype):
#         try:
#             self._prototypes[prototype.name].discard(prototype)
#         except KeyError:
#             pass
# 
#     def resolve(self, prototype):
#         top, top_equal = [], 0
#         for candidate in self._prototypes[prototype.name]:
#             if candidate.arity != prototype.arity:
#                 continue
# 
#             equal, compatible = 0, 0
#             for candidate_type, type_ in izip(candidate.argument_types, prototype.argument_types):
#                 if type_ is candidate_type:
#                     equal += 1
#                 elif type_ in self._type_map and self._type_map[type_] is candidate_type:
#                     compatible += 1
#                 elif type_ in self._type_map and issubclass(type_, self._type_map[type_]):
#                     compatible += 1
#                 elif issubclass(type_, candidate_type):
#                     compatible += 1
#                 else:
#                     break
# 
#             if equal + compatible != prototype.arity:
#                 continue
# 
#             if equal > top_equal:
#                 top = [candidate]
#                 top_equal = equal
#             elif equal == top_equal:
#                 top.append(candidate)
# 
#         return top
# 
# Path: muninn/visitor.py
# class Visitor(object):
#     def visit(self, visitable, *args, **kwargs):
#         for type_ in inspect.getmro(type(visitable)):
#             try:
#                 visit_func = getattr(self, "visit_%s" % type_.__name__)
#             except AttributeError:
#                 pass
#             else:
#                 return visit_func(visitable, *args, **kwargs)
# 
#         try:
#             visit_func = getattr(self, "default")
#         except AttributeError:
#             pass
#         else:
#             return visit_func(visitable, *args, **kwargs)


from muninn._compat import string_types as basestring
from muninn.enum import Enum
from muninn.exceptions import *
from muninn.function import Prototype, FunctionTable
from muninn.schema import *
from muninn.visitor import Visitor
import copy
import datetime
import re
import uuid
import muninn.geometry as geometry
        token = self.token
        self.next()
        return token

    def _types_to_string(self, types):
        try:
            strings = map(TokenType.to_string, types)
        except TypeError:
            return TokenType.to_string(types)

        return "%s%s" % ("" if len(strings) == 1 else "one of: ", ", ".join(strings))

    def _values_to_string(self, values):
        if isinstance(values, basestring):
            return "\"%s\"" % values

        try:
            strings = ["\"%s\"" % value for value in values]
        except TypeError:
            return "\"%s\"" % values

        return "%s%s" % ("" if len(strings) == 1 else "one of: ", ", ".join(strings))

    def _test_token_types(self, types):
        try:
            return self.token.type_ in types
        except TypeError:
            return self.token.type_ == types

    def _test_token_values(self, values):

# Path: muninn/_compat.py
# PY3 = sys.version_info[0] == 3
#     def is_python2_unicode(x):
#     def dictkeys(d):
#     def dictvalues(d):
#     def path_utf8(path):
#     def encode(s):
#     def decode(s):
#     def is_python2_unicode(x):
#     def path_utf8(path):
#     def decode(s):
#     def encode(s):
# 
# Path: muninn/enum.py
# class MetaEnum(type):
#     def __new__(meta, name, bases, dct):
#     def count(cls):
#     def valid(cls, value):
#     def items(cls):
#     def to_string(cls, value):
#     def from_string(cls, value):
# 
# Path: muninn/function.py
# class Prototype(object):
#     def __init__(self, name, argument_types=(), return_type=None):
#         self.name = name
#         self.argument_types = argument_types
#         self.return_type = return_type
# 
#         self._id = "%s(%s)" % (self.name, ",".join(imap(lambda type: type.name(), self.argument_types)))
#         if self.return_type is not None:
#             self._id += " " + self.return_type.name()
# 
#     @property
#     def id(self):
#         return self._id
# 
#     @property
#     def arity(self):
#         return len(self.argument_types)
# 
#     def _argument_types_equal(self, other):
#         if self.arity != other.arity:
#             return False
# 
#         for type_self, type_other in izip(self.argument_types, other.argument_types):
#             if type_self is not type_other:
#                 return False
#         return True
# 
#     def __eq__(self, other):
#         return self.name == other.name and self._argument_types_equal(other) and self.return_type is other.return_type
# 
#     def __ne__(self, other):
#         return not self == other
# 
#     def __str__(self):
#         return self.id
# 
#     def __repr__(self):
#         return "Prototype(name=%r, argument_types=%r, return_type=%r)" % (self.name, self.argument_types,
#                                                                           self.return_type)
# 
#     def __hash__(self):
#         return hash(self.id)
# 
# class FunctionTable(MutableSet):
#     def __init__(self, prototypes=[], type_map=None):
#         self._prototypes = {}
#         self._type_map = type_map
#         for prototype in prototypes:
#             self.add(prototype)
# 
#     def __contains__(self, prototype):
#         try:
#             prototypes = self._prototypes[prototype.name]
#         except KeyError:
#             return False
#         else:
#             return prototype in prototypes
# 
#     def __iter__(self):
#         for prototypes in itervalues(self._prototypes):
#             for prototype in prototypes:
#                 yield prototype
# 
#     def __len__(self):
#         return sum(imap(len, itervalues(self._prototypes)))
# 
#     def add(self, prototype):
#         try:
#             self._prototypes[prototype.name].add(prototype)
#         except KeyError:
#             self._prototypes[prototype.name] = set((prototype,))
# 
#     def discard(self, prototype):
#         try:
#             self._prototypes[prototype.name].discard(prototype)
#         except KeyError:
#             pass
# 
#     def resolve(self, prototype):
#         top, top_equal = [], 0
#         for candidate in self._prototypes[prototype.name]:
#             if candidate.arity != prototype.arity:
#                 continue
# 
#             equal, compatible = 0, 0
#             for candidate_type, type_ in izip(candidate.argument_types, prototype.argument_types):
#                 if type_ is candidate_type:
#                     equal += 1
#                 elif type_ in self._type_map and self._type_map[type_] is candidate_type:
#                     compatible += 1
#                 elif type_ in self._type_map and issubclass(type_, self._type_map[type_]):
#                     compatible += 1
#                 elif issubclass(type_, candidate_type):
#                     compatible += 1
#                 else:
#                     break
# 
#             if equal + compatible != prototype.arity:
#                 continue
# 
#             if equal > top_equal:
#                 top = [candidate]
#                 top_equal = equal
#             elif equal == top_equal:
#                 top.append(candidate)
# 
#         return top
# 
# Path: muninn/visitor.py
# class Visitor(object):
#     def visit(self, visitable, *args, **kwargs):
#         for type_ in inspect.getmro(type(visitable)):
#             try:
#                 visit_func = getattr(self, "visit_%s" % type_.__name__)
#             except AttributeError:
#                 pass
#             else:
#                 return visit_func(visitable, *args, **kwargs)
# 
#         try:
#             visit_func = getattr(self, "default")
#         except AttributeError:
#             pass
#         else:
#             return visit_func(visitable, *args, **kwargs)


# Path: muninn/language.py
from muninn._compat import string_types as basestring
from muninn.enum import Enum
from muninn.exceptions import *
from muninn.function import Prototype, FunctionTable
from muninn.schema import *
from muninn.visitor import Visitor
import copy
import datetime
import re
import uuid
import muninn.geometry as geometry

        token = self.token
        self.next()
        return token

    def _types_to_string(self, types):
        try:
            strings = map(TokenType.to_string, types)
        except TypeError:
            return TokenType.to_string(types)

        return "%s%s" % ("" if len(strings) == 1 else "one of: ", ", ".join(strings))

    def _values_to_string(self, values):
        if isinstance(values, basestring):
            return "\"%s\"" % values

        try:
            strings = ["\"%s\"" % value for value in values]
        except TypeError:
            return "\"%s\"" % values

        return "%s%s" % ("" if len(strings) == 1 else "one of: ", ", ".join(strings))

    def _test_token_types(self, types):
        try:
            return self.token.type_ in types
        except TypeError:
            return self.token.type_ == types

    def _test_token_values(self, values):

        if isinstance(values, basestring):