soffes / SyntaxKit

TextMate-style syntax highlighting
MIT License
472 stars 65 forks source link

[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds #9

Closed janyou closed 8 years ago

janyou commented 9 years ago

use AttributedParser for .m file

@implementation Car

- (int) getOdometerReading
{
    SpecificCar *myCar = [[SpecificCar alloc] init];
    [myCar getOdometerReading];
    return 50000;
}
@end

crashed with: *\ -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds

The crash seems to be happening in Parser.swift

       /// Returns new location
    private func parse(string: String, inRange bounds: NSRange, callback: Callback) -> UInt {
        ...
          let endBounds = NSMakeRange(location, bounds.length - location - bounds.location) 
                  //when endBounds.length = -106  
rnaud commented 8 years ago

Having the same issue, I believe it's happening here:

matches = expression.matchesInString(string, options: [], range: bounds)

We are sometimes getting bounds that seem illogical. We have negative bounds.length it seems.

soffes commented 8 years ago

Can you post some sample code that reproduces this issue?

soffes commented 8 years ago

Fixed in #14