Fix some bugs in parsing FreeBasic code (#2489605).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3449 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2009-01-06 14:53:31 +00:00
parent e8ac3d2be2
commit a097d3dbb7
2 changed files with 33 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2009-01-06 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* tagmanager/basic.c:
Fix some bugs in parsing FreeBasic code (#2489605).
2009-01-04 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> 2009-01-04 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* wscript, THANKS, data/filetype_extensions.conf, src/templates.c, * wscript, THANKS, data/filetype_extensions.conf, src/templates.c,

View File

@ -71,9 +71,14 @@ static KeyWord freebasic_keywords[] = {
/* Match the name of a dim or const starting at pos. */ /* Match the name of a dim or const starting at pos. */
static int extract_dim (char const *pos, vString * name, BasicKind kind) static int extract_dim (char const *pos, vString * name, BasicKind kind)
{ {
const char *old_pos = pos;
while (isspace (*pos)) while (isspace (*pos))
pos++; pos++;
/* create tags only if there is some space between the keyword and the identifier */
if (old_pos == pos)
return 0;
vStringClear (name); vStringClear (name);
if (strncasecmp (pos, "shared", 6) == 0) if (strncasecmp (pos, "shared", 6) == 0)
@ -95,15 +100,20 @@ static int extract_dim (char const *pos, vString * name, BasicKind kind)
pos++; pos++;
/* now we are at the name */ /* now we are at the name */
} }
/* capture "dim as foo ptr bar" */ /* capture "dim as foo ptr bar" */
if (strncasecmp (pos, "ptr", 3) == 0) if (strncasecmp (pos, "ptr", 3) == 0 && isspace(*(pos+4)))
{ {
pos += 3; /* skip keyword "ptr" */ pos += 3; /* skip keyword "ptr" */
while (isspace (*pos)) while (isspace (*pos))
pos++; pos++;
} }
/* capture "dim as string * 4096 chunk" */
if (strncmp (pos, "*", 1) == 0)
{
pos += 1; /* skip "*" */
while (isspace (*pos) || isdigit(*pos) || ispunct(*pos))
pos++;
}
for (; *pos && !isspace (*pos) && *pos != '(' && *pos != ',' && *pos != '='; pos++) for (; *pos && !isspace (*pos) && *pos != '(' && *pos != ',' && *pos != '='; pos++)
vStringPut (name, *pos); vStringPut (name, *pos);
@ -155,6 +165,7 @@ static int match_keyword (const char *p, KeyWord const *kw)
vString *name; vString *name;
size_t i; size_t i;
int j; int j;
const char *old_p;
for (i = 0; i < strlen (kw->token); i++) for (i = 0; i < strlen (kw->token); i++)
{ {
if (tolower (p[i]) != kw->token[i]) if (tolower (p[i]) != kw->token[i])
@ -167,6 +178,17 @@ static int match_keyword (const char *p, KeyWord const *kw)
kw == &freebasic_keywords[2]) kw == &freebasic_keywords[2])
return extract_dim (p, name, kw->kind); /* extract_dim adds the found tag(s) */ return extract_dim (p, name, kw->kind); /* extract_dim adds the found tag(s) */
old_p = p;
while (isspace (*p))
p++;
/* create tags only if there is some space between the keyword and the identifier */
if (old_p == p)
{
vStringDelete (name);
return 0;
}
for (j = 0; j < 1; j++) for (j = 0; j < 1; j++)
{ {
p = extract_name (p, name); p = extract_name (p, name);
@ -207,8 +229,8 @@ static void findBasicTags (void)
while (isspace (*p)) while (isspace (*p))
p++; p++;
/* Empty line? */ /* Empty line or comment? */
if (!*p) if (!*p || *p == '\'')
continue; continue;
/* In Basic, keywords always are at the start of the line. */ /* In Basic, keywords always are at the start of the line. */