Skip to content

Commit 7e5ed42

Browse files
committed
basic: make extract_name() similar to extract_dim() and simplify code
1 parent 6adedf2 commit 7e5ed42

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

parsers/basic.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,24 @@ static void extract_dim (char const *pos, BasicKind kind)
150150
}
151151

152152
/* Match the name of a tag (function, variable, type, ...) starting at pos. */
153-
static char const *extract_name (char const *pos, vString * name)
153+
static void extract_name (char const *pos, BasicKind kind)
154154
{
155-
while (isspace (*pos))
156-
pos++;
157-
vStringClear (name);
155+
vString *name = vStringNew ();
158156
for (; *pos && !isspace (*pos) && *pos != '(' && *pos != ',' && *pos != '='; pos++)
159157
vStringPut (name, *pos);
160-
return pos;
158+
makeSimpleTag (name, kind);
159+
vStringDelete (name);
161160
}
162161

163162
/* Match a keyword starting at p (case insensitive). */
164-
static int match_keyword (const char *p, KeyWord const *kw)
163+
static bool match_keyword (const char *p, KeyWord const *kw)
165164
{
166-
vString *name;
167165
size_t i;
168166
const char *old_p;
169167
for (i = 0; i < strlen (kw->token); i++)
170168
{
171169
if (tolower (p[i]) != kw->token[i])
172-
return 0;
170+
return false;
173171
}
174172
p += i;
175173

@@ -179,19 +177,13 @@ static int match_keyword (const char *p, KeyWord const *kw)
179177

180178
/* create tags only if there is some space between the keyword and the identifier */
181179
if (old_p == p)
182-
return 0;
180+
return false;
183181

184182
if (kw->kind == K_VARIABLE)
185-
{
186183
extract_dim (p, kw->kind); /* extract_dim adds the found tag(s) */
187-
return 1;
188-
}
189-
190-
name = vStringNew ();
191-
extract_name (p, name);
192-
makeSimpleTag (name, kw->kind);
193-
vStringDelete (name);
194-
return 1;
184+
else
185+
extract_name (p, kw->kind);
186+
return true;
195187
}
196188

197189
/* Match a "label:" style label. */
@@ -213,12 +205,7 @@ static void match_colon_label (char const *p)
213205
static void match_dot_label (char const *p)
214206
{
215207
if (*p == '.')
216-
{
217-
vString *name = vStringNew ();
218-
extract_name (p + 1, name);
219-
makeSimpleTag (name, K_LABEL);
220-
vStringDelete (name);
221-
}
208+
extract_name (p + 1, K_LABEL);
222209
}
223210

224211
static void findBasicTags (void)

0 commit comments

Comments
 (0)