diff cmd2.py @ 45:67cde3f501de

findpipe tested
author catherine@cordelia
date Tue, 03 Jun 2008 07:41:46 -0400
parents b66372883bb4
children 27b45b33a574
line wrap: on
line diff
--- a/cmd2.py	Mon May 26 13:54:45 2008 -0400
+++ b/cmd2.py	Tue Jun 03 07:41:46 2008 -0400
@@ -175,11 +175,16 @@
         result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items())
         self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result))
 
-    pipeFinder = pyparsing.SkipTo(pyparsing.Literal('|') ^ pyparsing.StringEnd())
-    pipeFinder.ignore(pyparsing.sglQuotedString)
-    pipeFinder.ignore(pyparsing.dblQuotedString)
-    pipeFinder.ignore("--" + pyparsing.ZeroOrMore(pyparsing.CharsNotIn("\n"))) # sql-style comment
-    pipeFinder.ignore(pyparsing.cStyleComment)
+    notAPipe = pyparsing.SkipTo('|')
+    notAPipe.ignore(pyparsing.sglQuotedString)
+    notAPipe.ignore(pyparsing.dblQuotedString)    
+    pipeFinder = notAPipe + '|' + pyparsing.SkipTo(pyparsing.StringEnd())
+    def findPipe(self, statement):
+        try:
+            statement, pipe, destination = pipeFinder.parseString(statement)
+            return statement, destination
+        except pyparsing.ParseException:
+            return statement, None
     
     legalFileName = re.compile(r'''^[^"'\s]+$''')
     def parseRedirector(self, statement, symbol, mustBeTerminated=False):