<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <br>
    Thank you Dan for answering.<br>
    <br>
    I ended with this and gave up with shlex:<br>
    <br>
    split = ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
    '-option3', 'TAG']<br>
    <br>
    procedure_found = False<br>
    result          = []<br>
    <br>
    for token in split:<br>
        if not token.startswith('[') and not token.endswith(']') and not
    procedure_found:<br>
            result.append(token)<br>
        elif token.startswith('['):<br>
            procedure_found = True<br>
            _token = token<br>
        elif token.endswith(']'):<br>
            procedure_found = False<br>
            _token += ' ' + token<br>
            result.append(_token)<br>
        else:<br>
            _token += ' ' + token<br>
    <br>
    print split<br>
    print result<br>
    <br>
    which gives the desired values:<br>
    <br>
    ['-option1', '[get_rule', 'A1', 'B2]', '-option2', '$VAR',
    '-option3', 'TAG']<br>
    ['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3',
    'TAG']<br>
    <br>
    <br>
    Sure pyParsing seems to be pretty simple but my constraint is to use<br>
    standard lib (at maximum). To bad it is not part of python standard
    libs.<br>
    On the other hand, I will have to regroup expression like '-option1
    $VAL == $CONSTRAINT'<br>
    in ['-option1', '$VAL == $CONSTRAINT'].<br>
    <br>
    So it seems that I have no others choicse and have to use a parser
    like pyParsing.<br>
    <br>
    Regards<br>
    Karim<br>
    <br>
    On 07/27/2011 10:44 PM, Dan Stromberg wrote:
    <blockquote
cite="mid:CAGGBd_ry0sOMyh5EFrYftwNAtoVrOybwo-ctx6BXQUERaPnRTg@mail.gmail.com"
      type="cite"><br>
      I've not used the shlex module, but this feels more like an issue
      to address with a parser than for a lexical analyzer - or perhaps
      even both, since you're splitting on whitespace sometimes, and
      matching square brackets sometimes.<br>
      <br>
      I've used pyparsing for stuff a bit similar to this.<br>
      <br>
      Or here's a list:<br>
      <a moz-do-not-send="true"
        href="http://wiki.python.org/moin/LanguageParsing">http://wiki.python.org/moin/LanguageParsing</a><br>
      <br>
      <div class="gmail_quote">
        On Wed, Jul 27, 2011 at 12:30 PM, Karim <span dir="ltr"><<a
            moz-do-not-send="true" href="mailto:karim.liateni@free.fr">karim.liateni@free.fr</a>></span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <br>
          Hello All,<br>
          <br>
          I would like to parse this TCL command line with shlex:<br>
          <br>
          '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG'<br>
          <br>
          And I want to get the splitted list:<br>
          <br>
          ['-option1', '[get_rule A1 B2]', '-option2',  '$VAR',
          '-option3',  'TAG']<br>
          <br>
          Then I will gather in tuple 2 by 2 the arguments.<br>
          <br>
          I tried to the shlec properties attributes 'quotes',
          'whitespace', etc...<br>
          <br>
          But I make 'choux blanc'.<br>
          <br>
          If somebody has complex experiences with  this module I am in.<br>
          <br>
          Cheers<br>
          Karim<br>
          <font color="#888888">
            -- <br>
            <a moz-do-not-send="true"
              href="http://mail.python.org/mailman/listinfo/python-list"
              target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
          </font></blockquote>
      </div>
      <br>
    </blockquote>
    <br>
  </body>
</html>