Saturday, October 16, 2010

CodeAssistor - Command Entry Implemented

So for the past week I've added the Command Entry to CodeAssistor.

Right now I've only implemented the search/replace functionality, but the framework now exists to start adding all sorts of awesomeness

So how does it work?

Open up a file and press the ESC key. You'll notice the entry popup

type '/' to start searching, then type in a regular expression (thats right, I said regular expression!)
eg "/#define (.*?) " (thats a space after the (.*?) , dont include the quote marks)

This will find the first #define XXX (but only #define XXX even if there is a #define XXX YYY)
Press ENTER. You've now moved to the next occurrence.

So what about replacing?

Ok continue your Command Entry so that the string looks like
"/#define (.+?) (.*)$/#ifdef \1\n#undef \1\n#endif\n#define \1 \2"
you'll notice that this doesn't replace. It's important to give the user a method of writing out the full regular expression and replacement string.

To actually replace the find add a final "/" to the command entry string... like this:
"/#define (.+?) (.*)$/#ifdef \1\n#undef \1\n#endif\n#define \1 \2/"

The library I am using for regular expressions (the basic scintilla regular expressions derived from Ozan Yigit's library plus some '?' extensions I did myself) doesn't (yet) understand the | metacharacter, so you'll have to write a separate line for "/#define ([^\s]+)$" (aka empty macros)

Thursday, October 14, 2010

Half a Days labour

Hello Source fans!

I just realized a nice anecdotal metric due to some CodeAssitor work I did today.

I noticed when I sat down to work on some regular expression stuff for CA that it was ~1:30 in the afternoon, for some flakey reason, my brain made a mental timestamp. When I finished the feature I was working on I noticed that the time wasy ~5:30.

What's interesting is I completed one whole feature (or at least got the feature from 0 to code complete... which means there hasn't been extensive testing), and quite literally nothing else (no washing breaks, no coffee reheats, no email checking, nothing but code.

The day previous I worked on adding the 0-1 quantifier (?) to Scintilla's basic Regular expression code (RESearch.cxx), and got that feature code complete... unfortunately I didn't notice the time and I was very distracted watching the Chilean miners get free (CHI-CHI-CH LEI-LEI-LEI!), and was doing numerous other things.

Anyway... So I sit down in front of my computer to work on some CodeAssistor stuff and notice the time is 1:34. I check the Scintilla Mailing list to see someone had posted a reply to my ? quantifier work, and someone had. Here is Philippe's email:

On 13/10/2010 20:36, Michael Mullin wrote:
> I've added a small patch to add the ? operator to the built in regular
> expressions in the scintilla version used in CodeAssistor. I haven't
> done any extensive testing, so I guess this is a bit of a 'code
> review.'
> Anyone see bugs? Do you think this patch is useful for the main
> scintilla branch?

Yes, if it works... For this, you should:
- Fix indentation...
- Add documentation of the new operator in the documentation at the start of the file.
The semantic of the operator isn't clear. From a quick glance at the code, it looks like
it is used in place of * with the meaning of 0 or 1 occurrence of the previous token, not
as a modifier to make an operator non-greedy, right?
The latter would be more useful, but it much harder (if possible) to inject in the current
engine. The former can still be useful, though...
Philippe Lhoste
-- (near) Paris -- France
-- -- -- -- -- -- -- -- -- -- -- -- -- --
So for the next 4 hours I
1) added the lazy operator functionality
2) did up the spacing how he wanted + documentation

Anyways, it was 5:27 when I finished.

The most interesting part of this endeavor is that you can see just exactly what I accomplished during those 4 hours.

Anyways, I thought this was an interesting piece of data. Especially because I wasn't planning on timing myself, so I didn't change my work effort at all.

Note: its 5:44 as I finish this blog.