Mercurial > lcfOS
comparison python/ppci/errors.py @ 200:5e391d9a3381
Split off asm nodes
author | Windel Bouwman |
---|---|
date | Sun, 09 Jun 2013 16:06:49 +0200 |
parents | b01429a5d695 |
children | c1ccb1cb4cef |
comparison
equal
deleted
inserted
replaced
199:a690473b79e2 | 200:5e391d9a3381 |
---|---|
4 """ | 4 """ |
5 | 5 |
6 from . import SourceLocation | 6 from . import SourceLocation |
7 | 7 |
8 class CompilerError(Exception): | 8 class CompilerError(Exception): |
9 def __init__(self, msg, loc): | 9 def __init__(self, msg, loc=None): |
10 self.msg = msg | 10 self.msg = msg |
11 self.loc = loc | 11 self.loc = loc |
12 assert type(loc) is SourceLocation, '{0} must be SourceLocation'.format(type(loc)) | 12 if loc: |
13 assert type(loc) is SourceLocation, '{0} must be SourceLocation'.format(type(loc)) | |
13 def __repr__(self): | 14 def __repr__(self): |
14 return 'Compilererror {0} at row {1}'.format(self.msg, self.loc.row) | 15 if self.loc: |
16 return 'Compilererror: "{0}" at row {1}'.format(self.msg, self.loc.row) | |
17 else: | |
18 return 'Compilererror: "{0}"'.format(self.msg) | |
15 | 19 |
16 def printError(source, e): | 20 def printError(source, e): |
17 def printLine(row, txt): | 21 def printLine(row, txt): |
18 print(str(row)+':'+txt) | 22 print(str(row)+':'+txt) |
19 if e.loc.row == 0: | 23 if e.loc.row == 0: |