Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Tim Daneliuk Newsgroups: comp.lang.python Subject: Re: Quotation Ugliness Date: Wed, 26 Nov 2014 00:04:15 -0600 Organization: A noiseless patient Spider Lines: 55 Message-ID: <54756D5F.4040806@tundraware.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="d887b3e675279b69468e57e74ea1dcb8"; logging-data="23337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2A6IcZJbDPoTiheTOaljqUCSUDw2VddI=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: Cancel-Lock: sha1:zfndUBFWS8SjG0mrrp4HKkliZoU= Xref: csiph.com comp.lang.python:81547 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/