@@ -179,7 +179,7 @@ public ZXBasicMap(ZXCodeFile MainFile, IEnumerable<ZXCodeFile> AllFiles, string
179179 ParseInputParameters ( funcMatch . Groups [ 5 ] . Value , currentFunction . InputParameters ) ;
180180
181181 if ( funcMatch . Groups [ 7 ] . Success )
182- currentFunction . ReturnType = StorageFromString ( funcMatch . Groups [ 5 ] . Value , currentFunction . Name ) ;
182+ currentFunction . ReturnType = StorageFromString ( funcMatch . Groups [ 7 ] . Value , currentFunction . Name ) ;
183183 else
184184 currentFunction . ReturnType = ZXVariableStorage . F ;
185185
@@ -202,8 +202,7 @@ public ZXBasicMap(ZXCodeFile MainFile, IEnumerable<ZXCodeFile> AllFiles, string
202202 if ( varNameDef . Contains ( "(" ) ) //array
203203 {
204204 string varName = varNameDef . Substring ( 0 , varNameDef . IndexOf ( "(" ) ) . Trim ( ) ;
205-
206- if ( ! jointLines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_]){ varName } ($|[^a-zA-Z0-9_])", RegexOptions . Multiline ) ) )
205+ if ( ! jointLines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_$]){ Regex . Escape ( varName ) } ($|[^a-zA-Z0-9_$])", RegexOptions . Multiline ) ) )
207206 continue ;
208207
209208 string [ ] dims = varNameDef . Substring ( varNameDef . IndexOf ( "(" ) + 1 ) . Replace ( ")" , "" ) . Split ( "," , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -219,8 +218,7 @@ public ZXBasicMap(ZXCodeFile MainFile, IEnumerable<ZXCodeFile> AllFiles, string
219218 foreach ( var vName in varNames )
220219 {
221220 string varName = vName . Trim ( ) ;
222-
223- if ( ! jointLines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_]){ varName } ($|[^a-zA-Z0-9_])", RegexOptions . Multiline ) ) )
221+ if ( ! jointLines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_$]){ Regex . Escape ( varName ) } ($|[^a-zA-Z0-9_$])", RegexOptions . Multiline ) ) )
224222 continue ;
225223
226224 var storage = StorageFromString ( dimMatch . Groups [ 5 ] . Value , varName ) ;
@@ -291,15 +289,15 @@ public ZXBasicMap(ZXCodeFile MainFile, IEnumerable<ZXCodeFile> AllFiles, string
291289 //Search for the var in the sub/function that the location points to
292290 if ( location . LocationType == ZXBasicLocationType . Sub )
293291 {
294- var sub = subs . Where ( s => s . Name == location . Name ) . FirstOrDefault ( ) ;
292+ var sub = subs . FirstOrDefault ( s => string . Equals ( s . Name , location . Name , StringComparison . OrdinalIgnoreCase ) ) ;
295293 if ( sub != null )
296- foundVar = sub . LocalVariables . Where ( v => v . Name == varName ) . FirstOrDefault ( ) ;
294+ foundVar = sub . LocalVariables . FirstOrDefault ( v => string . Equals ( v . Name , varName , StringComparison . OrdinalIgnoreCase ) ) ;
297295 }
298296 else
299297 {
300- var func = functions . Where ( f => f . Name == location . Name ) . FirstOrDefault ( ) ;
298+ var func = functions . FirstOrDefault ( f => string . Equals ( f . Name , location . Name , StringComparison . OrdinalIgnoreCase ) ) ;
301299 if ( func != null )
302- foundVar = func . LocalVariables . Where ( v => v . Name == varName ) . FirstOrDefault ( ) ;
300+ foundVar = func . LocalVariables . FirstOrDefault ( v => string . Equals ( v . Name , varName , StringComparison . OrdinalIgnoreCase ) ) ;
303301 }
304302 }
305303
@@ -322,15 +320,15 @@ public ZXBasicMap(ZXCodeFile MainFile, IEnumerable<ZXCodeFile> AllFiles, string
322320 //(to avoid the very unprobable case where the same var is defined in different files in locations that match the same range)
323321 if ( possibleLocation . LocationType == ZXBasicLocationType . Sub )
324322 {
325- var sub = subs . Where ( s => s . Name == possibleLocation . Name ) . FirstOrDefault ( ) ;
323+ var sub = subs . FirstOrDefault ( s => string . Equals ( s . Name , possibleLocation . Name , StringComparison . OrdinalIgnoreCase ) ) ;
326324 if ( sub != null )
327- foundVar = sub . LocalVariables . Where ( v => v . Name == varName && ! v . Unused ) . FirstOrDefault ( ) ;
325+ foundVar = sub . LocalVariables . FirstOrDefault ( v => string . Equals ( v . Name , varName , StringComparison . OrdinalIgnoreCase ) && ! v . Unused ) ;
328326 }
329327 else
330328 {
331- var func = functions . Where ( f => f . Name == possibleLocation . Name ) . FirstOrDefault ( ) ;
329+ var func = functions . FirstOrDefault ( f => string . Equals ( f . Name , possibleLocation . Name , StringComparison . OrdinalIgnoreCase ) ) ;
332330 if ( func != null )
333- foundVar = func . LocalVariables . Where ( v => v . Name == varName && ! v . Unused ) . FirstOrDefault ( ) ;
331+ foundVar = func . LocalVariables . FirstOrDefault ( v => string . Equals ( v . Name , varName , StringComparison . OrdinalIgnoreCase ) && ! v . Unused ) ;
334332 }
335333
336334 //If the criteria finds a var, return it
@@ -359,11 +357,7 @@ void GetSubVars(ZXBasicSub Sub, string[] Lines)
359357 if ( varNameDef . Contains ( "(" ) ) //array
360358 {
361359 string varName = varNameDef . Substring ( 0 , varNameDef . IndexOf ( "(" ) ) . Trim ( ) ;
362-
363- //Ignore unused vars (vars that are found only on its dim line, there may be the improbable
364- //case where a var is defined and used in the same line using a colon and not used
365- //anywhere else, but that would be an awful code :) )
366- if ( ! Lines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_]){ varName } ($|[^a-zA-Z0-9_])", RegexOptions . Multiline ) ) )
360+ if ( ! Lines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_$]){ Regex . Escape ( varName ) } ($|[^a-zA-Z0-9_$])", RegexOptions . Multiline ) ) )
367361 continue ;
368362
369363 string [ ] dims = varNameDef . Substring ( varNameDef . IndexOf ( "(" ) + 1 ) . Replace ( ")" , "" ) . Split ( "," , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -379,9 +373,7 @@ void GetSubVars(ZXBasicSub Sub, string[] Lines)
379373 foreach ( var vName in varNames )
380374 {
381375 string varName = vName . Trim ( ) ;
382-
383- //Ignore unused vars
384- if ( ! Lines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_]){ varName } ($|[^a-zA-Z0-9_])", RegexOptions . Multiline ) ) )
376+ if ( ! Lines . Skip ( buc + 1 ) . Any ( l => Regex . IsMatch ( l , $ "(^|[^a-zA-Z0-9_$]){ Regex . Escape ( varName ) } ($|[^a-zA-Z0-9_$])", RegexOptions . Multiline ) ) )
385377 continue ;
386378
387379 var storage = StorageFromString ( dimMatch . Groups [ 5 ] . Value , varName ) ;
@@ -415,15 +407,15 @@ public List<ZXBasicLocation> GetBuildLocations(ZXCodeFile CodeFile)
415407
416408 if ( subMatch != null && subMatch . Success )
417409 {
418- loc = new ZXBasicLocation { Name = subMatch . Groups [ 2 ] . Value . Trim ( ) , LocationType = ZXBasicLocationType . Sub , FirstLine = buc , File = Path . Combine ( CodeFile . Directory , CodeFile . TempFileName ) } ;
410+ loc = new ZXBasicLocation { Name = subMatch . Groups [ 4 ] . Value . Trim ( ) , LocationType = ZXBasicLocationType . Sub , FirstLine = buc , File = Path . Combine ( CodeFile . Directory , CodeFile . TempFileName ) } ;
419411 continue ;
420412 }
421413
422414 var funcMatch = regFunc . Match ( line ) ;
423415
424416 if ( funcMatch != null && funcMatch . Success )
425417 {
426- loc = new ZXBasicLocation { Name = funcMatch . Groups [ 2 ] . Value . Trim ( ) , LocationType = ZXBasicLocationType . Function , FirstLine = buc , File = Path . Combine ( CodeFile . Directory , CodeFile . TempFileName ) } ;
418+ loc = new ZXBasicLocation { Name = funcMatch . Groups [ 4 ] . Value . Trim ( ) , LocationType = ZXBasicLocationType . Function , FirstLine = buc , File = Path . Combine ( CodeFile . Directory , CodeFile . TempFileName ) } ;
427419 continue ;
428420 }
429421 }
@@ -465,7 +457,7 @@ public bool ContainsBuildDim(ZXCodeFile CodeFile, string VarName, int LineNumber
465457 if ( LineNumber >= lines . Length )
466458 return false ;
467459
468- return Regex . IsMatch ( lines [ LineNumber ] , $ "(\\ s|,){ VarName } (\\ s|,|\\ (|$)", RegexOptions . Multiline ) ;
460+ return Regex . IsMatch ( lines [ LineNumber ] , $ "(\\ s|,){ Regex . Escape ( VarName ) } (\\ s|,|\\ (|$)", RegexOptions . Multiline ) ;
469461 }
470462
471463 private static void ParseInputParameters ( string ParameterString , List < ZXBasicParameter > Storage )
0 commit comments