Mercurial > python-cmd2
comparison cmd2.py @ 210:3f8fac776845
end wed
author | catherine@dellzilla |
---|---|
date | Tue, 10 Mar 2009 16:42:06 -0400 |
parents | 6dc79bf15fc6 |
children | 5da7d72e72ee |
comparison
equal
deleted
inserted
replaced
209:6dc79bf15fc6 | 210:3f8fac776845 |
---|---|
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 ''' | |
486 for (shortcut, expansion) in self.shortcuts.items(): | 485 for (shortcut, expansion) in self.shortcuts.items(): |
487 if s.lower().startswith(shortcut): | 486 if s.lower().startswith(shortcut): |
488 s = s.replace(shortcut, expansion + ' ', 1) | 487 s = s.replace(shortcut, expansion + ' ', 1) |
489 break | 488 break |
490 ''' | |
491 result = self.parser.parseString(s) | 489 result = self.parser.parseString(s) |
492 result['command'] = result.multilineCommand or result.command | 490 result['command'] = result.multilineCommand or result.command |
493 result['raw'] = raw | 491 result['raw'] = raw |
494 result['clean'] = self.commentGrammars.transformString(result.args) | 492 result['clean'] = self.commentGrammars.transformString(result.args) |
495 result['expanded'] = s | 493 result['expanded'] = s |
512 This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`. | 510 This (`cmd2`) version of `onecmd` already override's `cmd`'s `onecmd`. |
513 | 511 |
514 """ | 512 """ |
515 if not line: | 513 if not line: |
516 return self.emptyline() | 514 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 | |
521 if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line): | 515 if not pyparsing.Or(self.commentGrammars).setParseAction(lambda x: '').transformString(line): |
522 return 0 # command was empty except for comments | 516 return 0 # command was empty except for comments |
523 try: | 517 try: |
524 statement = self.parsed(line) | 518 statement = self.parsed(line) |
525 while statement.parsed.multilineCommand and (statement.parsed.terminator == ''): | 519 while statement.parsed.multilineCommand and (statement.parsed.terminator == ''): |