Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!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: Tue, 25 Nov 2014 19:18:52 -0600 Organization: A noiseless patient Spider Lines: 51 Message-ID: <54752A7C.2060800@tundraware.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="d887b3e675279b69468e57e74ea1dcb8"; logging-data="10996"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9lEJpbxCqMzPYYW6IqkZCq9YIeuzPX28=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: Cancel-Lock: sha1:R/exwM0lbsjY0YME1sqK4wQezFw= Xref: csiph.com comp.lang.python:81534 On 11/25/2014 06:40 PM, Tim Chase wrote: > On 2014-11-25 18:18, Tim Daneliuk wrote: >> A problem for your consideration: >> >> We are given a tuple of delimiter string pairs to quote or comment >> text, possibly over multiple lines. Something like this: >> >> delims = (('"', '"'), ("'", "'"), ('#', '\n'), ("\*", "*\), >> ('\\', '\n') ...) >> >> These may be nested. >> >> Here's the problem: Determine is the string S appears *outside* or >> *inside* any such quotation. > > > You would have to define what should happen in a case where you have > more than one single/double-quote delimited items on the same line: > > do("this", "and", "that") Each of them is considered quoted and thus if S appears within any of them it is "inside". > > should it return true or false when testing for 'this", "and", > "that'? (it is within double-quotes) False. > > And what should happen with mismatched quotes? > > do("th/*is", "and", "th*/at") Match pairs as usual, and let the remaining unterminated quote run on. > > It would also help to have a proposed function signature for the > functionality you want. Something like > > def inside_quote(s, corpus, delims=delims): I'd prefer: def quoted (s, corpus, delims=delims, domain=outside) ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/