changeset 69:824651b4d1b1

slash-endings working
author catherine@Elli.myhome.westell.com
date Mon, 23 Jun 2008 22:01:57 -0400
parents e06961ebd035
children 48b0bf2e3d2e
files cmd2.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Mon Jun 23 20:52:41 2008 -0400
+++ b/cmd2.py	Mon Jun 23 22:01:57 2008 -0400
@@ -128,6 +128,7 @@
             raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"')
         setPasteBuffer = getPasteBuffer
 
+pyparsing.ParserElement.setDefaultWhitespaceChars(' \t')    # see http://pyparsing.wikispaces.com/message/view/home/1352689    
 def punctuationParser(punctuators):
     """
     Produces a string parser based on a list of targets to search for.
@@ -137,7 +138,7 @@
     >>> p('is terminated;')
     ('is terminated', [';'], '')
     >>> p('is terminated EOF after the end')    
-    ('is terminated', ['EOF'], ' after the end')
+    ('is terminated', ['EOF'], 'after the end')
     >>> p('is not terminated')
     >>> pattern1 = pyparsing.Literal(';') + pyparsing.Optional(pyparsing.Word(pyparsing.nums))
     >>> p2 = punctuationParser([pattern1, 'EOF'])
@@ -164,7 +165,7 @@
         
 class Cmd(cmd.Cmd):
     caseInsensitive = True
-    terminators = [';','\n']    
+    terminators = [';', pyparsing.LineEnd() + pyparsing.LineEnd()]    
     multilineCommands = []          # commands that need a terminator to be finished
     terminatorKeepingCommands = []  # commands that expect to process their own terminators (else it will be stripped during parse)
     continuationPrompt = '> '    
@@ -190,8 +191,8 @@
         Commands may be terminated with: %(terminators)s
         Settable parameters: %(settable)s
         """ % 
-        { 'casesensitive': ('not ' and self.caseInsensitive) or '',
-          'terminators': ' '.join(str(self.terminators)),
+        { 'casesensitive': (self.caseInsensitive or '') and 'not ',
+          'terminators': str(self.terminators),
           'settable': ' '.join(self.settable)
         })