Sublime Forum

Objective C Syntax Highlighting bug

#1

There seems to be a bug if there’s a newline right after the method target. Here’s a trivial example:

#import <Foundation/Foundation.h>

void foo() {
    NSString * foo;
    // Correct syntax highlighting
    [NSString stringWithString:@"foo"];
    [NSString stringWithCString: "foo" encoding: NSASCIIStringEncoding];
    [foo characterAtIndex:0];

    // Incorrect syntax highlighting if newline immediately after the
    // message target. 'stringWithString', 'stringWithCString', 'encoding',
    // and 'characterAtIndex' should all be blue.
    [NSString
        stringWithString:@"foo"];
    [NSString
        stringWithCString: "foo" encoding: NSASCIIStringEncoding];
    [foo
        characterAtIndex:0];
}

0 Likes

#2

I suspect the lexical match for the line needed the entire thing on the same line. The engine parses things a line at a time. It should be possible to alter this with a starting context and a finishing context which will let it scan over multiple lines.

0 Likes

#3

please could you log this at https://github.com/sublimehq/Packages

0 Likes

#4

Done. https://github.com/sublimehq/Packages/issues/1138

1 Like

#5

It’s probably possible to fix but it’s gonna take a chunk of refactoring again. You’ll have to distinguish [ between when it’s an array-access and when it’s the start of a method call, I think.

0 Likes