Quotation Ugliness

Tim Daneliuk tundra at tundraware.com
Tue Nov 25 20:18:52 EST 2014


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 at tundraware.com
PGP Key:         http://www.tundraware.com/PGP/




More information about the Python-list mailing list