Mercurial > python-cmd2
diff cmd2.py @ 169:429c8e984df4
all working, except \n\n terminators
author | catherine@dellzilla |
---|---|
date | Wed, 10 Dec 2008 14:50:42 -0500 |
parents | 786ab5a83eea |
children | 310ebf4baa7a |
line wrap: on
line diff
--- a/cmd2.py Mon Dec 08 17:58:37 2008 -0500 +++ b/cmd2.py Wed Dec 10 14:50:42 2008 -0500 @@ -182,6 +182,9 @@ noSpecialParse = 'set ed edit exit'.split() defaultExtension = 'txt' defaultFileName = 'command.txt' + singleQuotedStrings = True + doubleQuotedStrings = True + editor = os.environ.get('EDITOR') _STOP_AND_EXIT = 2 if not editor: @@ -226,7 +229,7 @@ commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment]) commentGrammars.addParseAction(lambda x: '') commentInProgress = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd) - quotedStringInProgress = pyparsing.Literal('"') ^ pyparsing.Literal("'") + pyparsing.SkipTo(pyparsing.stringEnd) + #quotedStringInProgress = pyparsing.Literal('"') ^ pyparsing.Literal("'") + pyparsing.SkipTo(pyparsing.lineEnd) terminators = [';', '\n\n'] multilineCommands = [] @@ -380,9 +383,7 @@ pipe = pyparsing.Keyword('|', identChars='|') self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '') self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment) - self.quotedStringInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString) - #for element in (terminatorParser, outputParser, pipe): - # element.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress).ignore(self.quotedStringInProgress) + #self.quotedStringInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString) afterElements = \ pyparsing.Optional(pipe + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \ pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo')) @@ -400,8 +401,8 @@ ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + pyparsing.Optional(terminatorParser) + afterElements) ) - self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress).ignore(self.quotedStringInProgress) - + self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) + inputMark = pyparsing.Literal('<') inputMark.setParseAction(lambda x: '') inputFrom = pyparsing.Word(self.legalChars + '/\\')('inputFrom')