Mercurial > lcfOS
comparison python/c3/parser.py @ 254:bd26dc13f270
Added logger
author | Windel Bouwman |
---|---|
date | Wed, 31 Jul 2013 21:20:58 +0200 |
parents | 6ed3d3a82a63 |
children | e64bae57cda8 |
comparison
equal
deleted
inserted
replaced
253:74c6a20302d5 | 254:bd26dc13f270 |
---|---|
1 import logging | |
1 from . import astnodes, lexer | 2 from . import astnodes, lexer |
2 from ppci import CompilerError | 3 from ppci import CompilerError |
3 | 4 |
4 class Parser: | 5 class Parser: |
5 """ Parses sourcecode into an abstract syntax tree (AST) """ | 6 """ Parses sourcecode into an abstract syntax tree (AST) """ |
6 def __init__(self, diag): | 7 def __init__(self, diag): |
8 self.logger = logging.getLogger('c3') | |
7 self.diag = diag | 9 self.diag = diag |
8 | 10 |
9 def parseSource(self, source): | 11 def parseSource(self, source): |
10 self.initLex(source) | 12 self.logger.info('Parsing source') |
11 try: | 13 self.initLex(source) |
12 self.parsePackage() | 14 try: |
13 return self.mod | 15 self.parsePackage() |
14 except CompilerError as e: | 16 return self.mod |
15 self.diag.addDiag(e) | 17 except CompilerError as e: |
18 self.diag.addDiag(e) | |
16 | 19 |
17 def Error(self, msg): | 20 def Error(self, msg): |
18 raise CompilerError(msg, self.token.loc) | 21 raise CompilerError(msg, self.token.loc) |
19 | 22 |
20 # Lexer helpers: | 23 # Lexer helpers: |