<div dir="ltr"><div>shlex is for shell-like lexers, but you can use Racket's lexer to achieve what you want in this particular case:<br>(port->list read (open-input-string "one two three \"four five\""))<br>
; -> '(one two three "four five")<br></div><div><br>You get symbols and strings, but you can convert them to strings only if you want:<br>(map ~a (port->list read (open-input-string "one two three \"four five\"")))<br>
; -> '("one" "two" "three" "four five")<br><br></div><div>This won't work for single-quoted string though, because single quotes don't have a string meaning in Lisp/Scheme/Racket:<br>
(port->list read (open-input-string "one two three 'four five'"))<br>; -> Error: read: expected an element for quoting ' (found end-of-file)<br><br></div><div>You can then use the parser tools:<br>
<a href="http://docs.racket-lang.org/parser-tools/">http://docs.racket-lang.org/parser-tools/</a><br><br></div><div></div><div>HTH</div>Laurent<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 16, 2013 at 10:16 PM, Richard Parsons <span dir="ltr"><<a href="mailto:richard.lee.parsons@gmail.com" target="_blank">richard.lee.parsons@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Hi there, I'm new to Racket.<br><br></div>I'm trying to split strings on whitespace except when quoted, such as this:<br>
<br></div>"one two three \"four five\"" => '("one" "two" "three" "four five")<br>
<br></div><div>In Python, this could be done with shlex.split().<br></div><div><br></div>Perhaps I could do it with a lexer?<br><br>Perhaps I could do it with regular expressions?<br><br></div>Perhaps the source code for current-command-line-arguments could show me how to do it, although I can't work out how to locate it.<br>
<br>Any suggestions anyone?<br><br></div><div>Many thanks<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888">Richard<br>
</font></span></div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>