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


Groups > comp.lang.python > #10506

Re: shlex parsing

Date 2011-07-29 11:37 +0200
From Karim <karim.liateni@free.fr>
Subject Re: shlex parsing
References <mailman.1538.1311795072.1164.python-list@python.org> <4e3184d3$0$29530$426a74cc@news.free.fr> <pan.2011.07.28.16.37.35.287000@nowhere.com> <4e32618d$0$23657$426a74cc@news.free.fr>
Newsgroups comp.lang.python
Message-ID <mailman.1607.1311932260.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 07/29/2011 09:24 AM, Web Dreamer wrote:
> Nobody a écrit ce jeudi 28 juillet 2011 18:37 dans
> <pan.2011.07.28.16.37.35.287000@nowhere.com>  :
>
>> On Thu, 28 Jul 2011 17:48:34 +0200, Web Dreamer wrote:
>>
>>>> I would like to parse this TCL command line with shlex:
>>>>
>>>> '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'
>>>>>> s = s.replace('[','"[')
>>>>>> s = s.replace(']',']"')
>> Note that this approach won't work if you have nested brackets or braces.
>> That would require a real parser.
> True,
> I tried with the shlex class, but adding '[]' to a shlexobject.quotes
> doesn't work.
> Indeed, shlex expects an opening and closing quote to be the same, and [ is
> different from ] so shlex therefore expects an opening [ to be closed with [
> and not ]
>
> My solution indeed only works as long as there are not any nested brackets.
>
Yeah I saw that shlex object behavior is slighty different from 
shlex.split()
fonction. the char minus by default is taken as a individual word and in 
split
it is not. get_token() method return '-' alone and you have to set 
object attributes
wordchars += '-' to have the same behavior as shlex.split().

Cheers
Karim

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


Thread

shlex parsing Karim <karim.liateni@free.fr> - 2011-07-27 21:30 +0200
  Re: shlex parsing Web Dreamer <webdreamer@nospam.fr> - 2011-07-28 17:48 +0200
    Re: shlex parsing Karim <karim.liateni@free.fr> - 2011-07-28 18:21 +0200
    Re: shlex parsing Nobody <nobody@nowhere.com> - 2011-07-28 17:37 +0100
      Re: shlex parsing Karim <karim.liateni@free.fr> - 2011-07-28 19:51 +0200
        Re: shlex parsing Web Dreamer <webdreamer@nospam.fr> - 2011-07-29 09:30 +0200
      Re: shlex parsing Web Dreamer <webdreamer@nospam.fr> - 2011-07-29 09:24 +0200
        Re: shlex parsing Karim <karim.liateni@free.fr> - 2011-07-29 11:37 +0200
          Re: shlex parsing Web Dreamer <webdreamer@nospam.fr> - 2011-07-29 15:42 +0200
            Re: shlex parsing Karim <karim.liateni@free.fr> - 2011-07-29 16:34 +0200

csiph-web