# -*- coding: utf-8 -*- # lp4all: literate programming embedded in source code as wiki comments # Copyright (C) 2006 Jean-Marie Favreau, Frédéric Lehobey, David Mentré # and Thomas Petazzoni # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. class ParseException(Exception): def __init__(self, message = "", lineno = -1, endlineno = -1): Exception.__init__(self, message) self.lineno = lineno self.endlineno = endlineno self.filename = "" def __str__(self): if self.lineno == -1 and self.endlineno == -1: return "Parse error in " + self.filename + ": " + Exception.__str__(self) elif self.endlineno == -1: return "Parse error in " + self.filename + " at line " + str(self.lineno) + ": "+ Exception.__str__(self) else: return "Parse error in " + self.filename + " between line " + str(self.lineno) + " and " + str(self.endlineno) + ": " + Exception.__str__(self) def setCommentProperties(self, filename, commentStartLine, commentEndLine): self.filename = filename if self.lineno >= 0: self.lineno += commentStartLine if self.endlineno >= 0: self.endlineno += commentStartLine if self.lineno < 0 and self.endlineno < 0: self.lineno = commentStartLine self.endlineno = commentEndLine