comparison cmd2.py @ 249:55a12d77a4fa

finally, ls working right
author catherine@Elli.myhome.westell.com
date Mon, 30 Mar 2009 13:15:28 -0400
parents 575652efb3d8
children ff541573fb5b
comparison
equal deleted inserted replaced
248:575652efb3d8 249:55a12d77a4fa
314 self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result)) 314 self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result))
315 315
316 prefixParser = pyparsing.Empty() 316 prefixParser = pyparsing.Empty()
317 commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment]) 317 commentGrammars = pyparsing.Or([pyparsing.pythonStyleComment, pyparsing.cStyleComment])
318 commentGrammars.addParseAction(lambda x: '') 318 commentGrammars.addParseAction(lambda x: '')
319 commentInProgress = ((pyparsing.White() | pyparsing.lineStart) + 319 commentInProgress = pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd)
320 pyparsing.Literal('/*') + pyparsing.SkipTo(pyparsing.stringEnd))
321 # `blah/*` means `everything in directory `blah`, not comment
322 terminators = [';'] 320 terminators = [';']
323 blankLinesAllowed = False 321 blankLinesAllowed = False
324 multilineCommands = [] 322 multilineCommands = []
325 323
326 def _init_parser(self): 324 def _init_parser(self):
505 self.multilineParser = (((self.multilineCommand ^ oneLineCommand) + SkipToLast(terminatorParser).setParseAction(lambda x: x[0].strip())('args') + terminatorParser)('statement') + 503 self.multilineParser = (((self.multilineCommand ^ oneLineCommand) + SkipToLast(terminatorParser).setParseAction(lambda x: x[0].strip())('args') + terminatorParser)('statement') +
506 pyparsing.SkipTo(outputParser ^ pipe ^ stringEnd).setParseAction(lambda x: x[0].strip())('suffix') + afterElements) 504 pyparsing.SkipTo(outputParser ^ pipe ^ stringEnd).setParseAction(lambda x: x[0].strip())('suffix') + afterElements)
507 self.singleLineParser = ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') + 505 self.singleLineParser = ((oneLineCommand + pyparsing.SkipTo(terminatorParser ^ stringEnd ^ pipe ^ outputParser).setParseAction(lambda x:x[0].strip())('args'))('statement') +
508 pyparsing.Optional(terminatorParser) + afterElements) 506 pyparsing.Optional(terminatorParser) + afterElements)
509 self.multilineParser = self.multilineParser.setResultsName('multilineParser') 507 self.multilineParser = self.multilineParser.setResultsName('multilineParser')
508 self.multilineParser.ignore(self.commentInProgress)
510 self.singleLineParser = self.singleLineParser.setResultsName('singleLineParser') 509 self.singleLineParser = self.singleLineParser.setResultsName('singleLineParser')
511 self.blankLineTerminationParser = self.blankLineTerminationParser.setResultsName('blankLineTerminatorParser') 510 self.blankLineTerminationParser = self.blankLineTerminationParser.setResultsName('blankLineTerminatorParser')
512 self.parser = ( 511 self.parser = (
513 stringEnd | 512 stringEnd |
514 self.prefixParser + self.multilineParser | 513 self.prefixParser + self.multilineParser |
515 self.prefixParser + self.singleLineParser | 514 self.prefixParser + self.singleLineParser |
516 self.prefixParser + self.blankLineTerminationParser | 515 self.prefixParser + self.blankLineTerminationParser |
517 self.prefixParser + self.multilineCommand + pyparsing.SkipTo(stringEnd) 516 self.prefixParser + self.multilineCommand + pyparsing.SkipTo(stringEnd)
518 ) 517 )
519 self.parser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) 518 self.parser.ignore(pyparsing.quotedString).ignore(self.commentGrammars)
520 519
521 inputMark = pyparsing.Literal('<') 520 inputMark = pyparsing.Literal('<')
522 inputMark.setParseAction(lambda x: '') 521 inputMark.setParseAction(lambda x: '')
523 fileName = pyparsing.Word(self.legalChars + '/\\') 522 fileName = pyparsing.Word(self.legalChars + '/\\')
524 inputFrom = fileName('inputFrom') 523 inputFrom = fileName('inputFrom')