manual: added documentation about replacement of 'untitled.ext' with filename (#1804)
[geany-mirror.git] / ctags / parsers / tcl.c
blob2b43b7ba6645fb66d80e9981791308c52e4757c4
1 /*
2 * Copyright (c) 2000-2003, Darren Hiebert
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
7 * This module contains functions for generating tags for TCL scripts.
8 */
11 * INCLUDE FILES
13 #include "general.h" /* must always come first */
15 #include <string.h>
17 #include "parse.h"
18 #include "read.h"
19 #include "routines.h"
20 #include "vstring.h"
23 * DATA DEFINITIONS
25 typedef enum {
26 K_CLASS, K_METHOD, K_PROCEDURE, K_MODULE
27 } tclKind;
29 static kindOption TclKinds [] = {
30 { true, 'c', "class", "classes" },
31 { true, 'm', "method", "methods" },
32 { true, 'p', "procedure", "procedures" },
33 { true, 'n', "module", "modules" }
37 * FUNCTION DEFINITIONS
40 static const unsigned char *makeTclTag (
41 const unsigned char *cp,
42 vString *const name,
43 const tclKind kind)
45 vStringClear (name);
46 while ((int) *cp != '\0' && ! isspace ((int) *cp))
48 vStringPut (name, (int) *cp);
49 ++cp;
51 makeSimpleTag (name, TclKinds, kind);
52 return cp;
55 static bool match (const unsigned char *line, const char *word)
57 size_t len = strlen (word);
58 bool matched = (strncmp ((const char*) line, word, len) == 0);
60 if (matched)
62 /* check that the word is followed by a space to avoid detecting something
63 * like "proc_new ..." */
64 matched = isspace (*(line + len));
66 return matched;
69 static void findTclTags (void)
71 vString *name = vStringNew ();
72 const unsigned char *line;
74 while ((line = readLineFromInputFile ()) != NULL)
76 const unsigned char *cp;
78 while (isspace (line [0]))
79 ++line;
81 if (line [0] == '\0' || line [0] == '#')
82 continue;
84 /* read first word */
85 for (cp = line ; *cp != '\0' && ! isspace ((int) *cp) ; ++cp)
87 if (! isspace ((int) *cp))
88 continue;
89 while (isspace ((int) *cp))
90 ++cp;
91 /* Now `line' points at first word and `cp' points at next word */
93 if (match (line, "proc"))
94 cp = makeTclTag (cp, name, K_PROCEDURE);
95 else if (match (line, "class") || match (line, "itcl::class"))
96 cp = makeTclTag (cp, name, K_CLASS);
97 else if (match (line, "public") ||
98 match (line, "protected") ||
99 match (line, "private"))
101 if (match (cp, "method"))
103 cp += 6;
104 while (isspace ((int) *cp))
105 ++cp;
106 cp = makeTclTag (cp, name, K_METHOD);
109 else if (match (line, "method"))
111 cp = makeTclTag (cp, name, K_METHOD);
113 else if (match (line, "oo::class") ) {
114 if (match (cp, "create"))
116 cp += 6;
117 while (isspace ((int) *cp))
118 ++cp;
119 cp = makeTclTag (cp, name, K_CLASS);
122 else if (match (line, "namespace") ) {
123 if (match (cp, "eval"))
125 cp += 4;
126 while (isspace ((int) *cp))
127 ++cp;
128 cp = makeTclTag (cp, name, K_MODULE);
133 vStringDelete (name);
136 extern parserDefinition* TclParser (void)
138 static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
139 parserDefinition* def = parserNew ("Tcl");
140 def->kinds = TclKinds;
141 def->kindCount = ARRAY_SIZE (TclKinds);
142 def->extensions = extensions;
143 def->parser = findTclTags;
144 return def;