__all__ = [
    'ExecutionError',
    'NoDispatch',
    'InvalidLibraryDefinition',
    'CustomSyntaxError'
]

# TODO: BlazeException base class ?

# for Numba
class ExecutionError(Exception):
    """
    Raised when we are unable to execute a certain lazy or immediate
    expression.
    """

# for the RTS
class NoDispatch(Exception):
    def __init__(self, aterm):
        self.aterm = aterm
    def __str__(self):
        return "No implementation for '%r'" % self.aterm

# for the RTS
class InvalidLibraryDefinition(Exception):
    pass

#------------------------------------------------------------------------
# Generic Syntax Errors
#------------------------------------------------------------------------

syntax_error = """

  File {filename}, line {lineno}
    {line}
    {pointer}

{error}: {msg}
"""

class CustomSyntaxError(Exception):
    """
    Makes datashape parse errors look like Python SyntaxError.
    """
    def __init__(self, lineno, col_offset, filename, text, msg=None):
        self.lineno     = lineno
        self.col_offset = col_offset
        self.filename   = filename
        self.text       = text
        self.msg        = msg or 'invalid syntax'

    def __str__(self):
        return syntax_error.format(
            filename = self.filename,
            lineno   = self.lineno,
            line     = self.text.split()[self.lineno],
            pointer  = ' '*self.col_offset + '^',
            msg      = self.msg,
            error    = self.__class__.__name__,
        )

    def __repr__(self):
        return str(self)

__all__ = [
    'ExecutionError',
    'NoDispatch',
    'InvalidLibraryDefinition',
    'CustomSyntaxError'
]

# TODO: BlazeException base class ?

# for Numba
class ExecutionError(Exception):
    """
    Raised when we are unable to execute a certain lazy or immediate
    expression.
    """

# for the RTS
class NoDispatch(Exception):
    def __init__(self, aterm):
        self.aterm = aterm
    def __str__(self):
        return "No implementation for '%r'" % self.aterm

# for the RTS
class InvalidLibraryDefinition(Exception):
    pass

#------------------------------------------------------------------------
# Generic Syntax Errors
#------------------------------------------------------------------------

syntax_error = """

  File {filename}, line {lineno}
    {line}
    {pointer}

{error}: {msg}
"""

class CustomSyntaxError(Exception):
    """
    Makes datashape parse errors look like Python SyntaxError.
    """
    def __init__(self, lineno, col_offset, filename, text, msg=None):
        self.lineno     = lineno
        self.col_offset = col_offset
        self.filename   = filename
        self.text       = text
        self.msg        = msg or 'invalid syntax'

    def __str__(self):
        text_split = self.text.split()
        return syntax_error.format(
            filename = self.filename,
            lineno   = self.lineno,
            line     = text_split[max(self.lineno, len(text_split) - 1)],
            pointer  = ' '*self.col_offset + '^',
            msg      = self.msg,
            error    = self.__class__.__name__,
        )

    def __repr__(self):
        return str(self)

Fix out of bounds array access on end-of-string parse error