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 */
30 static kindOption LuaKinds
[] = {
31 { TRUE
, 'f', "function", "functions" }
35 * FUNCTION DEFINITIONS
38 /* for debugging purposes */
39 static void __unused__
print_string (char *p
, char *q
)
42 fprintf (errout
, "%c", *p
);
43 fprintf (errout
, "\n");
48 * Returns 1 if line looks like a line of Lua code.
50 * TODO: Recognize UNIX bang notation.
51 * (Lua treat first line as a comment if it starts with #!)
54 static boolean
is_a_code_line (const unsigned char *line
)
57 const unsigned char *p
= line
;
58 while (isspace ((int) *p
))
62 else if (p
[0] == '-' && p
[1] == '-')
69 static void extract_name (const char *begin
, const char *end
, vString
*name
)
71 if (begin
!= NULL
&& end
!= NULL
&& begin
< end
)
75 while (isspace ((int) *begin
))
77 while (isspace ((int) *end
))
81 for (cp
= begin
; cp
!= end
; cp
++)
82 vStringPut (name
, (int) *cp
);
83 vStringTerminate (name
);
85 makeSimpleTag (name
, LuaKinds
, K_FUNCTION
);
91 static void findLuaTags (void)
93 vString
*name
= vStringNew ();
94 const unsigned char *line
;
96 while ((line
= fileReadLine ()) != NULL
)
100 if (! is_a_code_line (line
))
103 p
= (const char*) strstr ((const char*) line
, "function");
107 q
= strchr ((const char*) line
, '=');
110 p
= p
+ 9; /* skip the `function' word */
111 q
= strchr ((const char*) p
, '(');
112 extract_name (p
, q
, name
);
113 } else if (*(q
+1) != '=') { /* ignore `if type(v) == "function" then ...' */
114 p
= (const char*) &line
[0];
115 extract_name (p
, q
, name
);
118 vStringDelete (name
);
121 extern parserDefinition
* LuaParser (void)
123 static const char* const extensions
[] = { "lua", NULL
};
124 parserDefinition
* def
= parserNew ("Lua");
125 def
->kinds
= LuaKinds
;
126 def
->kindCount
= KIND_COUNT (LuaKinds
);
127 def
->extensions
= extensions
;
128 def
->parser
= findLuaTags
;
132 /* vi:set tabstop=4 shiftwidth=4: */