lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Depends on how much sophistication you want. Something like this could
probably be done fastest with a quick simple parser. Runtime
performance wouldn't be great, but it would be fairly straightforward.

something like

function parse_string(mystring)
  var tokens = {}
    next_token, mystring = consume_token(mystring)
    table.add(tokens, next_token)
  until next_token = nil
  return tokens

and write the consume_token ad hoc (switch on first character ",
consume and add all letters to the returnvalue until you find a ",
and return your value, and stripped string.

The back and forth stringwalking here is horrible, as wikll runtime
complexity be, but for shortish tokens it should be doable.

On Wed, Oct 5, 2011 at 8:02 PM, Petite Abeille <> wrote:
> Hello,
> What would be a reasonable way to, hmmm, quote unquoted tokens?
> Say a token is an uninterrupted sequence of alphanumeric characters (%w) or a quoted token. A quoted token is any sequence of characters inside quotes, minus any quote characters.
> For example:
> 'foo "hello world" bar'
> How to turn the above into:
> '"foo" "hello world" "bar"'
> Thoughts?