Frank,

These are all questions that I've been meaning to address in an update to my little tutorial, but paying work (whee!) has limited my time. Anyway, brief answers follow...

On 11/16/2006, Frank Mantek said:

a) I could not find anything in the docs about how to best test a named subpattern. i know how to test an unnamed numbered pattern, but to make sure the P<function_name> pattern works, i would really like to test it...

My guess is that by "numbered pattern" you mean "groups" (a.k.a. captures), and you're testing them by putting a \1 (or whatever) in the replace pattern.

You can't do that with "named subpatterns," unfortunately. BBEdit's replace field doesn't understand the names.

The only way to test it (that I know of) is to build your pattern piece by piece. I write the pattern in a separate text file with the file type set to "Grep Search" so that I get the syntax coloring.

The "function" pattern is usually the biggest one in the .plist file, and mine are usually made up of a set of smaller "named groups." For example, the function pattern often needs to understand strings and comments, so I build those patterns first. Then for a C-like language I have a subpattern that describes identifiers (variable names, types, classes, functions, etc.). I put that identfiier in the first place that it's needed, and then refer to it later wherever I might need it later.

Every time you add another piece, test it.

Sometimes the patterns start growing a bit out of control, especially when they become recursive (self-referential, where the contents of a named sub-pattern includes a reference to itself). This makes testing even harder... I burned a few hours trying to figure one of these out for someone else on this list, around the time I wrote that tutorial. My form of testing was to run the search and then sit there for a few minutes and examine every character (of the document being searched) to figure out what went wrong. :-)

That's another tip: start out with really simple test cases. The simpler the better. You'll need to make sure it works with more complicated stuff too, but make it work with childishly-simple samples first.

b) i know how to match the function line etc, but as my terminating char for the Name is the opening paranthesis, what i want to do is: find beginning of line, search for opening paranthesis, and now create a subpattern by going backwards and match an identifier name... How do i do that? Is that even possible?

If you're sure that an open parenthesis is all it takes to define a function, then it would be something like this:

^[ \t]*(?P<function_name>(?P<identifier>[a-z][a-z0-9_]*)(?:[ \t]+(?P>identifier))*)[ \t]*\(

Isn't that purdy? ;-)

(Watch out for line wrap. That's all one line.)

c) If i don't use the CDATA trick, i need to html encode all special chars inside the string? or just open/close <> ?

You should use the CDATA trick, or (as John suggests) the older form of the plist file. I have templates for both styles linked at the bottom of the tutorial. I can't think of any reason not to use one of those formats.

However, the answer to your question is that if you don't use the "CDATA trick," then you only need to encode the angle brackets, nothing else.

Oh, anyone else found documentation about this, beside the very brief part of the manual (i downloaded the SDK, to my suprise there is nothing on CLMs in there). And yes, i looked through Seth's excellent tutorial.

There hasn't been any other documentation released yet, that I'm aware of.

Seth


--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to