From 0867e7b69bb9a9d21a439ab37d2530b508c2293a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 20 Jul 2012 15:30:53 -0500 Subject: [PATCH] Remove old language disambiguation functions --- lib/linguist/blob_helper.rb | 151 ------------------------------------ lib/linguist/language.rb | 7 -- 2 files changed, 158 deletions(-) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 8f2941e8..84a9bdaa 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -446,17 +446,9 @@ module Linguist # Internal: Disambiguates between multiple language extensions. # - # Delegates to "guess_EXTENSION_language". - # - # Please add additional test coverage to - # `test/test_blob.rb#test_language` if you add another method. - # # Returns a Language or nil. def disambiguate_extension_language if Language.ambiguous?(extname) - # name = "guess_#{extname.sub(/^\./, '')}_language" - # send(name) if respond_to?(name) - possible_languages = Language.all.select { |l| l.extensions.include?(extname) } if possible_languages.any? if result = Classifier.instance.classify(data, possible_languages).first @@ -466,142 +458,6 @@ module Linguist end end - # Internal: Guess language of .cls files - # - # Returns a Language. - def guess_cls_language - if lines.grep(/^(%|\\)/).any? - Language['TeX'] - elsif lines.grep(/^\s*(CLASS|METHOD|INTERFACE).*:\s*/i).any? || lines.grep(/^\s*(USING|DEFINE)/i).any? - Language['OpenEdge ABL'] - elsif lines.grep(/\{$/).any? || lines.grep(/\}$/).any? - Language['Apex'] - elsif lines.grep(/^(\'\*|Attribute|Option|Sub|Private|Protected|Public|Friend)/i).any? - Language['Visual Basic'] - else - # The most common language should be the fallback - Language['TeX'] - end - end - - # Internal: Guess language of header files (.h). - # - # Returns a Language. - def guess_h_language - if lines.grep(/^@(interface|property|private|public|end)/).any? - Language['Objective-C'] - elsif lines.grep(/^class |^\s+(public|protected|private):/).any? - Language['C++'] - else - Language['C'] - end - end - - # Internal: Guess language of .m files. - # - # Objective-C heuristics: - # * Keywords ("#import", "#include", "#ifdef", #define, "@end") or "//" and opening "\*" comments - # - # Matlab heuristics: - # * Leading "function " of "classdef " keyword - # * "%" comments - # - # Note: All "#" keywords, e.g., "#import", are guaranteed to be Objective-C. Because the ampersand - # is used to created function handles and anonymous functions in Matlab, most "@" keywords are not - # safe heuristics. However, "end" is a reserved term in Matlab and can't be used to create a valid - # function handle. Because @end is required to close any @implementation, @property, @interface, - # @synthesize, etc. directive in Objective-C, only @end needs to be checked for. - # - # Returns a Language. - def guess_m_language - # Objective-C keywords or comments - if lines.grep(/^#(import|include|ifdef|define)|@end/).any? || lines.grep(/^\s*\/\//).any? || lines.grep(/^\s*\/\*/).any? - Language['Objective-C'] - - # Matlab file function or class or comments - elsif lines.any? && lines.first.match(/^\s*(function |classdef )/) || lines.grep(/^\s*%/).any? - Language['Matlab'] - - # Fallback to Objective-C, don't want any Matlab false positives - else - Language['Objective-C'] - end - end - - # Internal: Guess language of .pl files - # - # The rules for disambiguation are: - # - # 1. Many perl files begin with a shebang - # 2. Most Prolog source files have a rule somewhere (marked by the :- operator) - # 3. Default to Perl, because it is more popular - # - # Returns a Language. - def guess_pl_language - if shebang_script == 'perl' - Language['Perl'] - elsif lines.grep(/:-/).any? - Language['Prolog'] - else - Language['Perl'] - end - end - - # Internal: Guess language of .r files. - # - # Returns a Language. - def guess_r_language - if lines.grep(/(rebol|(:\s+func|make\s+object!|^\s*context)\s*\[)/i).any? - Language['Rebol'] - else - Language['R'] - end - end - - # Internal: Guess language of .t files. - # - # Returns a Language. - def guess_t_language - score = 0 - score += 1 if lines.grep(/^% /).any? - score += data.gsub(/ := /).count - score += data.gsub(/proc |procedure |fcn |function /).count - score += data.gsub(/var \w+: \w+/).count - - # Tell-tale signs its gotta be Perl - if lines.grep(/^(my )?(sub |\$|@|%)\w+/).any? - score = 0 - end - - if score >= 3 - Language['Turing'] - else - Language['Perl'] - end - end - - # Internal: Guess language of .v files. - # - # Returns a Language - def guess_v_language - if lines.grep(/^(\/\*|\/\/|module|parameter|input|output|wire|reg|always|initial|begin|\`)/).any? - Language['Verilog'] - else - Language['Coq'] - end - end - - # Internal: Guess language of .gsp files. - # - # Returns a Language. - def guess_gsp_language - if lines.grep(/<%|<%@|\$\{|<%|