lib/linguist/heuristics.rb in github-linguist-5.0.8 vs lib/linguist/heuristics.rb in github-linguist-5.0.9

- old
+ new

@@ -123,15 +123,22 @@ Language["C#"] end end disambiguate ".d" do |data| - if /^module /.match(data) + # see http://dlang.org/spec/grammar + # ModuleDeclaration | ImportDeclaration | FuncDeclaration | unittest + if /^module\s+[\w.]*\s*;|import\s+[\w\s,.:]*;|\w+\s+\w+\s*\(.*\)(?:\(.*\))?\s*{[^}]*}|unittest\s*(?:\(.*\))?\s*{[^}]*}/.match(data) Language["D"] - elsif /^((dtrace:::)?BEGIN|provider |#pragma (D (option|attributes)|ident)\s)/.match(data) + # see http://dtrace.org/guide/chp-prog.html, http://dtrace.org/guide/chp-profile.html, http://dtrace.org/guide/chp-opt.html + elsif /^(\w+:\w*:\w*:\w*|BEGIN|END|provider\s+|(tick|profile)-\w+\s+{[^}]*}|#pragma\s+D\s+(option|attributes|depends_on)\s|#pragma\s+ident\s)/.match(data) Language["DTrace"] - elsif /(\/.*:( .* \\)$| : \\$|^ : |: \\$)/.match(data) + # path/target : dependency \ + # target : \ + # : dependency + # path/file.ext1 : some/path/../file.ext2 + elsif /([\/\\].*:\s+.*\s\\$|: \\$|^ : |^[\w\s\/\\.]+\w+\.\w+\s*:\s+[\w\s\/\\.]+\w+\.\w+)/.match(data) Language["Makefile"] end end disambiguate ".ecl" do |data| @@ -156,19 +163,19 @@ if /^: /.match(data) Language["Forth"] elsif data.include?("flowop") Language["Filebench WML"] elsif fortran_rx.match(data) - Language["FORTRAN"] + Language["Fortran"] end end disambiguate ".for" do |data| if /^: /.match(data) Language["Forth"] elsif fortran_rx.match(data) - Language["FORTRAN"] + Language["Fortran"] end end disambiguate ".fr" do |data| if /^(: |also |new-device|previous )/.match(data) @@ -217,11 +224,11 @@ if /\(def(un|macro)\s/.match(data) Language["Common Lisp"] elsif /^(%[%{}]xs|<.*>)/.match(data) Language["Lex"] elsif /^\.[a-z][a-z](\s|$)/i.match(data) - Language["Groff"] + Language["Roff"] elsif /^\((de|class|rel|code|data|must)\s/.match(data) Language["PicoLisp"] end end @@ -261,11 +268,11 @@ disambiguate ".md" do |data| if /(^[-a-z0-9=#!\*\[|>])|<\//i.match(data) || data.empty? Language["Markdown"] elsif /^(;;|\(define_)/.match(data) - Language["GCC machine description"] + Language["GCC Machine Description"] else Language["Markdown"] end end @@ -287,21 +294,21 @@ end end disambiguate ".ms" do |data| if /^[.'][a-z][a-z](\s|$)/i.match(data) - Language["Groff"] + Language["Roff"] elsif /(?<!\S)\.(include|globa?l)\s/.match(data) || /(?<!\/\*)(\A|\n)\s*\.[A-Za-z]/.match(data.gsub(/"([^\\"]|\\.)*"|'([^\\']|\\.)*'|\\\s*(?:--.*)?\n/, "")) - Language["GAS"] + Language["Unix Assembly"] else Language["MAXScript"] end end disambiguate ".n" do |data| if /^[.']/.match(data) - Language["Groff"] + Language["Roff"] elsif /^(module|namespace|using)\s/.match(data) Language["Nemerle"] end end @@ -335,20 +342,20 @@ elsif /^(use v6|(my )?class|module)/.match(data) Language["Perl6"] end end - disambiguate ".pm", ".t" do |data| - if /use strict|use\s+v?5\./.match(data) - Language["Perl"] - elsif /^(use v6|(my )?class|module)/.match(data) + disambiguate ".pm" do |data| + if /^\s*(?:use\s+v6\s*;|(?:\bmy\s+)?class|module)\b/.match(data) Language["Perl6"] + elsif /\buse\s+(?:strict\b|v?5\.)/.match(data) + Language["Perl"] end end disambiguate ".pod" do |data| - if /^=\w+$/.match(data) + if /^=\w+\b/.match(data) Language["Pod"] else Language["Perl"] end end @@ -383,11 +390,11 @@ disambiguate ".rno" do |data| if /^\.!|^\.end lit(?:eral)?\b/i.match(data) Language["RUNOFF"] elsif /^\.\\" /.match(data) - Language["Groff"] + Language["Roff"] end end disambiguate ".rpy" do |data| if /(^(import|from|class|def)\s)/m.match(data) @@ -434,13 +441,15 @@ Language["SubRip Text"] end end disambiguate ".t" do |data| - if /^\s*%|^\s*var\s+\w+\s*:\s*\w+/.match(data) + if /^\s*%[ \t]+|^\s*var\s+\w+\s*:=\s*\w+/.match(data) Language["Turing"] - elsif /^\s*use\s+v6\s*;/.match(data) + elsif /^\s*(?:use\s+v6\s*;|\bmodule\b|\b(?:my\s+)?class\b)/.match(data) Language["Perl6"] + elsif /\buse\s+(?:strict\b|v?5\.)/.match(data) + Language["Perl"] end end disambiguate ".toc" do |data| if /^## |@no-lib-strip@/.match(data)