2 * $Id: lua.c 443 2006-05-30 04:37:13Z darren $
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.
15 #include "general.h" /* must always come first */
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
)
43 fprintf (errout
, "%c", *p
);
44 fprintf (errout
, "\n");
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
)
58 const unsigned char *p
= line
;
59 while (isspace ((int) *p
))
63 else if (p
[0] == '-' && p
[1] == '-')
70 static void extract_name (const char *begin
, const char *end
, vString
*name
)
72 if (begin
!= NULL
&& end
!= NULL
&& begin
< end
)
76 while (isspace ((int) *begin
))
78 while (isspace ((int) *end
))
82 for (cp
= begin
; cp
!= end
; cp
++)
83 vStringPut (name
, (int) *cp
);
84 vStringTerminate (name
);
86 makeSimpleTag (name
, LuaKinds
, K_FUNCTION
);
92 static void findLuaTags (void)
94 vString
*name
= vStringNew ();
95 const unsigned char *line
;
97 while ((line
= fileReadLine ()) != NULL
)
101 if (! is_a_code_line (line
))
104 p
= (const char*) strstr ((const char*) line
, "function");
108 q
= strchr ((const char*) line
, '=');
111 p
= p
+ 9; /* skip the `function' word */
112 q
= strchr ((const char*) p
, '(');
113 extract_name (p
, q
, name
);
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
;
133 /* vi:set tabstop=4 shiftwidth=4: */