Illusory stillness

mumble mumble techblog

Editing Structured Regexes Interactively in Emacs

I was using regex-builder to make something, but it still looked like this:

1
"^ *\\([^:(\t\n]+\\)\\(:\\([0-9]+\\)\\)?\\(:\\([0-9]+\\)\\)?\\(: \\(\\(\\w\\|\\s_\\)+\\|\\[\\(\\w\\|\\s \\)+\\]\\)\\)?\\(: \\(.*\\)\\)?"

Leaning-toothpicks syndrome is kicking my ass. What if I write a regex using S-expressions? Wouldn’t that be the bee’s knees?

Well, one thing I can do use use the rx macro, but re-builder doesn’t seem to want to work with it. I call (reb-change-syntax) to select ‘rx’ but it only performs a search sometimes? And often finds no matches?

Debugging from this impetus I get to stepping through reb-update-overlays but I can’t inspect the value of local variables in either edebug or debug for some weird reason. (Because of -*- lexical-binding:t -*- in the file.)

New yak frame: how to inspect vars in lexically bound code? It’s probably impossible, though there was an incomplete thread about it a couple years ago.

Well, I guess I’ll debug it by adding messages.

Now, I find that when I use (rx (one-or-more "/")), that macro should expand to "/+" but but the regexp we search for is actually "\\(?:/\\+\\)" which doesn’t look like a proper regex. What is reb-target-binding doing? Pulling the binding from the target buffer. What’s reb-cook-regexp doing? Calling rx-to-string on the result of an rx macro. Which it shouldn’t?

Oh, I was typing

1
(rx (one-or-more ":"))

in the buffer like a sucker (idk, that’s what you would write in Elisp?). Turns out I need to type

1
'(one-or-more ":")

So how do I do a longer regex????? Use and/seq. It should be called progn, shouldn’t it? Turns out I should write in regexp-builder like

1
'(seq (one-or-more ":") (class )

So now I write regexps in regexp-builder like:

1
2
3
4
5
'(seq bol (zero-or-more " ")
      (group (one-or-more (not (char ":\n\t"))))
      (zero-or-one ":" (group (one-or-more digit)))
      (zero-or-one ":" (group (one-or-more digit)))
      (zero-or-one ": " (group (one-or-more (or (syntax word) (syntax symbol))))))

and then paste the (seq ...) into an (rx ...) macro when I’m done.

Well, there’s one more problem. Sometimes I can type a correct regexp and it won’t update (it actually removes all highlights). Seems to have something to do with regexp-builder behaving inappropriately when an edit doesn’t change the compiled form of the regexp. But I can then call (reb-force-update) and it does, that’ll work for now.