Mercurial > python-cmd2
diff lineend.py @ 65:4e028e9ec4c2
punctFinder going to go in
author | catherine@Elli.myhome.westell.com |
---|---|
date | Mon, 23 Jun 2008 12:51:37 -0400 |
parents | a0f7702f2a4b |
children |
line wrap: on
line diff
--- a/lineend.py Sat Jun 21 19:54:57 2008 -0400 +++ b/lineend.py Mon Jun 23 12:51:37 2008 -0400 @@ -1,8 +1,8 @@ import pyparsing, sys, doctest -intgr = pyparsing.Optional(pyparsing.Word(pyparsing.nums)) -terminators = [pyparsing.Literal(';') + intgr, - pyparsing.Literal('\\t') + intgr] +integer_pattern = pyparsing.Optional(pyparsing.Word(pyparsing.nums)) +terminators = [pyparsing.Literal(';') + integer_pattern, + pyparsing.Literal('\\t') + integer_pattern] complete_pattern = reduce(lambda x, y: x ^ y, terminators) redirect_pattern = pyparsing.oneOf('< >') + pyparsing.restOfLine pipe_pattern = pyparsing.Literal('|') + pyparsing.restOfLine @@ -11,21 +11,21 @@ pattern.ignore(pyparsing.sglQuotedString) pattern.ignore(pyparsing.dblQuotedString) -def parse(txt, mustBeTerminated=False): +def parse(txt): """ - >>> sorted(parse('select * from dual;', True).items()) + >>> sorted(parse('select * from dual;').items()) [('inputFrom', None), ('outputTo', None), ('pipeTo', None), ('terminator', [';'])] - >>> sorted(parse('select * from dual E', True).items()) + >>> sorted(parse('select * from dual E').items()) [('inputFrom', None), ('outputTo', None), ('pipeTo', None), ('terminator', None)] - >>> sorted(parse('select * from', True).items()) + >>> sorted(parse('select * from').items()) [('inputFrom', None), ('outputTo', None), ('pipeTo', None), ('terminator', None)] - >>> sorted(parse('select * from dual; > result.txt', True).items()) + >>> sorted(parse('select * from dual; > result.txt').items()) [('inputFrom', None), ('outputTo', 'result.txt'), ('pipeTo', None), ('terminator', [';'])] - >>> sorted(parse("select * from dual where val = 'x > y'", True).items()) + >>> sorted(parse("select * from dual where val = 'x > y'").items()) [('inputFrom', None), ('outputTo', None), ('pipeTo', None), ('terminator', None)] - >>> sorted(parse('select * from dual; | wc -c', True).items()) + >>> sorted(parse('select * from dual; | wc -c').items()) [('inputFrom', None), ('outputTo', None), ('pipeTo', 'wc -c'), ('terminator', [';'])] - >>> sorted(parse('select * from dual; | sort > sorted.txt', True).items()) + >>> sorted(parse('select * from dual; | sort > sorted.txt').items()) [('inputFrom', None), ('outputTo', None), ('pipeTo', 'sort > sorted.txt'), ('terminator', [';'])] """ result = {'inputFrom': None, 'outputTo': None, 'pipeTo': None, 'terminator': None}