How would people feel about this diff in the C syntax bundle? It will work on functions of the form:
int main () {
but not on
int main()
What would be the appropriate regexp for making it work in both cases? What I'm trying to do is get the functions to show up in the Symbols menu.
The other thing that's broken with C is that #defines which are not functions are incorrectly marked as functions. For instance:
#define FOOBAR 10
adds FOOBAR to the symbols menu. I think that's because the regexp that handles #defines tries to handle the case where the #define is really a macro
#define MIN(a,b) ((a)<(b)?(a):(b))
but applies the name even if the syntax doesn't match... I'll take a look at this later this week if no one has a workaround...
@@ -140,6 +140,20 @@ </array> </dict> <dict> + <key>captures</key> + <dict> + <key>1</key> + <dict> + <key>name</key> + <string>entity.name.function.c</string> + </dict> + </dict> + <key>match</key> + <string>^([a-zA-Z_][a-zA-Z0-9_]*)\s*(</string> + <key>name</key> + <string>source.c.function</string> + </dict> + <dict> <key>begin</key> <string>^\s*#\s*(define)\s+([a-zA-Z_][a-zA- Z0-9_]*)(?:( ((?:\s*[a-zA-Z_][a-zA-Z0-9_]*\s*,?)*))|\b)</string> <key>captures</key>
-- pgp fingerprint: BC64 2E7A CAEF 39E1 9544 80CA F7D5 784D FB46 16C1
On 10/11/2005, at 23.29, Oscar Bonilla wrote:
How would people feel about this diff in the C syntax bundle? It will work on functions of the form: [...]
While I appreciate your contribution, it does seem a little limited.
[...] What would be the appropriate regexp for making it work in both cases? What I'm trying to do is get the functions to show up in the Symbols menu.
The problem with just matching “«something» «something» («something»)” is that the pattern arise in a lot of places (in C++ at least) where it is not a function, and in addition, it doesn't catch all functions, e.g. the function result could be a complex (templated) type like: struct { int; } my_fun (…). Although maybe it's less important with these made-up (legal) cases, as no-one would probably declare functions like that.
Given that function declarations can only occur at root level, or as direct child of struct, class, or namespace, I think the best solution would be to rewrite the C grammar to know about these contexts -- it's something I could probably give a shoot, though it's a lot of work, since it really needs to know about a lot of the C(++) syntax, like initializer lists for constructors (which also look like function declarations) and could in practive be fooled by (bad) preprocessor usage.
But it's worth a shot -- although I'd prefer to wait till I add ability to (re-)apply rules to captures, so that I can recognize the primitive types correctly in all contexts, w/o having to resort to humongous regexp patterns.
The other thing that's broken with C is that #defines which are not functions are incorrectly marked as functions. For instance:
Oh, I did that on purpose, although only for the coloring (not thinking of the symbol popup at the time).
[...] I'll take a look at this later this week if no one has a workaround...
The rule is other.preprocessor.c -- it'd have to be two rules, with the one matching defines w/o arguments using another scope name (probably just add with/without-arg to the scope name (we do this a few other places as well), for which the showInSymbolList can then just be set) -- I'll gladly accept a patch for this change.
On 10/11/2005, at 23.29, Oscar Bonilla wrote:
[...] What would be the appropriate regexp for making it work in both cases?
Rob Rix worked it out (and I refined it slightly :) ):
{ name = 'declaration.function.c'; begin = '(?:^|(?<=[\w*&>])(?<!else|new|&&)\s+)([A-Za-z_][A-Za-z0-9_:] +)\s*((?=[^)]*)(\s+const)?\s*({|\n))'; end = ')'; beginCaptures = { 1 = { name = 'entity.name.function.c'; }; }; patterns = ( { include = "$base"; } ); },
It works pretty well — and it'll be part of the syntax with next build.
Cool. Thanks.
On Nov 14, 2005, at 5:04 PM, Allan Odgaard wrote:
On 10/11/2005, at 23.29, Oscar Bonilla wrote:
[...] What would be the appropriate regexp for making it work in both cases?
Rob Rix worked it out (and I refined it slightly :) ):
{ name = 'declaration.function.c'; begin = '(?:^|(?<=[\w*&>])(?<!else|new|&&)\s+)([A-Za-z_][A-Za- z0-9_:]+)\s*((?=[^)]*)(\s+const)?\s*({|\n))'; end = ')'; beginCaptures = { 1 = { name = 'entity.name.function.c'; }; }; patterns = ( { include = "$base"; } ); },
It works pretty well — and it'll be part of the syntax with next build.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
-- pgp fingerprint: BC64 2E7A CAEF 39E1 9544 80CA F7D5 784D FB46 16C1