[TxMt] C Syntax
Allan Odgaard
throw-away-1 at macromates.com
Fri Nov 11 11:54:22 UTC 2005
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.
More information about the textmate
mailing list