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 version 2 or (at your option) any later version.
7 * This module contains functions for generating tags for Lua language.
13 #include "general.h" /* must always come first */
29 static kindDefinition LuaKinds
[] = {
30 { true, 'f', "function", "functions" }
34 * FUNCTION DEFINITIONS
39 * Returns 1 if line looks like a line of Lua code.
41 * TODO: Recognize UNIX bang notation.
42 * (Lua treat first line as a comment if it starts with #!)
45 static bool is_a_code_line (const unsigned char *line
)
48 const unsigned char *p
= line
;
49 while (isspace ((int) *p
))
53 else if (p
[0] == '-' && p
[1] == '-')
60 static void extract_name (const char *begin
, const char *end
, vString
*name
)
62 if (begin
!= NULL
&& end
!= NULL
&& begin
< end
)
66 while (isspace ((int) *begin
))
68 while (isspace ((int) *end
))
72 for (cp
= begin
; cp
!= end
; cp
++)
73 vStringPut (name
, (int) *cp
);
75 makeSimpleTag (name
, K_FUNCTION
);
81 static void findLuaTags (void)
83 vString
*name
= vStringNew ();
84 const unsigned char *line
;
86 while ((line
= readLineFromInputFile ()) != NULL
)
90 if (! is_a_code_line (line
))
93 p
= (const char*) strstr ((const char*) line
, "function");
97 q
= strchr ((const char*) line
, '=');
100 p
= p
+ 9; /* skip the `function' word */
101 q
= strchr ((const char*) p
, '(');
102 extract_name (p
, q
, name
);
103 } else if (*(q
+1) != '=') { /* ignore `if type(v) == "function" then ...' */
104 p
= (const char*) &line
[0];
105 extract_name (p
, q
, name
);
108 vStringDelete (name
);
111 extern parserDefinition
* LuaParser (void)
113 static const char* const extensions
[] = { "lua", NULL
};
114 parserDefinition
* def
= parserNew ("Lua");
115 def
->kindTable
= LuaKinds
;
116 def
->kindCount
= ARRAY_SIZE (LuaKinds
);
117 def
->extensions
= extensions
;
118 def
->parser
= findLuaTags
;