comparison cmd2.py @ 168:786ab5a83eea

quotes still getting snipped, ugh
author catherine@dellzilla
date Mon, 08 Dec 2008 17:58:37 -0500
parents a38303571916
children 429c8e984df4
comparison
equal deleted inserted replaced
167:a38303571916 168:786ab5a83eea
376 terminatorParser = pyparsing.oneOf(self.terminators)('terminator') 376 terminatorParser = pyparsing.oneOf(self.terminators)('terminator')
377 stringEnd = pyparsing.stringEnd ^ '\nEOF' 377 stringEnd = pyparsing.stringEnd ^ '\nEOF'
378 multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand') 378 multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand')
379 oneLineCommand = pyparsing.Word(self.legalChars)('command') 379 oneLineCommand = pyparsing.Word(self.legalChars)('command')
380 pipe = pyparsing.Keyword('|', identChars='|') 380 pipe = pyparsing.Keyword('|', identChars='|')
381 self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '')
382 self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment)
383 self.quotedStringInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString)
384 #for element in (terminatorParser, outputParser, pipe):
385 # element.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress).ignore(self.quotedStringInProgress)
381 afterElements = \ 386 afterElements = \
382 pyparsing.Optional(pipe + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \ 387 pyparsing.Optional(pipe + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \
383 pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo')) 388 pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo'))
384 if self.caseInsensitive: 389 if self.caseInsensitive:
385 multilineCommand.setParseAction(lambda x: x[0].lower()) 390 multilineCommand.setParseAction(lambda x: x[0].lower())
393 multilineCommand + pyparsing.SkipTo(pyparsing.stringEnd) 398 multilineCommand + pyparsing.SkipTo(pyparsing.stringEnd)
394 ^ 399 ^
395 ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + 400 ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') +
396 pyparsing.Optional(terminatorParser) + afterElements) 401 pyparsing.Optional(terminatorParser) + afterElements)
397 ) 402 )
398 self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '') 403 self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress).ignore(self.quotedStringInProgress)
399 self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment) 404
400 self.quotedStringInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString)
401 self.parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress).ignore(self.quotedStringInProgress)
402
403 inputMark = pyparsing.Literal('<') 405 inputMark = pyparsing.Literal('<')
404 inputMark.setParseAction(lambda x: '') 406 inputMark.setParseAction(lambda x: '')
405 inputFrom = pyparsing.Word(self.legalChars + '/\\')('inputFrom') 407 inputFrom = pyparsing.Word(self.legalChars + '/\\')('inputFrom')
406 inputFrom.setParseAction(lambda x: (x and open(x[0]).read()) or getPasteBuffer()) 408 inputFrom.setParseAction(lambda x: (x and open(x[0]).read()) or getPasteBuffer())
407 self.inputParser = inputMark + pyparsing.Optional(inputFrom) 409 self.inputParser = inputMark + pyparsing.Optional(inputFrom)