Mercurial > python-cmd2
comparison cmd2.py @ 160:59b7847ec3ca
little fixes
author | catherine@dellzilla |
---|---|
date | Mon, 01 Dec 2008 13:43:35 -0500 |
parents | 5a94501b6b93 |
children | 1d1439be0a55 |
comparison
equal
deleted
inserted
replaced
159:5a94501b6b93 | 160:59b7847ec3ca |
---|---|
374 outputParser = pyparsing.oneOf(['>>','>'])('output') | 374 outputParser = pyparsing.oneOf(['>>','>'])('output') |
375 terminatorParser = pyparsing.oneOf(self.terminators)('terminator') | 375 terminatorParser = pyparsing.oneOf(self.terminators)('terminator') |
376 stringEnd = pyparsing.stringEnd ^ '\nEOF' | 376 stringEnd = pyparsing.stringEnd ^ '\nEOF' |
377 multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand') | 377 multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand') |
378 oneLineCommand = pyparsing.Word(self.legalChars + pyparsing.alphanums + pyparsing.alphas8bit)('command') | 378 oneLineCommand = pyparsing.Word(self.legalChars + pyparsing.alphanums + pyparsing.alphas8bit)('command') |
379 pipe = pyparsing.Keyword('|', identChars='|') | |
379 afterElements = \ | 380 afterElements = \ |
380 pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \ | 381 pyparsing.Optional(pipe + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \ |
381 pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo')) | 382 pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo')) |
382 if self.caseInsensitive: | 383 if self.caseInsensitive: |
383 multilineCommand.setParseAction(lambda x: x[0].lower()) | 384 multilineCommand.setParseAction(lambda x: x[0].lower()) |
384 oneLineCommand.setParseAction(lambda x: x[0].lower()) | 385 oneLineCommand.setParseAction(lambda x: x[0].lower()) |
385 self.parser = ( | 386 self.parser = ( |
386 pyparsing.stringEnd | 387 pyparsing.stringEnd |
387 ^ | 388 ^ |
388 (((multilineCommand ^ oneLineCommand) + pyparsing.SkipTo(terminatorParser).setParseAction(lambda x: x[0].strip())('args') + terminatorParser)('statement') + | 389 (((multilineCommand ^ oneLineCommand) + pyparsing.SkipTo(terminatorParser).setParseAction(lambda x: x[0].strip())('args') + terminatorParser)('statement') + |
389 pyparsing.SkipTo(outputParser ^ '|' ^ stringEnd).setParseAction(lambda x: x[0].strip())('suffix') + afterElements) | 390 pyparsing.SkipTo(outputParser ^ pipe ^ stringEnd).setParseAction(lambda x: x[0].strip())('suffix') + afterElements) |
390 ^ | 391 ^ |
391 multilineCommand + pyparsing.SkipTo(pyparsing.stringEnd) | 392 multilineCommand + pyparsing.SkipTo(pyparsing.stringEnd) |
392 ^ | 393 ^ |
393 ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ '|' ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + | 394 ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + |
394 pyparsing.Optional(terminatorParser) + afterElements) | 395 pyparsing.Optional(terminatorParser) + afterElements) |
395 ) | 396 ) |
396 self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '') | 397 self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '') |
397 self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment) | 398 self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment) |
398 self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) | 399 self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) |