whitequark/parser — pull request #154 by yujinakayama (2014-06-10 15:13:31+00:00)
Title: Introduce transaction for atomic rewrite actions

In RuboCop and Transpec, each independent class performs source rewrite and sometimes errors are raised by overlapped rewrite. In such case we rescue the error, save the source once, and perform the rewrite again. However there are some rewrite manipulations that consist of multiple rewrite actions (e.g. parenthesizing something by 2 insertions), and if one succeeds but another is failed, it possibly produces halfway and invalid source.

This change introduces `Parser::Source::Rewriter#transaction` which provides a protected block where a sequence of multiple rewrite actions are handled atomic. If any of the action is failed by clobbering, all the actions are rollbacked.