Sync whitespace in parsers
[geany-mirror.git] / ctags / parsers / tcl.c
blob7e91ed519534ce7ea6eff7518c5de8ca44733c4b
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 vStringTerminate (name);
52 makeSimpleTag (name, TclKinds, kind);
53 return cp;
56 static boolean match (const unsigned char *line, const char *word)
58 size_t len = strlen (word);
59 boolean matched = (strncmp ((const char*) line, word, len) == 0);
61 if (matched)
63 /* check that the word is followed by a space to avoid detecting something
64 * like "proc_new ..." */
65 matched = isspace (*(line + len));
67 return matched;
70 static void findTclTags (void)
72 vString *name = vStringNew ();
73 const unsigned char *line;
75 while ((line = readLineFromInputFile ()) != NULL)
77 const unsigned char *cp;
79 while (isspace (line [0]))
80 ++line;
82 if (line [0] == '\0' || line [0] == '#')
83 continue;
85 /* read first word */
86 for (cp = line ; *cp != '\0' && ! isspace ((int) *cp) ; ++cp)
88 if (! isspace ((int) *cp))
89 continue;
90 while (isspace ((int) *cp))
91 ++cp;
92 /* Now `line' points at first word and `cp' points at next word */
94 if (match (line, "proc"))
95 cp = makeTclTag (cp, name, K_PROCEDURE);
96 else if (match (line, "class") || match (line, "itcl::class"))
97 cp = makeTclTag (cp, name, K_CLASS);
98 else if (match (line, "public") ||
99 match (line, "protected") ||
100 match (line, "private"))
102 if (match (cp, "method"))
104 cp += 6;
105 while (isspace ((int) *cp))
106 ++cp;
107 cp = makeTclTag (cp, name, K_METHOD);
110 else if (match (line, "method"))
112 cp = makeTclTag (cp, name, K_METHOD);
114 else if (match (line, "oo::class") ) {
115 if (match (cp, "create"))
117 cp += 6;
118 while (isspace ((int) *cp))
119 ++cp;
120 cp = makeTclTag (cp, name, K_CLASS);
123 else if (match (line, "namespace") ) {
124 if (match (cp, "eval"))
126 cp += 4;
127 while (isspace ((int) *cp))
128 ++cp;
129 cp = makeTclTag (cp, name, K_MODULE);
134 vStringDelete (name);
137 extern parserDefinition* TclParser (void)
139 static const char *const extensions [] = { "tcl", "tk", "wish", "itcl", NULL };
140 parserDefinition* def = parserNew ("Tcl");
141 def->kinds = TclKinds;
142 def->kindCount = ARRAY_SIZE (TclKinds);
143 def->extensions = extensions;
144 def->parser = findTclTags;
145 return def;
148 /* vi:set tabstop=4 shiftwidth=4: */