From e0190a5a6e1ec52dbdb70ef9f62db6e6043bd03c Mon Sep 17 00:00:00 2001 From: Laurent Parenteau Date: Tue, 27 Mar 2012 11:47:52 -0400 Subject: [PATCH 1/4] Added detection for the new M (aka MUMPS) language. --- lib/linguist/blob_helper.rb | 7 +++++++ lib/linguist/languages.yml | 8 ++++++++ test/fixtures/m_simple.m | 4 ++++ test/test_blob.rb | 1 + 4 files changed, 20 insertions(+) create mode 100644 test/fixtures/m_simple.m diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 8050d37b..ba19144e 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -457,6 +457,9 @@ module Linguist # * Leading function keyword # * "%" comments # + # M heuristics: + # * ";" comments + # # Returns a Language. def guess_m_language # Objective-C keywords @@ -471,6 +474,10 @@ module Linguist elsif lines.grep(/^%/).any? Language['Matlab'] + # M comment + elsif lines.grep(/^[ \t]*;/).any? + Language['M'] + # Fallback to Objective-C, don't want any Matlab false positives else Language['Objective-C'] diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index c74f6a94..28285e00 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -627,6 +627,14 @@ Lua: - .lua - .nse +M: + type: programming + lexer: Text only + aliases: + - mumps + extensions: + - .m + Makefile: extensions: - .mak diff --git a/test/fixtures/m_simple.m b/test/fixtures/m_simple.m new file mode 100644 index 00000000..73592acc --- /dev/null +++ b/test/fixtures/m_simple.m @@ -0,0 +1,4 @@ +fox + ; The quick brown fox jumps over the lazy dog + write "The quick brown fox jumps over the lazy dog",! + quit diff --git a/test/test_blob.rb b/test/test_blob.rb index f62ad060..9d0a49bc 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -307,6 +307,7 @@ class TestBlob < Test::Unit::TestCase assert_equal Language['Objective-C'], blob("hello.m").language assert_equal Language['Matlab'], blob("matlab_function.m").language assert_equal Language['Matlab'], blob("matlab_script.m").language + assert_equal Language['M'], blob("m_simple.m").language # .r disambiguation assert_equal Language['R'], blob("hello-r.R").language From 1e34faa920657b45ab281295b94e7d53578d2549 Mon Sep 17 00:00:00 2001 From: Laurent Parenteau Date: Wed, 28 Mar 2012 20:30:24 -0400 Subject: [PATCH 2/4] 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 From 23b6b4c499ab91777a8efca2cc1a2478d2d5a73e Mon Sep 17 00:00:00 2001 From: Laurent Parenteau Date: Fri, 27 Apr 2012 10:09:37 -0400 Subject: [PATCH 3/4] Use Common Lisp lexer for M syntax highlighting, which gives pretty good results. --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 28285e00..1d6526d1 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -629,7 +629,7 @@ Lua: M: type: programming - lexer: Text only + lexer: common-lisp aliases: - mumps extensions: From 91364a9769ba774876fb9dfc33bcfbe10c1de35f Mon Sep 17 00:00:00 2001 From: Laurent Parenteau Date: Mon, 14 May 2012 09:56:00 -0400 Subject: [PATCH 4/4] Improved comment. --- lib/linguist/blob_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 2a40f59c..b2c5bf42 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -478,7 +478,7 @@ module Linguist 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 + # Fallback to Objective-C, don't want any M or Matlab false positives else Language['Objective-C'] end