From 30528921d36e4084b0582c740a5e47a59e81e907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Fri, 21 Mar 2008 16:47:17 +0000 Subject: [PATCH] Update TCL parser from CTags SVN which adds new symbol types for classes and methods (closes #1918748). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2380 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 ++ src/symbols.c | 1 + tagmanager/tcl.c | 112 ++++++++++++++++++++++++++++++----------------- 3 files changed, 77 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index c32a0917..0e1020be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,9 @@ documentation. * data/snippets.conf: Add better "for" completion for Python. + * tagmanager/tcl.c, src/symbols.c: + Update TCL parser from CTags SVN which adds new symbol types for + classes and methods (closes #1918748). 2008-03-21 Nick Treleaven diff --git a/src/symbols.c b/src/symbols.c index c5c31ea6..cdeb5e3b 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -648,6 +648,7 @@ static void init_tag_list(gint idx) /*&(tv_iters.tag_other), _("Other"), NULL);*/ break; } + case GEANY_FILETYPES_TCL: case GEANY_FILETYPES_PYTHON: { tag_list_add_groups(tag_store, diff --git a/tagmanager/tcl.c b/tagmanager/tcl.c index 7c18c118..fa6abe5b 100644 --- a/tagmanager/tcl.c +++ b/tagmanager/tcl.c @@ -1,6 +1,7 @@ /* +* $Id$ * -* Copyright (c) 2000-2001, Darren Hiebert +* Copyright (c) 2000-2003, Darren Hiebert * * This source code is released for free distribution under the terms of the * GNU General Public License. @@ -11,7 +12,7 @@ /* * INCLUDE FILES */ -#include "general.h" /* must always come first */ +#include "general.h" /* must always come first */ #include @@ -23,60 +24,93 @@ * DATA DEFINITIONS */ typedef enum { - K_PROCEDURE + K_CLASS, K_METHOD, K_PROCEDURE } tclKind; static kindOption TclKinds [] = { - { TRUE, 'f', "function", "procedures" } + { TRUE, 'c', "class", "classes" }, + { TRUE, 'm', "member", "methods" }, + { TRUE, 'p', "function", "procedures" } }; /* * FUNCTION DEFINITIONS */ -static void findTclTags (void) +static const unsigned char *makeTclTag ( + const unsigned char *cp, + vString *const name, + const tclKind kind) { - vString *name = vStringNew (); - const unsigned char *line; - - while ((line = fileReadLine ()) != NULL) - { - int i; - - if (line [0] == '\0' || line [0] == '#') - continue; - - /* read first word */ - for (i = 0 ; line [i] != '\0' && ! isspace (line [i]) ; ++i) - ; - - if (strncmp ((const char*) line, "proc", (size_t) 4) == 0) + vStringClear (name); + while ((int) *cp != '\0' && ! isspace ((int) *cp)) { - const unsigned char *cp = line + i; - while (isspace ((int) *cp)) - ++cp; - while (line [i] != '\0' && ! isspace ((int) *cp)) - { vStringPut (name, (int) *cp); ++cp; - } - vStringTerminate (name); - makeSimpleTag (name, TclKinds, K_PROCEDURE); - vStringClear (name); } - } - vStringDelete (name); + vStringTerminate (name); + makeSimpleTag (name, TclKinds, kind); + return cp; +} + +static boolean match (const unsigned char *line, const char *word) +{ + return (boolean) (strncmp ((const char*) line, word, strlen (word)) == 0); +} + +static void findTclTags (void) +{ + vString *name = vStringNew (); + const unsigned char *line; + + while ((line = fileReadLine ()) != NULL) + { + const unsigned char *cp; + + while (isspace (line [0])) + ++line; + + if (line [0] == '\0' || line [0] == '#') + continue; + + /* read first word */ + for (cp = line ; *cp != '\0' && ! isspace ((int) *cp) ; ++cp) + ; + if (! isspace ((int) *cp)) + continue; + while (isspace ((int) *cp)) + ++cp; + /* Now `line' points at first word and `cp' points at next word */ + + if (match (line, "proc")) + cp = makeTclTag (cp, name, K_PROCEDURE); + else if (match (line, "class") || match (line, "itcl::class")) + cp = makeTclTag (cp, name, K_CLASS); + else if (match (line, "public") || + match (line, "protected") || + match (line, "private")) + { + if (match (cp, "method")) + { + cp += 6; + while (isspace ((int) *cp)) + ++cp; + cp = makeTclTag (cp, name, K_METHOD); + } + } + } + vStringDelete (name); } extern parserDefinition* TclParser (void) { - static const char *const extensions [] = { "tcl", "tk", "wish", NULL }; - parserDefinition* def = parserNew ("Tcl"); - def->kinds = TclKinds; - def->kindCount = KIND_COUNT (TclKinds); - def->extensions = extensions; - def->parser = findTclTags; - return def; + static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL }; + parserDefinition* def = parserNew ("Tcl"); + def->kinds = TclKinds; + def->kindCount = KIND_COUNT (TclKinds); + def->extensions = extensions; + def->parser = findTclTags; + return def; } -/* vi:set tabstop=8 shiftwidth=4: */ +/* vi:set tabstop=4 shiftwidth=4: */