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 kindOption LuaKinds
[] = {
30 { true, 'f', "function", "functions" }
34 * FUNCTION DEFINITIONS
37 /* for debugging purposes */
38 static void CTAGS_ATTR_UNUSED
print_string (char *p
, char *q
)
41 fprintf (errout
, "%c", *p
);
42 fprintf (errout
, "\n");
47 * Returns 1 if line looks like a line of Lua code.
49 * TODO: Recognize UNIX bang notation.
50 * (Lua treat first line as a comment if it starts with #!)
53 static bool is_a_code_line (const unsigned char *line
)
56 const unsigned char *p
= line
;
57 while (isspace ((int) *p
))
61 else if (p
[0] == '-' && p
[1] == '-')
68 static void extract_name (const char *begin
, const char *end
, vString
*name
)
70 if (begin
!= NULL
&& end
!= NULL
&& begin
< end
)
74 while (isspace ((int) *begin
))
76 while (isspace ((int) *end
))
80 for (cp
= begin
; cp
!= end
; cp
++)
81 vStringPut (name
, (int) *cp
);
83 makeSimpleTag (name
, LuaKinds
, K_FUNCTION
);
89 static void findLuaTags (void)
91 vString
*name
= vStringNew ();
92 const unsigned char *line
;
94 while ((line
= readLineFromInputFile ()) != 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
= ARRAY_SIZE (LuaKinds
);
125 def
->extensions
= extensions
;
126 def
->parser
= findLuaTags
;