From: David Vallner Date: 2006-01-12T00:43:56+09:00 Subject: Re: ruby and parsing. Stephane Wirtel wrote: >Hi all, > >Firstly, Happy New Year :p > >Secondly, I have a c++ source code with many "try catch". > >try { > >} >catch (Exception &pException) { > >} > >I would like to parse my file and add a 'catch' with std::exception automatically, >to get the next example. > >try { > >} >catch (Exception &pException) { > >} >/// New catch added by a ruby script. >catch (std::exception &pException) { > >} > > >How can I do it ? Because I find some problems :( >1) Try to parse a lot of line with Regexp. >2) In the body of a 'catch', it can contains brackets > > >Best Regards, > >Stephane > > > I don't think Regexp is a viable alternative for this one - you might want to implement a trivial recursive-descent parser for C++, counting the opening and closing brackets after each catch clause. Unless the bodies of the exception handlers contain unmatched brackets in strings, that should work. David Vallner