From 9c64f72f358d3cdef45d2a76a0fcbe2fb1f579dc Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Wed, 12 Nov 2014 19:38:54 -0500 Subject: [PATCH 1/2] Add .mm as an XML extension with heuristic rule --- lib/linguist/heuristics.rb | 13 ++++++ lib/linguist/languages.yml | 1 + samples/XML/some-ideas.mm | 89 ++++++++++++++++++++++++++++++++++++++ test/test_heuristics.rb | 12 +++++ 4 files changed, 115 insertions(+) create mode 100644 samples/XML/some-ideas.mm diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index c7519881..8585dbfe 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -34,6 +34,9 @@ module Linguist if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) } result = disambiguate_asc(data, languages) end + if languages.all? { |l| ["XML", "Objective-C++"].include?(l) } + result = disambiguate_mm(data, languages) + end return result end end @@ -124,6 +127,16 @@ module Linguist matches end + def self.disambiguate_mm(data, languages) + matches = [] + if //.match(data) + matches << Language["XML"] + else + matches << Language["Objective-C++"] + end + matches + end + def self.active? !!ACTIVE end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index fc00dfbf..99584772 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2771,6 +2771,7 @@ XML: - .jelly - .kml - .launch + - .mm - .mxml - .nproj - .nuspec diff --git a/samples/XML/some-ideas.mm b/samples/XML/some-ideas.mm new file mode 100644 index 00000000..070e87e4 --- /dev/null +++ b/samples/XML/some-ideas.mm @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index e75fb470..7f9fc585 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -122,4 +122,16 @@ class TestHeuristcs < Test::Unit::TestCase results = Heuristics.disambiguate_sc(fixture("Scala/node11.sc"), languages) assert_equal Language["Scala"], results.first end + + def test_mm_objective_cpp_by_heuristics + languages = ["XML", "Objective-C++"] + results = Heuristics.disambiguate_mm(fixture("Objective-C++/objsql.mm"), languages) + assert_equal Language["Objective-C++"], results.first + end + + def test_mm_xml_by_heuristics + languages = ["XML", "Objective-C++"] + results = Heuristics.disambiguate_mm(fixture("XML/some-ideas.mm"), languages) + assert_equal Language["XML"], results.first + end end From 1356d4e579ec783e7f29b55ae989b70c5f907eb5 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Mon, 17 Nov 2014 19:20:45 -0500 Subject: [PATCH 2/2] Remove heuristic rules for .mm files --- lib/linguist/heuristics.rb | 13 ------------- test/test_heuristics.rb | 12 ------------ 2 files changed, 25 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 8585dbfe..c7519881 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -34,9 +34,6 @@ module Linguist if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) } result = disambiguate_asc(data, languages) end - if languages.all? { |l| ["XML", "Objective-C++"].include?(l) } - result = disambiguate_mm(data, languages) - end return result end end @@ -127,16 +124,6 @@ module Linguist matches end - def self.disambiguate_mm(data, languages) - matches = [] - if //.match(data) - matches << Language["XML"] - else - matches << Language["Objective-C++"] - end - matches - end - def self.active? !!ACTIVE end diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 7f9fc585..e75fb470 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -122,16 +122,4 @@ class TestHeuristcs < Test::Unit::TestCase results = Heuristics.disambiguate_sc(fixture("Scala/node11.sc"), languages) assert_equal Language["Scala"], results.first end - - def test_mm_objective_cpp_by_heuristics - languages = ["XML", "Objective-C++"] - results = Heuristics.disambiguate_mm(fixture("Objective-C++/objsql.mm"), languages) - assert_equal Language["Objective-C++"], results.first - end - - def test_mm_xml_by_heuristics - languages = ["XML", "Objective-C++"] - results = Heuristics.disambiguate_mm(fixture("XML/some-ideas.mm"), languages) - assert_equal Language["XML"], results.first - end end