We have a heuristic for this common mis-detection but it looks like the Objective-C regex isn't matching here. There _is_ a match though for Mathematica:
http://rubular.com/r/14CnutbFQq
I wonder if we should add things like NSString NSArray to this regex. Any suggestions on how to improve this @tbodt would be very welcome!
In the context of M, MUF, Mathematica, Matlab and Mercury couldn't we use a simpler regex? For instance #(include|import|define).
How about ^[ \t]*(@(interface|class|protocol|property|end|synchronised|selector|implementation))|(#(include|import|define))\b? A combination of the existing regex and @pchaigno's idea. Or we could just look for message-passing syntax:
/\[ [^\[]+? \s+ \w+(:.+?)? \]/x
This looks for [, some stuff that is not [ (the message target), some space, some word characters (the message name), an optional : followed by some stuff (message arguments), and a ]. I think it would match most Objective-C code. I tried it on a random app delegate from an app I'm working on, and the results can be found at http://rubular.com/r/NJhCNXkjOV.
Wouldn't the three keywords include, import and define be sufficient? I'm worried about the complexity (and performance implications) of these regex...
@pchaigno Hmm. Technically, you can write Objective-C code without any of those:
int main() {
}
But if you want to call any library functions, you need either include or import.
Plus, I now realize that the standard main.m doesn't match the Objective-C regex:
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
return NSApplicationMain(argc, argv);
}
No special Objective-C keywords. I don't know how that's disambiguated correctly.
I think \#(include|import|define) should work fine. If someone is going to create an Objective-C file with only int main(){}, they deserve to have the wrong language. That's probably legal in 10+ languages.
I have this problem too, but I can't share the whole file. It starts like this:
//
// FileName.m
// AppName
//
// Created by Creator on 12/13/13.
// Copyright (c) 2013 Creator. All rights reserved.
//
#import "FileName.h"
#import "ControllerManager.h"
#import "UserManager.h"
#import "Util.h"
@implementation FileName
@tbodt Is this still an issue?
@pchaigno not for me...
This is still a problem for this file.
The Objective-C file in the comment above from @elmindreda is still being mis-classified as Mathematica. Could this be because of the comment at the top of the file?
Right now it's being syntax highlighted as objective-c. My guess is that the classifier is fixed and you just need to wait for the cache to clear.
Most helpful comment
This is still a problem for this file.