Mercurial > python-cmd2
comparison cmd2.py @ 156:7e5a57df88aa
kinks in assumeComplete
author | catherine@dellzilla |
---|---|
date | Fri, 21 Nov 2008 17:56:28 -0500 |
parents | 8ba5127167f5 |
children | 10e917acf787 |
comparison
equal
deleted
inserted
replaced
155:8ba5127167f5 | 156:7e5a57df88aa |
---|---|
353 terminatorParser = pyparsing.oneOf(self.terminators)('terminator') | 353 terminatorParser = pyparsing.oneOf(self.terminators)('terminator') |
354 stringEnd = pyparsing.stringEnd ^ '\nEOF' | 354 stringEnd = pyparsing.stringEnd ^ '\nEOF' |
355 multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand') | 355 multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand') |
356 oneLineCommand = pyparsing.Word(pyparsing.printables)('command') | 356 oneLineCommand = pyparsing.Word(pyparsing.printables)('command') |
357 afterElements = \ | 357 afterElements = \ |
358 pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ stringEnd).setParseAction(lambda x: [y.strip() for y in x])('pipeTo')) + \ | 358 pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \ |
359 pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo')) | 359 pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo')) |
360 if self.caseInsensitive: | 360 if self.caseInsensitive: |
361 multilineCommand.setParseAction(lambda x: x[0].lower()) | 361 multilineCommand.setParseAction(lambda x: x[0].lower()) |
362 oneLineCommand.setParseAction(lambda x: x[0].lower()) | 362 oneLineCommand.setParseAction(lambda x: x[0].lower()) |
363 self.parser = ( | 363 self.parser = ( |
418 return | 418 return |
419 if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line): | 419 if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line): |
420 return | 420 return |
421 try: | 421 try: |
422 statement = self.parsed(line) | 422 statement = self.parsed(line) |
423 while statement.multilineCommand and not (statement.terminator or assumeComplete): | 423 if assumeComplete: |
424 statement = self.parsed('%s\n%s' % (statement.raw, | 424 if statement.multilineCommand and not statement.terminator: |
425 self.pseudo_raw_input(self.continuationPrompt))) | 425 statement = self.parsed(statement.raw + self.terminators[0]) |
426 else: | |
427 while statement.multilineCommand and not statement.terminator: | |
428 statement = self.parsed('%s\n%s' % (statement.raw, | |
429 self.pseudo_raw_input(self.continuationPrompt))) | |
426 except Exception, e: | 430 except Exception, e: |
427 print e | 431 print e |
428 return 0 | 432 return 0 |
429 | 433 |
430 statekeeper = None | 434 statekeeper = None |
568 raise NotSettableError | 572 raise NotSettableError |
569 currentVal = getattr(self, paramName) | 573 currentVal = getattr(self, paramName) |
570 if (val[0] == val[-1]) and val[0] in ("'", '"'): | 574 if (val[0] == val[-1]) and val[0] in ("'", '"'): |
571 val = val[1:-1] | 575 val = val[1:-1] |
572 else: | 576 else: |
573 val = cast(currentVal, self.parsed(val).unterminated) | 577 val = cast(currentVal, self.parsed(val).statement) |
574 setattr(self, paramName, val) | 578 setattr(self, paramName, val) |
575 self.stdout.write('%s - was: %s\nnow: %s\n' % (paramName, currentVal, val)) | 579 self.stdout.write('%s - was: %s\nnow: %s\n' % (paramName, currentVal, val)) |
576 except (ValueError, AttributeError, NotSettableError), e: | 580 except (ValueError, AttributeError, NotSettableError), e: |
577 self.do_show(arg) | 581 self.do_show(arg) |
578 | 582 |