* plugins/language-support-cpp-java/cpp-java-assist.c:
[anjuta-git-plugin.git] / tagmanager / lua.c
blobb0831609e5395abd34491c7174f20ff88c5e1b22
1 /*
2 * $Id$
4 * Copyright (c) 2000-2001, Max Ischenko <mfi@ukr.net>.
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 Lua language.
13 * INCLUDE FILES
15 #include "general.h" /* must always come first */
17 #include <string.h>
19 #include "options.h"
20 #include "parse.h"
21 #include "read.h"
22 #include "vstring.h"
25 * DATA DEFINITIONS
27 typedef enum {
28 K_FUNCTION
29 } luaKind;
31 static kindOption LuaKinds [] = {
32 { TRUE, 'f', "function", "functions" }
36 * FUNCTION DEFINITIONS
39 /* for debugging purposes */
40 static void __unused__ print_string (char *p, char *q)
42 for ( ; p != q; p++)
43 fprintf (errout, "%c", *p);
44 fprintf (errout, "\n");
48 * Helper function.
49 * Returns 1 if line looks like a line of Lua code.
51 * TODO: Recognize UNIX bang notation.
52 * (Lua treat first line as a comment if it starts with #!)
55 static boolean is_a_code_line (const unsigned char *line)
57 boolean result;
58 const unsigned char *p = line;
59 while (isspace ((int) *p))
60 p++;
61 if (p [0] == '\0')
62 result = FALSE;
63 else if (p [0] == '-' && p [1] == '-')
64 result = FALSE;
65 else
66 result = TRUE;
67 return result;
70 static void extract_name (const char *begin, const char *end, vString *name)
72 if (begin != NULL && end != NULL && begin < end)
74 const char *cp;
76 while (isspace ((int) *begin))
77 begin++;
78 while (isspace ((int) *end))
79 end--;
80 if (begin < end)
82 for (cp = begin ; cp != end; cp++)
83 vStringPut (name, (int) *cp);
84 vStringTerminate (name);
86 makeSimpleTag (name, LuaKinds, K_FUNCTION);
87 vStringClear (name);
92 static void findLuaTags (void)
94 vString *name = vStringNew ();
95 const unsigned char *line;
97 while ((line = fileReadLine ()) != NULL)
99 const char *p, *q;
101 if (! is_a_code_line (line))
102 continue;
104 p = (const char*) strstr ((const char*) line, "function");
105 if (p == NULL)
106 continue;
108 q = strchr ((const char*) line, '=');
110 if (q == NULL) {
111 p = p + 9; /* skip the `function' word */
112 q = strchr ((const char*) p, '(');
113 extract_name (p, q, name);
114 } else {
115 p = (const char*) &line[0];
116 extract_name (p, q, name);
119 vStringDelete (name);
122 extern parserDefinition* LuaParser (void)
124 static const char* const extensions [] = { "lua", NULL };
125 parserDefinition* def = parserNew ("Lua");
126 def->kinds = LuaKinds;
127 def->kindCount = KIND_COUNT (LuaKinds);
128 def->extensions = extensions;
129 def->parser = findLuaTags;
130 return def;
133 /* vi:set tabstop=4 shiftwidth=4: */