lib/linguist/heuristics.rb in github-linguist-4.2.7 vs lib/linguist/heuristics.rb in github-linguist-4.3.0

- old
+ new

@@ -59,10 +59,13 @@ # Internal: Perform the heuristic def call(data) @heuristic.call(data) end + # Common heuristics + ObjectiveCRegex = /^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/ + disambiguate "BitBake", "BlitzBasic" do |data| if /^\s*; /.match(data) || data.include?("End Function") Language["BlitzBasic"] elsif /^\s*(# |include|require)\b/.match(data) Language["BitBake"] @@ -76,11 +79,11 @@ Language["C#"] end end disambiguate "Objective-C", "C++", "C" do |data| - if (/^[ \t]*@(interface|class|protocol|property|end|synchronised|selector|implementation)\b/.match(data)) + if ObjectiveCRegex.match(data) Language["Objective-C"] elsif (/^\s*#\s*include <(cstdint|string|vector|map|list|array|bitset|queue|stack|forward_list|unordered_map|unordered_set|(i|o|io)stream)>/.match(data) || /^\s*template\s*</.match(data) || /^[ \t]*try/.match(data) || /^[ \t]*catch\s*\(/.match(data) || /^[ \t]*(class|(using[ \t]+)?namespace)\s+\w+/.match(data) || /^[ \t]*(private|public|protected):$/.match(data) || /std::\w+/.match(data)) Language["C++"] end @@ -110,10 +113,19 @@ else Language["IDL"] end end + disambiguate "GAP", "Scilab" do |data| + if (data.include?("gap> ")) + Language["GAP"] + # Heads up - we don't usually write heuristics like this (with no regex match) + else + Language["Scilab"] + end + end + disambiguate "Common Lisp", "OpenCL", "Cool" do |data| if data.include?("(defun ") Language["Common Lisp"] elsif /^class/x.match(data) Language["Cool"] @@ -158,18 +170,40 @@ elsif /^\s*(#include|#pragma|precision|uniform|varying|void)/.match(data) Language["GLSL"] end end + disambiguate "M", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data| + if ObjectiveCRegex.match(data) + Language["Objective-C"] + elsif data.include?(":- module") + Language["Mercury"] + elsif /^\s*;/.match(data) + Language["M"] + elsif /^\s*\(\*/.match(data) + Language["Mathematica"] + elsif /^\s*%/.match(data) + Language["Matlab"] + end + end + disambiguate "Gosu", "JavaScript" do |data| Language["Gosu"] if /^uses java\./.match(data) end disambiguate "LoomScript", "LiveScript" do |data| if /^\s*package\s*[\w\.\/\*\s]*\s*{/.match(data) Language["LoomScript"] else Language["LiveScript"] + end + end + + disambiguate "Common Lisp", "NewLisp" do |data| + if /^\s*\((defun|in-package|defpackage) /.match(data) + Language["Common Lisp"] + elsif /^\s*\(define /.match(data) + Language["NewLisp"] end end disambiguate "TypeScript", "XML" do |data| if data.include?("<TS ")