diff cmd2.py @ 288:e743cf74c518

hooray, fixed bad comment parser - all unit tests pass
author catherine@bothari
date Thu, 29 Oct 2009 13:31:41 -0400
parents 1cd23003e8d5
children 327ace491fa9
line wrap: on
line diff
--- a/cmd2.py	Mon Oct 19 18:00:26 2009 -0400
+++ b/cmd2.py	Thu Oct 29 13:31:41 2009 -0400
@@ -387,7 +387,8 @@
     prefixParser = pyparsing.Empty()
     commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
     commentGrammars.addParseAction(lambda x: '')
-    commentInProgress  = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd)
+    commentInProgress  = pyparsing.Literal('/*') + pyparsing.SkipTo(
+        pyparsing.stringEnd ^ '*/')
     terminators = [';']
     blankLinesAllowed = False
     multilineCommands = []
@@ -550,6 +551,7 @@
           - terminator: ['\n', '\n']
         - terminator: ['\n', '\n']
         '''
+        tstr = 'multiline command /* with comment complete */ is done;'
         outputParser = (pyparsing.Literal('>>') | (pyparsing.WordStart() + '>') | pyparsing.Regex('[^=]>'))('output')
         
         terminatorParser = pyparsing.Or([(hasattr(t, 'parseString') and t) or pyparsing.Literal(t) for t in self.terminators])('terminator')
@@ -575,9 +577,9 @@
         self.multilineParser.ignore(self.commentInProgress)
         self.singleLineParser = ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') +
                                  pyparsing.Optional(terminatorParser) + afterElements)
-        self.multilineParser = self.multilineParser.setResultsName('multilineParser')
-        self.singleLineParser = self.singleLineParser.setResultsName('singleLineParser')
-        self.blankLineTerminationParser = self.blankLineTerminationParser.setResultsName('blankLineTerminatorParser')
+        #self.multilineParser = self.multilineParser.setResultsName('multilineParser')
+        #self.singleLineParser = self.singleLineParser.setResultsName('singleLineParser')
+        self.blankLineTerminationParser = self.blankLineTerminationParser.setResultsName('statement')
         self.parser = self.prefixParser + (
             stringEnd |
             self.multilineParser |
@@ -988,6 +990,7 @@
             self.perror('Error saving %s: %s' % (fname, str(e)))
             
     def read_file_or_url(self, fname):
+        # TODO: not working on localhost
         if isinstance(fname, file):
             result = open(fname, 'r')
         else: