Linguist: Objective-C is being confused with Mathematica

Created on 5 Mar 2015  路  12Comments  路  Source: github/linguist

This file is actually Objective-C, but the Linguist thinks it's Mathematica. There are no other files that I know of that are like this.

Misidentified Language

Most helpful comment

This is still a problem for this file.

All 12 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

henrywright picture henrywright  路  6Comments

BnSalahFahmi picture BnSalahFahmi  路  3Comments

lucasrodes picture lucasrodes  路  6Comments

philiparvidsson picture philiparvidsson  路  4Comments

d4nyll picture d4nyll  路  3Comments