comparison cmd2.py @ 145:0e0fc729e1a2

accept special terminators on most anything
author catherine@dellzilla
date Wed, 19 Nov 2008 16:36:45 -0500
parents 2d3477aa79d4
children 9ffb01d8876f
comparison
equal deleted inserted replaced
144:2d3477aa79d4 145:0e0fc729e1a2
219 + pyparsing.Optional(filenamePattern)('outputTo') 219 + pyparsing.Optional(filenamePattern)('outputTo')
220 redirectInPattern = pyparsing.Literal('<')('input') \ 220 redirectInPattern = pyparsing.Literal('<')('input') \
221 + pyparsing.Optional(filenamePattern)('inputFrom') 221 + pyparsing.Optional(filenamePattern)('inputFrom')
222 punctuationPattern = pipePattern ^ redirectInPattern ^ redirectOutPattern 222 punctuationPattern = pipePattern ^ redirectInPattern ^ redirectOutPattern
223 223
224 def parsed(self, s): 224 def parsed(self, s, assumeComplete=False):
225 ''' 225 '''
226 >>> c = Cmd() 226 >>> c = Cmd()
227 >>> r = c.parsed('quotes "are > ignored" < inp.txt') 227 >>> r = c.parsed('quotes "are > ignored" < inp.txt')
228 >>> r.statement, r.input, r.inputFrom, r.output, r.outputFrom 228 >>> r.statement, r.input, r.inputFrom, r.output, r.outputFrom
229 ('quotes "are > ignored" ', '<', 'inp.txt', '', '') 229 ('quotes "are > ignored" ', '<', 'inp.txt', '', '')
263 result['statement'] = result.upToIncluding 263 result['statement'] = result.upToIncluding
264 result['unterminated'] = result.before 264 result['unterminated'] = result.before
265 result['parseable'] = result.after 265 result['parseable'] = result.after
266 else: 266 else:
267 # does not catch output marks 267 # does not catch output marks
268 if command in self.multilineCommands: 268 if (not assumeComplete) and (command in self.multilineCommands):
269 return result # don't bother with the rest, we're still collecting input 269 return result # don't bother with the rest, we're still collecting input
270 result['statement'] = result['unterminated'] = result.before
270 result += parseSearchResults(self.punctuationPattern, s) 271 result += parseSearchResults(self.punctuationPattern, s)
271 result['statement'] = result['unterminated'] = result.before
272 result += parseSearchResults(self.pipePattern, result.parseable) 272 result += parseSearchResults(self.pipePattern, result.parseable)
273 result += parseSearchResults(self.redirectInPattern, result.parseable) 273 result += parseSearchResults(self.redirectInPattern, result.parseable)
274 result += parseSearchResults(self.redirectOutPattern, result.parseable) 274 result += parseSearchResults(self.redirectOutPattern, result.parseable)
275 result += parseSearchResults(self.argSeparatorPattern, result.statement) 275 result += parseSearchResults(self.argSeparatorPattern, result.statement)
276 if self.caseInsensitive: 276 if self.caseInsensitive: