comparison cmd2.py @ 148:01ad9cd681a7

all but ignore seems to work
author catherine@dellzilla
date Thu, 20 Nov 2008 16:34:11 -0500
parents cda32481187c
children 2377461a35f3
comparison
equal deleted inserted replaced
147:cda32481187c 148:01ad9cd681a7
228 >>> print c.p2('command with args, terminator;sufx | piped').dump() 228 >>> print c.p2('command with args, terminator;sufx | piped').dump()
229 >>> print c.p2('simple | piped').dump() 229 >>> print c.p2('simple | piped').dump()
230 >>> print c.p2('output into > afile.txt').dump() 230 >>> print c.p2('output into > afile.txt').dump()
231 >>> print c.p2('output into;sufx | pipethrume plz > afile.txt').dump() 231 >>> print c.p2('output into;sufx | pipethrume plz > afile.txt').dump()
232 >>> print c.p2('output to paste buffer >> ').dump() 232 >>> print c.p2('output to paste buffer >> ').dump()
233 >>> print c.p2('ignore the /* commented | > */ stuff;') 233 >>> print c.p2('ignore the /* commented | > */ stuff;').dump()
234 ''' 234 '''
235 outputParser = pyparsing.oneOf(['>>','>'])('output') 235 outputParser = pyparsing.oneOf(['>>','>'])('output')
236 terminatorParser = pyparsing.oneOf(self.terminators)('terminator') 236 terminatorParser = pyparsing.oneOf(self.terminators)('terminator')
237 (pyparsing.stringEnd ^ pyparsing.oneOf(self.terminators) ^ '\nEOF' ^ '|' ^ outputParser)('terminator') 237 (pyparsing.stringEnd ^ pyparsing.oneOf(self.terminators) ^ '\nEOF' ^ '|' ^ outputParser)('terminator')
238 statementParser = pyparsing.Combine(pyparsing.Word(pyparsing.printables)('command') + 238 statementParser = pyparsing.Combine(pyparsing.Word(pyparsing.printables)('command') +
239 pyparsing.SkipTo(terminatorParser ^ '\nEOF' ^ '|' ^ outputParser ^ pyparsing.stringEnd)('args') + 239 pyparsing.SkipTo(terminatorParser ^ '\nEOF' ^ '|' ^ outputParser ^ pyparsing.stringEnd)('args') +
240 pyparsing.Optional(terminatorParser) 240 pyparsing.Optional(terminatorParser)
241 )('statement') 241 )('statement')
242 self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '')
243 self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment)
242 parser = statementParser + \ 244 parser = statementParser + \
243 pyparsing.SkipTo(outputParser ^ '|' ^ pyparsing.stringEnd)('suffix') + \ 245 pyparsing.SkipTo(outputParser ^ '|' ^ pyparsing.stringEnd)('suffix') + \
244 pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ pyparsing.stringEnd)('pipeDest')) + \ 246 pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ pyparsing.stringEnd)('pipeDest')) + \
245 pyparsing.Optional(outputParser + pyparsing.SkipTo(pyparsing.stringEnd)('outputDest')) 247 pyparsing.Optional(outputParser + pyparsing.SkipTo(pyparsing.stringEnd)('outputDest'))
246 self.commentGrammars.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).setParseAction(lambda x: '') 248 parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress)
247 self.commentInProgress.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(pyparsing.cStyleComment)
248 parser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress)
249 return parser.parseString(s) 249 return parser.parseString(s)
250 250
251 def parsed(self, s, assumeComplete=False): 251 def parsed(self, s, assumeComplete=False):
252 pass 252 pass
253 ''' 253 '''