On 9/11/2006, Graham Nelson said:
Thanks - but I was asking if it's possible to use PCREs for things _other_
than functions, for instance, to specify comment opening and closing,
and/or block opening and closing, etc. Somebody here said that it was, but
that this isn't documented yet!
Yes, that was me.
There are at least two other supported patterns: one for
strings, and one for comments.
Here's an example string pattern which supports both single and
double quotes, and forces strings to stop at the end of the line.
<key>String Pattern</key>
<string>(?x:
(?> ' (?s: \\. | [^'] )*? (?: ' | $ ) ) |
(?> " (?s: \\. | [^"] )*? (?: " | $ ) )
)</string>
The "(?x:" puts the pattern into extended mode (I think that's
what it's called), and remember the "(?>" is just the
XML-entity version of "(?>" because the above is taken from a
.plist XML file.
Comments work the same way. Here's a pattern that supports both
/* inline */ and // rest-of-line comment syntax:
<key>Comment Pattern</key>
<string>(?x:
(?> // .* $ ) |
(?> /\* (?s:.*?) (?: \*/ | \z ) )
)</string>
BBEdit actually sets these up as "named subpatterns", so that
you can reference them (function, comment, and string) within
each other. For example, your function pattern might look like this:
<key>Function Pattern</key>
<string>(?x:
(?P<function>
(?P<function_name>
[ _0-9A-Za-z]+
)
\s*
(?>
(?P>comment)
\s*
)*
\s*
(?P<block>
\{
(?:
(?>
(?> [^[{}]+ ) |
(?: - (?!-) ) |
(?: / (?!\*) ) |
(?P>comment) |
(?P>string) |
(?P>function) |
(?P>block)
)
)*
\}
)
)
)</string>
(That's perhaps not the most useful example, as it's too simple
for many languages, but it does demonstrate how you'd refer from
one pattern to another, and how a pattern can even refer to itself.
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]>