Extracting function names (was: [SVN] Bundle commit 636 (C))
Allan Odgaard
allan at macromates.com
Fri Apr 22 00:36:12 UTC 2005
On Apr 22, 2005, at 0:44, Chris Thomas wrote:
> • Add a primitive declaration.function, partly based on the one Allan
> seems to have left in there. We'll have to see whether this is good
> enough for now or not. It's very much not perfect. You can't be
> perfect unless you embed a C interpreter, but you can do better than
> this. However, I think the only way to do a better job without a C
> intepreter is to maintain the curlybracket nesting level.
Yes, one option for handling curly braces could be something like (root
level patterns):
1. match = function prototypes
2. begin = "(namespace|class|struct).*{", end = "}", patterns =
include source.c
3. begin = {, end = }, patterns = all the normal stuff
4. include patterns from previous rule
So rule 2 is recursive, rule 3 is also recursive but doesn't include
from the root level (like rule 4), thus ditching rule 1.
The underlying system can handle this, but I haven't written the
handler for the include directive yet, to support arbitrary paths --
most likely I'll have that written for beta 7 (main problem is just how
to specify the path, the scopes are space-separated, but to remain
backwards compatible, I led the include still allow one to specify the
name of the syntax instead of the scopeName, which makes it ambiguous,
since the name can have spaces -- actually though, I do consider
requiring the UUID in the include statement, but maybe that's a bit too
unfriendly).
One problem with the above is that if the C++ language includes C, it
will lose the new rules it declares (inside curly braces). There also
still is a problem with C++ initializer lists.
Another option is to have the C parser as a plugin, but I doubt many
would write actual parsers even if I did add an API for this ;)
A third option is to only have functions optionally grabbed using the
scope system. This will most likely be how it ends: i.e. I'll add a
tool to TM to query documents using the scope system (or allow it
through AS), and by default to grab the function names it'll just run:
“tm_query 'declaration.function name'”, but it could instead be a grep
or ctags.
More information about the textmate-dev
mailing list