Lichen

Annotated pyparser/error.py

794:7dd8e4815848
2017-03-31 Paul Boddie Introduced a multiple outcome result which can be used to provide a choice of return values to supply the initialiser and alias details.
paul@437 1
paul@437 2
class SyntaxError(Exception):
paul@437 3
    """Base class for exceptions raised by the parser."""
paul@437 4
paul@437 5
    def __init__(self, msg, lineno=0, offset=0, text=None, filename=None,
paul@437 6
                 lastlineno=0):
paul@437 7
        self.msg = msg
paul@437 8
        self.lineno = lineno
paul@437 9
        self.offset = offset
paul@437 10
        self.text = text
paul@437 11
        self.filename = filename
paul@437 12
        self.lastlineno = lastlineno
paul@437 13
paul@437 14
    def __str__(self):
paul@437 15
        return "%s at pos (%d, %d) in %r" % (self.__class__.__name__,
paul@437 16
                                             self.lineno,
paul@437 17
                                             self.offset,
paul@437 18
                                             self.text)
paul@437 19
paul@437 20
class IndentationError(SyntaxError):
paul@437 21
    pass
paul@437 22
paul@437 23
class TokenError(SyntaxError):
paul@437 24
paul@437 25
    def __init__(self, msg, line, lineno, column, tokens, lastlineno=0):
paul@437 26
        SyntaxError.__init__(self, msg, lineno, column, line,
paul@437 27
                             lastlineno=lastlineno)
paul@437 28
        self.tokens = tokens
paul@437 29
paul@437 30
class TokenIndentationError(IndentationError):
paul@437 31
paul@437 32
    def __init__(self, msg, line, lineno, column, tokens):
paul@437 33
        SyntaxError.__init__(self, msg, lineno, column, line)
paul@437 34
        self.tokens = tokens