2 * Copyright (c) 2000-2001, Max Ischenko <mfi@ukr.net>.
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License.
7 * This module contains functions for generating tags for Lua language.
13 #include "general.h" /* must always come first */
28 static kindOption LuaKinds
[] = {
29 { TRUE
, 'f', "function", "functions" }
33 * FUNCTION DEFINITIONS
36 /* for debugging purposes */
37 static void __unused__
print_string (char *p
, char *q
)
40 fprintf (errout
, "%c", *p
);
41 fprintf (errout
, "\n");
46 * Returns 1 if line looks like a line of Lua code.
48 * TODO: Recognize UNIX bang notation.
49 * (Lua treat first line as a comment if it starts with #!)
52 static boolean
is_a_code_line (const unsigned char *line
)
55 const unsigned char *p
= line
;
56 while (isspace ((int) *p
))
60 else if (p
[0] == '-' && p
[1] == '-')
67 static void extract_name (const char *begin
, const char *end
, vString
*name
)
69 if (begin
!= NULL
&& end
!= NULL
&& begin
< end
)
73 while (isspace ((int) *begin
))
75 while (isspace ((int) *end
))
79 for (cp
= begin
; cp
!= end
; cp
++)
80 vStringPut (name
, (int) *cp
);
81 vStringTerminate (name
);
83 makeSimpleTag (name
, LuaKinds
, K_FUNCTION
);
89 static void findLuaTags (void)
91 vString
*name
= vStringNew ();
92 const unsigned char *line
;
94 while ((line
= fileReadLine ()) != NULL
)
98 if (! is_a_code_line (line
))
101 p
= (const char*) strstr ((const char*) line
, "function");
105 q
= strchr ((const char*) line
, '=');
108 p
= p
+ 9; /* skip the `function' word */
109 q
= strchr ((const char*) p
, '(');
110 extract_name (p
, q
, name
);
111 } else if (*(q
+1) != '=') { /* ignore `if type(v) == "function" then ...' */
112 p
= (const char*) &line
[0];
113 extract_name (p
, q
, name
);
116 vStringDelete (name
);
119 extern parserDefinition
* LuaParser (void)
121 static const char* const extensions
[] = { "lua", NULL
};
122 parserDefinition
* def
= parserNew ("Lua");
123 def
->kinds
= LuaKinds
;
124 def
->kindCount
= KIND_COUNT (LuaKinds
);
125 def
->extensions
= extensions
;
126 def
->parser
= findLuaTags
;
130 /* vi:set tabstop=4 shiftwidth=4: */