Allow POD with Perl shebangs (#3735)

* Allow perl interpreter for Pod too

* Use precise dist

* This is a tautology

* Update heuristic to accept candidate input

* Minor rename
This commit is contained in:
Yuki Izumi
2017-07-31 13:39:20 +10:00
committed by GitHub
parent b94e018c3a
commit 7451424f12
4 changed files with 2094 additions and 12 deletions

View File

@@ -31,3 +31,4 @@ git:
depth: 3 depth: 3
cache: bundler cache: bundler
dist: precise

View File

@@ -17,9 +17,8 @@ module Linguist
data = blob.data data = blob.data
@heuristics.each do |heuristic| @heuristics.each do |heuristic|
if heuristic.matches?(blob.name) if heuristic.matches?(blob.name, candidates)
languages = Array(heuristic.call(data)) return Array(heuristic.call(data))
return languages if languages.any? || languages.all? { |l| candidates.include?(l) }
end end
end end
@@ -28,7 +27,8 @@ module Linguist
# Internal: Define a new heuristic. # Internal: Define a new heuristic.
# #
# languages - String names of languages to disambiguate. # exts_and_langs - String names of file extensions and languages to
# disambiguate.
# heuristic - Block which takes data as an argument and returns a Language or nil. # heuristic - Block which takes data as an argument and returns a Language or nil.
# #
# Examples # Examples
@@ -41,23 +41,28 @@ module Linguist
# end # end
# end # end
# #
def self.disambiguate(*extensions, &heuristic) def self.disambiguate(*exts_and_langs, &heuristic)
@heuristics << new(extensions, &heuristic) @heuristics << new(exts_and_langs, &heuristic)
end end
# Internal: Array of defined heuristics # Internal: Array of defined heuristics
@heuristics = [] @heuristics = []
# Internal # Internal
def initialize(extensions, &heuristic) def initialize(exts_and_langs, &heuristic)
@extensions = extensions @exts_and_langs, @candidates = exts_and_langs.partition {|e| e =~ /\A\./}
@heuristic = heuristic @heuristic = heuristic
end end
# Internal: Check if this heuristic matches the candidate languages. # Internal: Check if this heuristic matches the candidate filenames or
def matches?(filename) # languages.
def matches?(filename, candidates)
filename = filename.downcase filename = filename.downcase
@extensions.any? { |ext| filename.end_with?(ext) } candidates = candidates.compact.map(&:name)
@exts_and_langs.any? { |ext| filename.end_with?(ext) } ||
(candidates.any? &&
(@candidates - candidates == [] &&
candidates - @candidates == []))
end end
# Internal: Perform the heuristic # Internal: Perform the heuristic
@@ -354,7 +359,7 @@ module Linguist
end end
end end
disambiguate ".pod" do |data| disambiguate ".pod", "Pod", "Perl" do |data|
if /^=\w+\b/.match(data) if /^=\w+\b/.match(data)
Language["Pod"] Language["Pod"]
else else

View File

@@ -3300,6 +3300,8 @@ Pod:
wrap: true wrap: true
extensions: extensions:
- ".pod" - ".pod"
interpreters:
- perl
tm_scope: none tm_scope: none
language_id: 288 language_id: 288
PogoScript: PogoScript:

2074
samples/Pod/feedgnuplot Normal file

File diff suppressed because it is too large Load Diff