Mercurial > python-cmd2
comparison cmd2.py @ 401:3397b9c199f5
added postparse
author | catherine.devlin@gmail.com |
---|---|
date | Tue, 21 Sep 2010 15:25:56 -0400 |
parents | 2fccf9c87fe7 |
children | be18c88a0fc8 |
comparison
equal
deleted
inserted
replaced
400:2fccf9c87fe7 | 401:3397b9c199f5 |
---|---|
700 pyparsing.Optional(fileName) + (pyparsing.stringEnd | '|') | 700 pyparsing.Optional(fileName) + (pyparsing.stringEnd | '|') |
701 self.inputParser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) | 701 self.inputParser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) |
702 | 702 |
703 def preparse(self, raw, **kwargs): | 703 def preparse(self, raw, **kwargs): |
704 return raw | 704 return raw |
705 | 705 def postparse(self, parseResult): |
706 return parseResult | |
707 | |
706 def parsed(self, raw, **kwargs): | 708 def parsed(self, raw, **kwargs): |
707 if isinstance(raw, ParsedString): | 709 if isinstance(raw, ParsedString): |
708 p = raw | 710 p = raw |
709 else: | 711 else: |
710 # preparse is an overridable hook; default makes no changes | 712 # preparse is an overridable hook; default makes no changes |
716 s = s.replace(shortcut, expansion + ' ', 1) | 718 s = s.replace(shortcut, expansion + ' ', 1) |
717 break | 719 break |
718 result = self.parser.parseString(s) | 720 result = self.parser.parseString(s) |
719 result['raw'] = raw | 721 result['raw'] = raw |
720 result['command'] = result.multilineCommand or result.command | 722 result['command'] = result.multilineCommand or result.command |
723 result = self.postparse(result) | |
721 p = ParsedString(result.args) | 724 p = ParsedString(result.args) |
722 p.parsed = result | 725 p.parsed = result |
723 p.parser = self.parsed | 726 p.parser = self.parsed |
724 for (key, val) in kwargs.items(): | 727 for (key, val) in kwargs.items(): |
725 p.parsed[key] = val | 728 p.parsed[key] = val |