Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81531

Re: Quotation Ugliness

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'pop': 0.05; 'definitions': 0.07; 'nested': 0.07; 'parser': 0.07; 'problem:': 0.07; 'strict': 0.07; 'string': 0.09; 'definition,': 0.09; 'lines.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '\'"\'),': 0.16; "'\\n')": 0.16; 'definitions,': 0.16; 'delimiter': 0.16; 'empty,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hashes': 0.16; 'line).': 0.16; 'list)': 0.16; 'markers,': 0.16; 'nest': 0.16; 'nesting': 0.16; 'pairs': 0.16; 'stack;': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'stack': 0.19; '(the': 0.22; 'appears': 0.22; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'text,': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'correct': 0.29; 'am,': 0.29; 'tim': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'though.': 0.31; 'extend': 0.32; 'another': 0.32; 'quite': 0.32; 'not.': 0.33; 'comment': 0.34; 'problem': 0.35; 'something': 0.35; 'definition': 0.35; 'usual': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'building': 0.35; 'data,': 0.36; 'programming,': 0.36; 'step': 0.37; 'sometimes': 0.38; 'nov': 0.38; 'that,': 0.38; 'little': 0.38; 'quote': 0.39; 'according': 0.40; 'skip:u 10': 0.60; 'worry': 0.60; 'simple': 0.61; "you're": 0.61; 'such': 0.63; 'talking': 0.65; 'determine': 0.67; '26,': 0.68; '(any': 0.84; '(probably': 0.84; 'characters,': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=PVyFjXvLJPfT9ccS3JRxZhi2IUuZiMhh6L1mnxHHEjo=; b=ozk8AxNZ1hB2lrtVwbV14f+OZyJAeAoRmuPmEtLMIb+fOHD9pWdwUmh8wHFY8GQWRN VwVLvRgyuJY/ZK9xi2CNdA2xHgEktzh9LE16hO3dyzc+vYTQYdTUJXmp5FFW0U6bXIgt nx3G/4yWzAg9yxn7J1DU8X9PAoLCOzYM8omCi8NdbhBHnWvTXbsUZPiroDRp3FSQkyoM cbfTfVfEdr9uIrhlBMhwQTWmEW+6ffMk901jMPt4p9VCKXADEGcA8L9+HgKkpORzkzhK 9XlH7HfH8TUF9x+nSj+UThb49Abhp2NGnnhbJ6IKq2jZeG5XRx2xcCENnV7/gyYzDR67 YYow==
MIME-Version 1.0
X-Received by 10.50.171.193 with SMTP id aw1mr20687209igc.2.1416962699326; Tue, 25 Nov 2014 16:44:59 -0800 (PST)
In-Reply-To <grifkb-kpo1.ln1@ozzie.tundraware.com>
References <grifkb-kpo1.ln1@ozzie.tundraware.com>
Date Wed, 26 Nov 2014 11:44:59 +1100
Subject Re: Quotation Ugliness
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16298.1416962702.18130.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416962702 news.xs4all.nl 2941 [2001:888:2000:d::a6]:36200
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 5639
X-Received-Body-CRC 891886849
Xref csiph.com comp.lang.python:81531

Show key headers only | View raw


On Wed, Nov 26, 2014 at 11:18 AM, Tim Daneliuk <tundra@tundraware.com> 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.

Be aware that, according to the usual definitions, some of those don't
nest... and others may or may not. If you're talking about comment
characters, for instance, /* /* */ */ sometimes nests and sometimes
doesn't; but # # \n \n definitely doesn't nest (two hashes on a line
doesn't extend the comment to another line). Also, they're usually
slashes, not backslashes.

But if your definitions are simple and strict (any of these may be
nested and to any level) and correct (the tuple is exactly the pairs
you're after), then your best bet would be to step through the data,
building up a stack (probably in a Python list) of currently-open
delimiters. As you find open-quote markers, you add to the stack; any
time you find the top-of-stack closing delimiter, you pop it off. When
you find the string S, if the stack is empty, it's outside; otherwise,
it's inside.

You may have issues with your definition of nesting, though. For
instance, what's it mean if you have double-quotes, then a hash? In
normal programming, the hash isn't significant. If that's your
definition, then the only nesting you need worry about is /* and */,
so your parser is quite simple: when you find any opener, you seek its
corresponding closer, and then special-case /* to count any additional
/* and look for a */ for each one */ .

At the moment, the problem's a little underspecified.

ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 18:18 -0600
  Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-25 18:40 -0600
    Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:18 -0600
      Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-26 12:32 +1100
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:00 -0600
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:00 -0600
    Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:18 -0600
  Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-26 11:44 +1100
    Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:20 -0600
    Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-25 19:20 -0600
      Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-25 19:44 -0600
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:01 -0600
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:01 -0600
  Re: Quotation Ugliness Ben Finney <ben+python@benfinney.id.au> - 2014-11-26 12:54 +1100
    Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:04 -0600
    Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 00:04 -0600
      Using a password with ‘sudo’ (was: Quotation Ugliness) Ben Finney <ben+python@benfinney.id.au> - 2014-11-26 18:02 +1100
      Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-26 18:10 +1100
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:59 -0600
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:59 -0600
      Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-26 06:56 -0600
        Re: Quotation Ugliness Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-11-26 15:45 +0200
          Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 01:37 +1100
          Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-26 08:26 -0600
          Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:07 +1100
          Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:09 +1100
            Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:36 -0600
            Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:36 -0600
              Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:48 +1100
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:55 -0600
                Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 11:00 -0500
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:02 -0600
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:02 -0600
                Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 03:13 +1100
                Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 11:16 -0500
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:54 -0600
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:54 -0600
                Re: Quotation Ugliness alister <alister.nospam.ware@ntlworld.com> - 2014-11-26 16:45 +0000
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 10:54 -0600
                Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:55 -0600
              Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 10:53 -0500
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:58 -0600
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 08:58 -0600
          Re: Quotation Ugliness Chris Angelico <rosuav@gmail.com> - 2014-11-27 02:06 +1100
          Re: Quotation Ugliness Tim Chase <python.list@tim.thechases.com> - 2014-11-26 09:23 -0600
          Re: Quotation Ugliness Ben Finney <ben+python@benfinney.id.au> - 2014-11-27 07:24 +1100
      Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 09:12 -0500
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:02 -0600
        Re: Quotation Ugliness Tim Daneliuk <tundra@tundraware.com> - 2014-11-26 09:02 -0600
          Re: Quotation Ugliness random832@fastmail.us - 2014-11-26 10:16 -0500

csiph-web