Skip to content

Commit 08a9d8b

Browse files
committed
basic: skip () pairs and "" strings in variable declarations
The current code gets confused when ',' appears inside () parens or inside "" strings. Fix that by skipping these. Fixes geany/geany#2461
1 parent 92ffe75 commit 08a9d8b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Units/parser-basic.r/simple.bas.d/expected.tags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ f input.bas /^Function f()$/;" f
77
g input.bas /^dim shared as string g$/;" v
88
h input.bas /^dim as string ptr h$/;" v
99
i input.bas /^dim as string * 4096 i$/;" v
10+
j input.bas /^dim j as string="Export_GIR_FULL_"+mid(date,7)+","+mid(date,1,2)+""+mid(date,4,2)+".csv"$/;" v
11+
k input.bas /^dim as string k="Export_GIR_FULL_"+mid(date(),"(")+","+mid(date,1,2)+""+mid(date,4,2)+".csv", l$/;" v
12+
l input.bas /^dim as string k="Export_GIR_FULL_"+mid(date(),"(")+","+mid(date,1,2)+""+mid(date,4,2)+".csv", l$/;" v
1013
one input.bas /^Const one = 1$/;" c
1114
start input.bas /^start:$/;" l
1215
str input.bas /^DIM AS STRING str$/;" v

Units/parser-basic.r/simple.bas.d/input.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ dim as string c(20), d="a", e
99
dim shared as string g
1010
dim as string ptr h
1111
dim as string * 4096 i
12+
dim j as string="Export_GIR_FULL_"+mid(date,7)+","+mid(date,1,2)+""+mid(date,4,2)+".csv"
13+
dim as string k="Export_GIR_FULL_"+mid(date(),"(")+","+mid(date,1,2)+""+mid(date,4,2)+".csv", l
1214

1315
Type test
1416
a As Integer

parsers/basic.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,41 @@ static KeyWord basic_keywords[] = {
8181
* FUNCTION DEFINITIONS
8282
*/
8383

84+
static const char *skipToMatching (char begin, char end, const char *pos)
85+
{
86+
int counter = 1;
87+
pos++;
88+
while (*pos && counter > 0)
89+
{
90+
if (*pos == end)
91+
counter--;
92+
else if (*pos == begin)
93+
counter++;
94+
else if (*pos == '"')
95+
pos = skipToMatching ('"', '"', pos) - 1;
96+
pos++;
97+
}
98+
return pos;
99+
}
100+
101+
static const char *nextPos (const char *pos)
102+
{
103+
if (*pos == '\0')
104+
return pos;
105+
106+
pos++;
107+
switch (*pos)
108+
{
109+
case '(':
110+
pos = skipToMatching ('(', ')', pos);
111+
break;
112+
case '"':
113+
pos = skipToMatching ('"', '"', pos);
114+
break;
115+
}
116+
return pos;
117+
}
118+
84119
static bool isIdentChar (char c)
85120
{
86121
return c && !isspace (c) && c != '(' && c != ',' && c != '=';
@@ -134,7 +169,7 @@ static void extract_dim (char const *pos, BasicKind kind)
134169
{
135170
/* skip all we don't need(e.g. "..., new_array(5), " we skip "(5)") */
136171
while (*pos != ',' && *pos != '\'' && *pos)
137-
pos++;
172+
pos = nextPos (pos);
138173

139174
if (*pos == '\'')
140175
break; /* break if we are in a comment */

0 commit comments

Comments
 (0)