comparison cmd2.py @ 45:67cde3f501de

findpipe tested
author catherine@cordelia
date Tue, 03 Jun 2008 07:41:46 -0400
parents b66372883bb4
children 27b45b33a574
comparison
equal deleted inserted replaced
44:b66372883bb4 45:67cde3f501de
173 def do_shortcuts(self, args): 173 def do_shortcuts(self, args):
174 """Lists single-key shortcuts available.""" 174 """Lists single-key shortcuts available."""
175 result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items()) 175 result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items())
176 self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result)) 176 self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result))
177 177
178 pipeFinder = pyparsing.SkipTo(pyparsing.Literal('|') ^ pyparsing.StringEnd()) 178 notAPipe = pyparsing.SkipTo('|')
179 pipeFinder.ignore(pyparsing.sglQuotedString) 179 notAPipe.ignore(pyparsing.sglQuotedString)
180 pipeFinder.ignore(pyparsing.dblQuotedString) 180 notAPipe.ignore(pyparsing.dblQuotedString)
181 pipeFinder.ignore("--" + pyparsing.ZeroOrMore(pyparsing.CharsNotIn("\n"))) # sql-style comment 181 pipeFinder = notAPipe + '|' + pyparsing.SkipTo(pyparsing.StringEnd())
182 pipeFinder.ignore(pyparsing.cStyleComment) 182 def findPipe(self, statement):
183 try:
184 statement, pipe, destination = pipeFinder.parseString(statement)
185 return statement, destination
186 except pyparsing.ParseException:
187 return statement, None
183 188
184 legalFileName = re.compile(r'''^[^"'\s]+$''') 189 legalFileName = re.compile(r'''^[^"'\s]+$''')
185 def parseRedirector(self, statement, symbol, mustBeTerminated=False): 190 def parseRedirector(self, statement, symbol, mustBeTerminated=False):
186 # pipeFinder.scanString(statement) 191 # pipeFinder.scanString(statement)
187 parts = statement.split(symbol) 192 parts = statement.split(symbol)