Forum: Ruby ruby and parsing.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
356c59627d6c448194a2714850f306ad?d=identicon&s=25 Stephane Wirtel (Guest)
on 2006-01-11 13:35
(Received via mailing list)
Hi all,

Firstly, Happy New Year :p

Secondly, I have a c++ source code with many "try catch".

try {
	<BODY OF TRY>
}
catch (Exception &pException) {
	<BODY OF CATCH (for Exception)>
}

I would like to parse my file and add a 'catch' with std::exception
automatically,
to get the next example.

try {
	<BODY OF TRY>
}
catch (Exception &pException) {
	<BODY OF CATCH (for Exception)>
}
/// New catch added by a ruby script.
catch (std::exception &pException) {
	<Fill the body of this catch with the body of catch (for Exception).>
}


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
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-01-11 16:46
(Received via mailing list)
Stephane Wirtel wrote:

>	<BODY OF CATCH (for Exception)>
>}
>
>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
356c59627d6c448194a2714850f306ad?d=identicon&s=25 Stephane Wirtel (Guest)
on 2006-01-12 08:39
(Received via mailing list)
> 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.
Thanks David,

I will try this solution during my week.

Best Regards,

Stephane
This topic is locked and can not be replied to.