1 2 class SyntaxError(Exception): 3 """Base class for exceptions raised by the parser.""" 4 5 def __init__(self, msg, lineno=0, offset=0, text=None, filename=None, 6 lastlineno=0): 7 self.msg = msg 8 self.lineno = lineno 9 self.offset = offset 10 self.text = text 11 self.filename = filename 12 self.lastlineno = lastlineno 13 14 def __str__(self): 15 return "%s at pos (%d, %d) in %r" % (self.__class__.__name__, 16 self.lineno, 17 self.offset, 18 self.text) 19 20 class IndentationError(SyntaxError): 21 pass 22 23 class ASTError(Exception): 24 def __init__(self, msg, ast_node ): 25 self.msg = msg 26 self.ast_node = ast_node 27 28 29 class TokenError(SyntaxError): 30 31 def __init__(self, msg, line, lineno, column, tokens, lastlineno=0): 32 SyntaxError.__init__(self, msg, lineno, column, line, 33 lastlineno=lastlineno) 34 self.tokens = tokens 35 36 class TokenIndentationError(IndentationError): 37 38 def __init__(self, msg, line, lineno, column, tokens): 39 SyntaxError.__init__(self, msg, lineno, column, line) 40 self.tokens = tokens