Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!news.ecp.fr!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'syntax': 0.04; 'problem:': 0.07; 'tries': 0.07; 'string': 0.09; 'parsing': 0.09; 'pgp': 0.09; 'skip:/ 10': 0.09; 'bullet': 0.16; 'descending': 0.16; 'finney': 0.16; 'general.': 0.16; 'sudo': 0.16; 'well-known': 0.16; 'worst': 0.16; 'language': 0.16; 'wrote:': 0.18; 'library': 0.18; 'obviously': 0.18; 'trying': 0.19; 'solution.': 0.20; 'command': 0.22; 'appears': 0.22; 'input': 0.22; 'header:User-Agent:1': 0.23; 'errors.': 0.24; 'instance,': 0.24; 'own.': 0.24; 'passes': 0.24; 'text.': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'wondering': 0.29; 'tim': 0.29; 'specified': 0.30; "i'm": 0.30; 'convince': 0.31; 'writes:': 0.31; 'yourself.': 0.31; 'this.': 0.32; 'problem': 0.35; 'skip:u 20': 0.35; 'case,': 0.35; 'one,': 0.35; 'but': 0.35; 'there': 0.35; 'possible': 0.36; 'changing': 0.37; 'requirements': 0.37; 'ben': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'simple,': 0.60; 'solve': 0.60; 'simple': 0.61; 'first': 0.61; 'such': 0.63; 'determine': 0.67; '*this': 0.68; 'bite': 0.84; 'fails,': 0.84; 'mature': 0.84; 'pain': 0.84; 'recover': 0.91; 'acknowledge': 0.93 Date: Wed, 26 Nov 2014 00:04:15 -0600 From: Tim Daneliuk User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 Newsgroups: comp.lang.python To: Ben Finney , python-list@python.org Subject: Re: Quotation Ugliness References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (ozzie.tundraware.com [75.145.138.73]); Wed, 26 Nov 2014 00:04:16 -0600 (CST) X-TundraWare-MailScanner-Information: Please contact the ISP for more information X-TundraWare-MailScanner-ID: sAQ64FZn060887 X-TundraWare-MailScanner: Found to be clean X-TundraWare-MailScanner-From: tundra@tundraware.com X-Spam-Status: No X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416981872 news.xs4all.nl 2906 [2001:888:2000:d::a6]:57770 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81545 On 11/25/2014 07:54 PM, Ben Finney wrote: > Tim Daneliuk writes: > >> Here's the problem: Determine is the string S appears *outside* or >> *inside* any such quotation. > > This is a problem for parsing text. There is no general, simple > solution. > > If someone tries to convince you they have one, be highly suspicious: it > will either be not general, or not simple, or neither simple nor general. > >> I know lots of ugly/complicated/heavyweight ways to solve this, but >> I'm wondering if any of you geniuses have a pythonic/elegant/short >> algo that solves this. > > I would recommend one of the following, in descending order of > preference: > > * Try very hard to change the requirements so that the input must be in > a mature well-known format for which there are *existing*, maintained, > reliable parsers. Use those instead of rolling your own. > > * If that fails, then: Try very hard to drastically simplify the > specified input format so that every possible input is either > obviously invalid, or obviously has exactly one meaning. > > * If that fails, then: Bite the bullet and acknowledge you will be > entering the complexities of parsing text. Use a mature library for > writing your parser; don't attempt to write a parsing library > yourself. *This is the worst option*; changing the requirements for > input will be much less pain than this. > In this case, I am not trying to write a fullblown language or recover from syntax errors. Here's a usecase - I want to know whether I need to use a sudo password when the user passes a command on the command line of a program: someprog.py uname && sudo cat /etc/sudoers vs. someprog.py uname && echo "sudo cat /etc/suoders" In the first instance, I need the sudo passoword, in the second I don't. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/