comparison python/c3/parser.py @ 169:ee0d30533dae

Added more tests and improved the diagnostic update
author Windel Bouwman
date Sat, 23 Mar 2013 18:34:41 +0100
parents 0b5b2ee6b435
children 46d62dadd61b
comparison
equal deleted inserted replaced
168:49f1ab80d040 169:ee0d30533dae
11 def __init__(self, diag): 11 def __init__(self, diag):
12 self.sema = semantics.Semantics(diag) 12 self.sema = semantics.Semantics(diag)
13 self.diag = diag 13 self.diag = diag
14 def parseSource(self, source): 14 def parseSource(self, source):
15 self.initLex(source) 15 self.initLex(source)
16 self.sema.reinit()
16 try: 17 try:
17 self.parsePackage() 18 self.parsePackage()
18 except CompilerError as e: 19 except CompilerError as e:
19 self.diag.addDiag(e) 20 self.diag.addDiag(e)
20 return self.sema.mod 21 return self.sema.mod
208 self.Error('Unable to determine statement') 209 self.Error('Unable to determine statement')
209 210
210 # Parsing expressions: 211 # Parsing expressions:
211 def parseExpression(self): 212 def parseExpression(self):
212 return self.parseBinopRhs(self.parsePrimary(), 0) 213 return self.parseBinopRhs(self.parsePrimary(), 0)
213 # TODO: use this error handling:
214 try:
215 return self.parseBinopRhs(self.parsePrimary(), 0)
216 except CompilerError as e:
217 self.diag.addDiag(e)
218 self.skipToSemi(';')
219 return astnodes.Literal(0)
220 def parsePrimary(self): 214 def parsePrimary(self):
221 if self.hasConsumed('('): 215 if self.hasConsumed('('):
222 e = self.parseExpression() 216 e = self.parseExpression()
223 self.Consume(')') 217 self.Consume(')')
224 return e 218 return e