mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Start towards pl heuristics
This commit is contained in:
@@ -14,7 +14,10 @@ module Linguist
|
|||||||
def self.find_by_heuristics(data, languages)
|
def self.find_by_heuristics(data, languages)
|
||||||
if active?
|
if active?
|
||||||
if languages.all? { |l| ["Objective-C", "C++"].include?(l) }
|
if languages.all? { |l| ["Objective-C", "C++"].include?(l) }
|
||||||
disambiguate_h(data, languages)
|
disambiguate_c(data, languages)
|
||||||
|
end
|
||||||
|
if languages.all? { |l| ["Perl", "Prolog"].include?(l) }
|
||||||
|
disambiguate_pl(data, languages)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -23,14 +26,19 @@ module Linguist
|
|||||||
# We want to shortcut look for Objective-C _and_ now C++ too!
|
# We want to shortcut look for Objective-C _and_ now C++ too!
|
||||||
#
|
#
|
||||||
# Returns an array of Languages or []
|
# Returns an array of Languages or []
|
||||||
# TODO rename this method as we're not strictly disambiguating between .h files here.
|
def self.disambiguate_c(data, languages)
|
||||||
def self.disambiguate_h(data, languages)
|
|
||||||
matches = []
|
matches = []
|
||||||
matches << Language["Objective-C"] if data.include?("@interface")
|
matches << Language["Objective-C"] if data.include?("@interface")
|
||||||
matches << Language["C++"] if data.include?("#include <cstdint>")
|
matches << Language["C++"] if data.include?("#include <cstdint>")
|
||||||
matches
|
matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self_disambiguate_pl(data, languages)
|
||||||
|
matches = []
|
||||||
|
matches << Language["Prolog"] if data.include?(":-")
|
||||||
|
matches
|
||||||
|
end
|
||||||
|
|
||||||
def self.active?
|
def self.active?
|
||||||
!!ACTIVE
|
!!ACTIVE
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ class TestHeuristcs < Test::Unit::TestCase
|
|||||||
def test_obj_c_by_heuristics
|
def test_obj_c_by_heuristics
|
||||||
languages = ["C++", "Objective-C"]
|
languages = ["C++", "Objective-C"]
|
||||||
all_h_fixtures("Objective-C").each do |fixture|
|
all_h_fixtures("Objective-C").each do |fixture|
|
||||||
results = Heuristics.disambiguate_h(fixture("Objective-C/#{File.basename(fixture)}"), languages)
|
results = Heuristics.disambiguate_c(fixture("Objective-C/#{File.basename(fixture)}"), languages)
|
||||||
assert_equal Language["Objective-C"], results.first
|
assert_equal Language["Objective-C"], results.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cpp_by_heuristics
|
def test_cpp_by_heuristics
|
||||||
languages = ["C++", "Objective-C"]
|
languages = ["C++", "Objective-C"]
|
||||||
results = Heuristics.disambiguate_h(fixture("C++/render_adapter.cpp"), languages)
|
results = Heuristics.disambiguate_c(fixture("C++/render_adapter.cpp"), languages)
|
||||||
assert_equal Language["C++"], results.first
|
assert_equal Language["C++"], results.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user