Permalink
Browse files

Roughly update the library to have all the languages that upstream Li…

…nguist does.
  • Loading branch information...
1 parent 26a4770 commit d53780868484a39cac36277e0912cc337589f159 @relrod relrod committed May 5, 2012
Showing with 401 additions and 20 deletions.
  1. +52 −0 lib/language_sniffer/blob_helper.rb
  2. +313 −12 lib/language_sniffer/languages.yml
  3. +34 −6 test/test_language.rb
  4. +2 −2 test/test_pathname.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require 'language_sniffer/language'
require 'language_sniffer/pathname'
require 'yaml'
@@ -225,6 +226,24 @@ def disambiguate_extension_language
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.
@@ -297,6 +316,39 @@ def guess_r_language
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.
Oops, something went wrong.

0 comments on commit d537808

Please sign in to comment.