------art_113890_28079218.1156370740379
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

The below works, excpet for the case highlighted, but its a start!

j`ey
http://www.eachmapinject.com

class String
  def get_args
   (split(/(.*[^(].*),(.*[^)].*)/) - [""]).map{|e| e.strip}
  end
end
require 'test/unit'

class TestArgumentParser < Test::Unit::TestCase
  def test_simple_cases
    assert_equal %w[ a b ],         'a,b'.get_args
    assert_equal %w[ a_frog b25 ],  'a_frog, b25'.get_args
  end
  def test_embedded_parens
    assert_equal %w[ a(1) b ],      'a(1), b'.get_args
    assert_equal %w[ a b(i) ],      'a, b(i)'.get_args
  end
  def test_embedded_parens_with_commas
    assert_equal %w[ a(0,j) b ],    'a(0,j),b'.get_args
    assert_equal %w[ a() b(j,k) ],  'a(),b(j,k)'.get_args ## doesnt work
    assert_equal %w[ c(i,j,t(1)) ], 'c(i,j,t(1))'.get_args
  end
end
On 8/23/06, QApassion <bhoang / verance.com> wrote:
>
>
> Hi,
>
> How about parsing a parameter list with embedded white space between two
> words and EOF?
>
> Thanks,
> -----------------------------------------
>
> Bil Kleb wrote:
> >
> > Hello,
> >
> > Can someone please point me at a simple recipe for
> > parsing a parameter list with embedded parentheses
> > and commas, e.g.,
> >
> >   class String
> >     def get_args
> >       split(',').map{|e| e.strip} # naive recipe
> >     end
> >   end
> >
> >   require 'test/unit'
> >
> >   class TestArgumentParser < Test::Unit::TestCase
> >     def test_simple_cases
> >       assert_equal %w[ a b ],         'a,b'.get_args
> >       assert_equal %w[ a_frog b25 ],  'a_frog, b25'.get_args
> >     end
> >     def test_embedded_parens
> >       assert_equal %w[ a(1) b ],      'a(1), b'.get_args
> >       assert_equal %w[ a b(i) ],      'a, b(i)'.get_args
> >     end
> >     def test_embedded_parens_with_commas
> >       assert_equal %w[ a(0,j) b ],    'a(0,j),b'.get_args
> >       assert_equal %w[ a() b(j,k) ],  'a(),b(j,k)'.get_args
> >       assert_equal %w[ c(i,j,t(1)) ], 'c(i,j,t(1))'.get_args
> >     end
> >   end
> >
> > Thanks,
> > --
> > Bil
> > http://fun3d.larc.nasa.gov
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/argument-parsing-with-embedded-parentheses-tf1461223.html#a5953306
> Sent from the ruby-talk forum at Nabble.com.
>
>
>

------art_113890_28079218.1156370740379--