From 1e34faa920657b45ab281295b94e7d53578d2549 Mon Sep 17 00:00:00 2001 From: Laurent Parenteau Date: Wed, 28 Mar 2012 20:30:24 -0400 Subject: [PATCH] Improved M detection to be more specific. --- lib/linguist/blob_helper.rb | 8 ++++---- test/fixtures/m_simple.m | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index ba19144e..2a40f59c 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -458,7 +458,7 @@ module Linguist # * "%" comments # # M heuristics: - # * ";" comments + # * Look at first line. It is either a comment (1st regex) or label/code (2nd regex) # # Returns a Language. def guess_m_language @@ -466,7 +466,7 @@ module Linguist if lines.grep(/^#import|@(interface|implementation|property|synthesize|end)/).any? Language['Objective-C'] - # File function + # Matlab leading function keyword elsif lines.first.to_s =~ /^function / Language['Matlab'] @@ -474,8 +474,8 @@ module Linguist elsif lines.grep(/^%/).any? Language['Matlab'] - # M comment - elsif lines.grep(/^[ \t]*;/).any? + # M (see M heuristics above) + elsif lines.first.to_s =~ /^[\t ]*;/ or lines.first.to_s =~ /^%?[A-Za-z0-9]+[\t ]*;*/ Language['M'] # Fallback to Objective-C, don't want any Matlab false positives diff --git a/test/fixtures/m_simple.m b/test/fixtures/m_simple.m index 73592acc..53547477 100644 --- a/test/fixtures/m_simple.m +++ b/test/fixtures/m_simple.m @@ -1,4 +1,3 @@ -fox - ; The quick brown fox jumps over the lazy dog +fox ; The quick brown fox jumps over the lazy dog write "The quick brown fox jumps over the lazy dog",! quit