4 * Copyright (c) 2000-2003, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for generating tags for TCL scripts.
15 #include "general.h" /* must always come first */
27 K_CLASS
, K_METHOD
, K_PROCEDURE
, K_MODULE
30 static kindOption TclKinds
[] = {
31 { TRUE
, 'c', "class", "classes" },
32 { TRUE
, 'f', "member", "methods" },
33 { TRUE
, 'p', "function", "procedures" },
34 { TRUE
, 'm', "namespace", "modules" }
38 * FUNCTION DEFINITIONS
41 static const unsigned char *makeTclTag (
42 const unsigned char *cp
,
47 while ((int) *cp
!= '\0' && ! isspace ((int) *cp
))
49 vStringPut (name
, (int) *cp
);
52 vStringTerminate (name
);
53 makeSimpleTag (name
, TclKinds
, kind
);
57 static boolean
match (const unsigned char *line
, const char *word
)
59 size_t len
= strlen (word
);
60 boolean matched
= (strncmp ((const char*) line
, word
, len
) == 0);
64 /* check that the word is followed by a space to avoid detecting something
65 * like "proc_new ..." */
66 matched
= isspace (*(line
+ len
));
71 static void findTclTags (void)
73 vString
*name
= vStringNew ();
74 const unsigned char *line
;
76 while ((line
= fileReadLine ()) != NULL
)
78 const unsigned char *cp
;
80 while (isspace (line
[0]))
83 if (line
[0] == '\0' || line
[0] == '#')
87 for (cp
= line
; *cp
!= '\0' && ! isspace ((int) *cp
) ; ++cp
)
89 if (! isspace ((int) *cp
))
91 while (isspace ((int) *cp
))
93 /* Now `line' points at first word and `cp' points at next word */
95 if (match (line
, "proc"))
96 cp
= makeTclTag (cp
, name
, K_PROCEDURE
);
97 else if (match (line
, "class") || match (line
, "itcl::class"))
98 cp
= makeTclTag (cp
, name
, K_CLASS
);
99 else if (match (line
, "public") ||
100 match (line
, "protected") ||
101 match (line
, "private"))
103 if (match (cp
, "method"))
106 while (isspace ((int) *cp
))
108 cp
= makeTclTag (cp
, name
, K_METHOD
);
111 else if (match (line
, "method"))
113 cp
= makeTclTag (cp
, name
, K_METHOD
);
115 else if (match (line
, "oo::class") ) {
116 if (match (cp
, "create"))
119 while (isspace ((int) *cp
))
121 cp
= makeTclTag (cp
, name
, K_CLASS
);
124 else if (match (line
, "namespace") ) {
125 if (match (cp
, "eval"))
128 while (isspace ((int) *cp
))
130 cp
= makeTclTag (cp
, name
, K_MODULE
);
135 vStringDelete (name
);
138 extern parserDefinition
* TclParser (void)
140 static const char *const extensions
[] = { "tcl", "tk", "wish", "itcl", NULL
};
141 parserDefinition
* def
= parserNew ("Tcl");
142 def
->kinds
= TclKinds
;
143 def
->kindCount
= KIND_COUNT (TclKinds
);
144 def
->extensions
= extensions
;
145 def
->parser
= findTclTags
;
149 /* vi:set tabstop=4 shiftwidth=4: */