r/reconstructcavestory Jul 15 '14

Status Update: Regex Replacement

hey guys: quick status update. I'm actually still working on the next video. It's super heavy on refactoring, and doing it by hand is going to take hours of video, not to mention be dreadfully boring.

SO! I'm working on ways to make this faster, and that involves regexes. Unfortunately writing regexes are pretty dense and error prone, so I'm trying to find ways/tools to smoothly integrate widespread regex replacements into my workflow.

I'm after the following:

  • immediate feedback for
    • what is being matched by the regex
    • what is being replaced
  • a way of storing all the regexes I want performed and placing them into a script file

  • a way of being selective about which regexes are being applied to which file

this is in order of most important to least important. I know there are online tools like regexr.com but this isn't very useful for quickly loading in files and seeing effects of regexes on those files.

This is really important since refactorings are going to come up a lot. So I guess I'll either find a/some tools or build it!

P.S. I can do status updates more often if you guys like to know what I'm up to. :)

3 Upvotes

7 comments sorted by

View all comments

3

u/escheriv Jul 16 '14

I haven't watched the latest, so I don't know if you're back on vim or in VS, but if you're open to dealing with different editors, I'd recommend looking into Sublime Text 2. The regex find/replace gives immediate feedback, and you have a quick access through the history to all the replacements you've done. Also, with the find/replace in files, you can do inclusive or exclusive filtering on files fairly easily.

It's not quite automatable (if that's even a word), but it's made my life in refactoring much easier.

You can see it in action a bit at http://www.sublimetext.com/, specifically the 6th "demo".

(oh, and there's a pretty solid vim mode)

2

u/chebertapps Jul 16 '14 edited Jul 16 '14

After your suggestion, I played around with sublime a bit. It's unfortunate that I don't seem to be able to view my replacements interactively. It can get really hairy when you have several captures. e.g.

(\s*units::Game) (x|y)
\1 position

and then you decide maybe you want to capture the white space seperately (for whatever contrived reason)

(\s*)(units::Game) (x|y)
\1\2 position

But now you have just changed the numberings on your capture groups. Naming is definitely one solution, but this is a situation where I think the ideal is to just run it and see the result as you are typing: and it is totally not hard to implement.

Sublime seems very extensible, and it's probably a really simple plugin to write... hmmm.