lib/linguist/heuristics.rb in github-linguist-3.4.1 vs lib/linguist/heuristics.rb in github-linguist-3.5.0

- old
+ new

@@ -23,10 +23,19 @@ result = disambiguate_pro(data, languages) end if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) } result = disambiguate_cl(data, languages) end + if languages.all? { |l| ["Hack", "PHP"].include?(l) } + result = disambiguate_hack(data, languages) + end + if languages.all? { |l| ["Scala", "SuperCollider"].include?(l) } + result = disambiguate_sc(data, languages) + end + if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) } + result = disambiguate_asc(data, languages) + end return result end end # .h extensions are ambiguous between C, C++, and Objective-C. @@ -83,9 +92,36 @@ def self.disambiguate_r(data, languages) matches = [] matches << Language["Rebol"] if /\bRebol\b/i.match(data) matches << Language["R"] if data.include?("<-") + matches + end + + def self.disambiguate_hack(data, languages) + matches = [] + if data.include?("<?hh") + matches << Language["Hack"] + elsif /<?[^h]/.match(data) + matches << Language["PHP"] + end + matches + end + + def self.disambiguate_sc(data, languages) + matches = [] + if (/\^(this|super)\./.match(data) || /^\s*(\+|\*)\s*\w+\s*{/.match(data) || /^\s*~\w+\s*=\./.match(data)) + matches << Language["SuperCollider"] + end + if (/^\s*import (scala|java)\./.match(data) || /^\s*val\s+\w+\s*=/.match(data) || /^\s*class\b/.match(data)) + matches << Language["Scala"] + end + matches + end + + def self.disambiguate_asc(data, languages) + matches = [] + matches << Language["AsciiDoc"] if /^=+(\s|\n)/.match(data) matches end def self.active? !!ACTIVE