Fixed bug #1741778 ("DIM AS <datatype> name" was not supported for FreeBasic)

git-svn-id: svn://svn.code.sf.net/p/ctags/code/trunk@561 c5d04d22-be80-434c-894e-aa346cc9e8e8
This commit is contained in:
elias 2007-06-22 20:53:27 +00:00
parent e7d99ee4ab
commit 8d50ac3549
2 changed files with 47 additions and 30 deletions

View File

@ -4,6 +4,7 @@ Const one = 1
Common a As Integer
Dim b As Integer
DIM AS STRING str
Type test
a As Integer

76
basic.c
View File

@ -32,12 +32,14 @@ typedef enum {
K_FUNCTION,
K_LABEL,
K_TYPE,
K_VARIABLE
K_VARIABLE,
K_ENUM
} BasicKind;
typedef struct {
char const *token;
BasicKind kind;
int skip;
} KeyWord;
static kindOption BasicKinds[] = {
@ -45,36 +47,43 @@ static kindOption BasicKinds[] = {
{TRUE, 'f', "function", "functions"},
{TRUE, 'l', "label", "labels"},
{TRUE, 't', "type", "types"},
{TRUE, 'v', "variable", "variables"}
{TRUE, 'v', "variable", "variables"},
{TRUE, 'g', "enum", "enumerations"}
};
static KeyWord blitzbasic_keywords[] = {
{"const", K_CONST},
{"global", K_VARIABLE},
{"dim", K_VARIABLE},
{"function", K_FUNCTION},
{"type", K_TYPE},
{NULL, 0}
{"const", K_CONST, 0},
{"global", K_VARIABLE, 0},
{"dim", K_VARIABLE, 0},
{"function", K_FUNCTION, 0},
{"type", K_TYPE, 0},
{NULL, 0, 0}
};
static KeyWord purebasic_keywords[] = {
{"newlist", K_VARIABLE},
{"global", K_VARIABLE},
{"dim", K_VARIABLE},
{"procedure", K_FUNCTION},
{"interface", K_TYPE},
{"structure", K_TYPE},
{NULL, 0}
{"newlist", K_VARIABLE, 0},
{"global", K_VARIABLE, 0},
{"dim", K_VARIABLE, 0},
{"procedure", K_FUNCTION, 0},
{"interface", K_TYPE, 0},
{"structure", K_TYPE, 0},
{NULL, 0, 0}
};
static KeyWord freebasic_keywords[] = {
{"const", K_CONST},
{"dim", K_VARIABLE},
{"common", K_VARIABLE},
{"function", K_FUNCTION},
{"sub", K_FUNCTION},
{"type", K_TYPE},
{NULL, 0}
{"const", K_CONST, 0},
{"dim as", K_VARIABLE, 1},
{"dim", K_VARIABLE, 0},
{"common", K_VARIABLE, 0},
{"function", K_FUNCTION, 0},
{"sub", K_FUNCTION, 0},
{"private sub", K_FUNCTION, 0},
{"public sub", K_FUNCTION, 0},
{"private function", K_FUNCTION, 0},
{"public function", K_FUNCTION, 0},
{"type", K_TYPE, 0},
{"enum", K_ENUM, 0},
{NULL, 0, 0}
};
/*
@ -82,7 +91,7 @@ static KeyWord freebasic_keywords[] = {
*/
/* Match the name of a tag (function, variable, type, ...) starting at pos. */
static void extract_name (char const *pos, vString * name)
static char const *extract_name (char const *pos, vString * name)
{
while (isspace (*pos))
pos++;
@ -90,22 +99,29 @@ static void extract_name (char const *pos, vString * name)
for (; *pos && !isspace (*pos) && *pos != '(' && *pos != ','; pos++)
vStringPut (name, *pos);
vStringTerminate (name);
return pos;
}
/* Match a keyword starting at p (case insensitive). */
static void match_keyword (const char *p, const char *keyword, BasicKind kind)
static int match_keyword (const char *p, KeyWord const *kw)
{
vString *name;
size_t i;
for (i = 0; i < strlen (keyword); i++)
int j;
for (i = 0; i < strlen (kw->token); i++)
{
if (tolower (p[i]) != keyword[i])
return;
if (tolower (p[i]) != kw->token[i])
return 0;
}
name = vStringNew ();
extract_name (p + i, name);
makeSimpleTag (name, BasicKinds, kind);
p += i;
for (j = 0; j < 1 + kw->skip; j++)
{
p = extract_name (p, name);
}
makeSimpleTag (name, BasicKinds, kw->kind);
vStringDelete (name);
return 1;
}
/* Match a "label:" style label. */
@ -154,7 +170,7 @@ static void findBasicTags (KeyWord const keywords[],
/* In Basic, keywords always are at the start of the line. */
for (kw = keywords; kw->token; kw++)
match_keyword (p, kw->token, kw->kind);
if (match_keyword (p, kw)) break;
/* Is it a label? */
label (p);