@@ -52,7 +52,6 @@ static kindDefinition BasicKinds[] = {
5252static KeyWord basic_keywords [] = {
5353 /* freebasic */
5454 {"const" , K_CONST , 0 },
55- {"dim as" , K_VARIABLE , 1 },
5655 {"dim" , K_VARIABLE , 0 },
5756 {"common" , K_VARIABLE , 0 },
5857 {"function" , K_FUNCTION , 0 },
@@ -83,6 +82,74 @@ static KeyWord basic_keywords[] = {
8382 * FUNCTION DEFINITIONS
8483 */
8584
85+ /* Match the name of a dim or const starting at pos. */
86+ static void extract_dim (char const * pos , BasicKind kind )
87+ {
88+ vString * name = vStringNew ();
89+
90+ if (strncasecmp (pos , "shared" , 6 ) == 0 )
91+ pos += 6 ; /* skip keyword "shared" */
92+
93+ while (isspace (* pos ))
94+ pos ++ ;
95+
96+ /* capture "dim as String str" */
97+ if (strncasecmp (pos , "as" , 2 ) == 0 )
98+ {
99+ pos += 2 ; /* skip keyword "as" */
100+
101+ while (isspace (* pos ))
102+ pos ++ ;
103+ while (!isspace (* pos ) && * pos ) /* skip next part which is a type */
104+ pos ++ ;
105+ while (isspace (* pos ))
106+ pos ++ ;
107+ /* now we are at the name */
108+ }
109+ /* capture "dim as foo ptr bar" */
110+ if (strncasecmp (pos , "ptr" , 3 ) == 0 && isspace (* (pos + 3 )))
111+ {
112+ pos += 3 ; /* skip keyword "ptr" */
113+ while (isspace (* pos ))
114+ pos ++ ;
115+ }
116+ /* capture "dim as string * 4096 chunk" */
117+ if (strncmp (pos , "*" , 1 ) == 0 )
118+ {
119+ pos += 1 ; /* skip "*" */
120+ while (isspace (* pos ) || isdigit (* pos ) || ispunct (* pos ))
121+ pos ++ ;
122+ }
123+
124+ for (; * pos && !isspace (* pos ) && * pos != '(' && * pos != ',' && * pos != '=' ; pos ++ )
125+ vStringPut (name , * pos );
126+ makeSimpleTag (name , kind );
127+
128+ /* if the line contains a ',', we have multiple declarations */
129+ while (* pos && strchr (pos , ',' ))
130+ {
131+ /* skip all we don't need(e.g. "..., new_array(5), " we skip "(5)") */
132+ while (* pos != ',' && * pos != '\'' && * pos )
133+ pos ++ ;
134+
135+ if (* pos == '\'' )
136+ break ; /* break if we are in a comment */
137+
138+ while (isspace (* pos ) || * pos == ',' )
139+ pos ++ ;
140+
141+ if (* pos == '\'' )
142+ break ; /* break if we are in a comment */
143+
144+ vStringClear (name );
145+ for (; * pos && !isspace (* pos ) && * pos != '(' && * pos != ',' && * pos != '=' ; pos ++ )
146+ vStringPut (name , * pos );
147+ makeSimpleTag (name , kind );
148+ }
149+
150+ vStringDelete (name );
151+ }
152+
86153/* Match the name of a tag (function, variable, type, ...) starting at pos. */
87154static char const * extract_name (char const * pos , vString * name )
88155{
@@ -116,6 +183,12 @@ static int match_keyword (const char *p, KeyWord const *kw)
116183 if (old_p == p )
117184 return 0 ;
118185
186+ if (kw -> kind == K_VARIABLE )
187+ {
188+ extract_dim (p , kw -> kind ); /* extract_dim adds the found tag(s) */
189+ return 1 ;
190+ }
191+
119192 name = vStringNew ();
120193 for (j = 0 ; j < 1 + kw -> skip ; j ++ )
121194 {
0 commit comments