comparison cmd2.py @ 209:6dc79bf15fc6

trying move of shortcut expansion
author catherine@dellzilla
date Tue, 10 Mar 2009 09:48:04 -0400
parents f10bd1f0c7e3
children 3f8fac776845
comparison
equal deleted inserted replaced
208:f10bd1f0c7e3 209:6dc79bf15fc6
480 def parsed(self, raw, **kwargs): 480 def parsed(self, raw, **kwargs):
481 if isinstance(raw, ParsedString): 481 if isinstance(raw, ParsedString):
482 p = raw 482 p = raw
483 else: 483 else:
484 s = self.inputParser.transformString(raw.lstrip()) 484 s = self.inputParser.transformString(raw.lstrip())
485 '''
485 for (shortcut, expansion) in self.shortcuts.items(): 486 for (shortcut, expansion) in self.shortcuts.items():
486 if s.lower().startswith(shortcut): 487 if s.lower().startswith(shortcut):
487 s = s.replace(shortcut, expansion + ' ', 1) 488 s = s.replace(shortcut, expansion + ' ', 1)
488 break 489 break
490 '''
489 result = self.parser.parseString(s) 491 result = self.parser.parseString(s)
490 result['command'] = result.multilineCommand or result.command 492 result['command'] = result.multilineCommand or result.command
491 result['raw'] = raw 493 result['raw'] = raw
492 result['clean'] = self.commentGrammars.transformString(result.args) 494 result['clean'] = self.commentGrammars.transformString(result.args)
493 result['expanded'] = s 495 result['expanded'] = s
510 This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`. 512 This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`.
511 513
512 """ 514 """
513 if not line: 515 if not line:
514 return self.emptyline() 516 return self.emptyline()
517 for (shortcut, expansion) in self.shortcuts.items():
518 if line.lower().lstrip().startswith(shortcut):
519 line = line.replace(shortcut, expansion + ' ', 1)
520 break
515 if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line): 521 if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line):
516 return 0 # command was empty except for comments 522 return 0 # command was empty except for comments
517 try: 523 try:
518 statement = self.parsed(line) 524 statement = self.parsed(line)
519 while statement.parsed.multilineCommand and (statement.parsed.terminator == ''): 525 while statement.parsed.multilineCommand and (statement.parsed.terminator == ''):