comparison cmd2.py @ 59:37f471fb29b1

beginning to migrate line-ends to pyparsing
author catherine@Elli.myhome.westell.com
date Fri, 20 Jun 2008 15:49:06 -0400
parents a791d615545c
children 682588392eaf
comparison
equal deleted inserted replaced
55:698710e88d1b 59:37f471fb29b1
284 self.stdout.close() 284 self.stdout.close()
285 statekeeper.restore() 285 statekeeper.restore()
286 286
287 return stop 287 return stop
288 288
289 #TODO: This should be replaced by pyparsing. What if terminators come
290 #inside a string? What about statements that end in different ways?
291 # + searching for EOF string is sloppy!
289 statementEndPattern = re.compile(r'[%s]\s*$' % terminators) 292 statementEndPattern = re.compile(r'[%s]\s*$' % terminators)
293 lineEndFinder = pyparsing.Optional(pyparsing.CharsNotIn(';')) + ';'
290 def statementHasEnded(self, lines): 294 def statementHasEnded(self, lines):
295 try:
296 lineEndFinder.parseString(lines)
297 return True`
298 except pyparsing.ParseException:
299 return False
300 '''
291 return bool(self.statementEndPattern.search(lines)) \ 301 return bool(self.statementEndPattern.search(lines)) \
292 or lines[-3:] == 'EOF' \ 302 or lines[-3:] == 'EOF' \
293 or self.parseRedirectors(lines)[1] 303 or self.parseRedirectors(lines)[1]'''
294 304
295 def finishStatement(self, firstline): 305 def finishStatement(self, firstline):
296 statement = firstline 306 statement = firstline
297 while not self.statementHasEnded(statement): 307 while not self.statementHasEnded(statement):
298 inp = self.pseudo_raw_input(self.continuationPrompt) 308 inp = self.pseudo_raw_input(self.continuationPrompt)