lib/linguist/heuristics.rb in github-linguist-4.4.2 vs lib/linguist/heuristics.rb in github-linguist-4.4.3
- old
+ new
@@ -31,11 +31,11 @@
# Examples
#
# disambiguate "Perl", "Prolog" do |data|
# if data.include?("use strict")
# Language["Perl"]
- # elsif data.include?(":-")
+ # elsif /^[^#]+:-/.match(data)
# Language["Prolog"]
# end
# end
#
def self.disambiguate(*languages, &heuristic)
@@ -92,27 +92,31 @@
disambiguate "Perl", "Perl6", "Prolog" do |data|
if data.include?("use v6")
Language["Perl6"]
elsif data.match(/use strict|use\s+v?5\./)
Language["Perl"]
- elsif data.include?(":-")
+ elsif /^[^#]+:-/.match(data)
Language["Prolog"]
end
end
disambiguate "ECL", "Prolog" do |data|
- if data.include?(":-")
+ if /^[^#]+:-/.match(data)
Language["Prolog"]
elsif data.include?(":=")
Language["ECL"]
end
end
- disambiguate "IDL", "Prolog" do |data|
- if data.include?(":-")
+ disambiguate "IDL", "Prolog", "INI", "QMake" do |data|
+ if /^[^#]+:-/.match(data)
Language["Prolog"]
- else
+ elsif data.include?("last_client=")
+ Language["INI"]
+ elsif data.include?("HEADERS") && data.include?("SOURCES")
+ Language["QMake"]
+ elsif /^\s*function[ \w,]+$/.match(data)
Language["IDL"]
end
end
disambiguate "GAP", "Scilab" do |data|
@@ -176,15 +180,17 @@
elsif /^\s*(#include|#pragma|precision|uniform|varying|void)/.match(data)
Language["GLSL"]
end
end
- disambiguate "M", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data|
+ disambiguate "M", "MUF", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data|
if ObjectiveCRegex.match(data)
Language["Objective-C"]
elsif data.include?(":- module")
Language["Mercury"]
+ elsif /^: /.match(data)
+ Language["MUF"]
elsif /^\s*;/.match(data)
Language["M"]
elsif /^\s*\(\*/.match(data)
Language["Mathematica"]
elsif /^\s*%/.match(data)
@@ -225,9 +231,35 @@
Language["Forth"]
elsif /^\s*(import|module|package|data|type) /.match(data)
Language["Frege"]
else
Language["Text"]
+ end
+ end
+
+ disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data|
+ if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN( WORK| TRANSACTION)?;/i.match(data)
+ #Postgres
+ Language["PLpgSQL"]
+ elsif /(alter module)|(language sql)|(begin( NOT)+ atomic)/i.match(data) || /signal SQLSTATE '[0-9]+'/i.match(data)
+ #IBM db2
+ Language["SQLPL"]
+ elsif /pragma|\$\$PLSQL_|XMLTYPE|sysdate|systimestamp|\.nextval|connect by|AUTHID (DEFINER|CURRENT_USER)/i.match(data) || /constructor\W+function/i.match(data)
+ #Oracle
+ Language["PLSQL"]
+ elsif ! /begin|boolean|package|exception/i.match(data)
+ #Generic SQL
+ Language["SQL"]
+ end
+ end
+
+ disambiguate "D", "DTrace", "Makefile" do |data|
+ if /^module /.match(data)
+ Language["D"]
+ elsif /^((dtrace:::)?BEGIN|provider |#pragma (D (option|attributes)|ident)\s)/.match(data)
+ Language["DTrace"]
+ elsif /(\/.*:( .* \\)$| : \\$|^ : |: \\$)/.match(data)
+ Language["Makefile"]
end
end
end
end