# HG changeset patch # User catherine@dellzilla # Date 1228938642 18000 # Node ID 429c8e984df4f25f9f4dc9facdca9b020345656d # Parent 786ab5a83eea42a136e616142e8e5208a02b5461 all working, except \n\n terminators diff -r 786ab5a83eea -r 429c8e984df4 cmd2.py --- 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') diff -r 786ab5a83eea -r 429c8e984df4 example/exampleSession.txt --- a/example/exampleSession.txt Mon Dec 08 17:58:37 2008 -0500 +++ b/example/exampleSession.txt Wed Dec 10 14:50:42 2008 -0500 @@ -2,18 +2,6 @@ Calling `example.py -t` runs it as a series of unit tests, verifying that the same output is still returned. -(Cmd) speak the /* hidden comment */ text -the text -(Cmd) speak the "unhidden quote" text -the "unhidden quote" text -(Cmd) speak "unhidden quote" text -"unhidden quote" text -(Cmd) orate "unhidden quote" text; -"unhidden quote" text -(Cmd) orate "not ; terminated; just; yet" -> now I end; -"not ; terminated; just; yet" -now I end (Cmd) help Documented commands (type help ): @@ -105,9 +93,16 @@ (Cmd) # comments do nothing (Cmd) /* C-style comments */ say are invisible are invisible -(Cmd) orate and they don't /* interfere; +(Cmd) orate and they do not /* interfere; > with multiline */ commands; -and they don't commands; +and they do not commands +(Cmd) speak the /* hidden comment */ text +the text +(Cmd) speak the "unhidden quote" text +the "unhidden quote" text +(Cmd) # Quoted strings immediately following the command are NOT included in the arguments - +(Cmd) # this is due to a bug in pyparsing. See: +(Cmd) # https://sourceforge.net/tracker/index.php?func=detail&aid=2412233&group_id=97203&atid=617311 (Cmd) set prompt "---> " prompt - was: (Cmd) now: --->