Skip to content

Commit

Permalink
Several extensions can be associated to a heuristic rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pchaigno committed Jun 6, 2015
1 parent 7fb62de commit 656f4f4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/linguist/heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ def self.call(blob, candidates)
# end
# end
#
def self.disambiguate(extension, &heuristic)
@heuristics << new(extension, &heuristic)
def self.disambiguate(*extensions, &heuristic)
@heuristics << new(extensions, &heuristic)
end

# Internal: Array of defined heuristics
@heuristics = []

# Internal
def initialize(extension, &heuristic)
@extension = extension
def initialize(extensions, &heuristic)
@extensions = extensions
@heuristic = heuristic
end

# Internal: Check if this heuristic matches the candidate languages.
def matches?(filename)
filename.end_with?(@extension)
@extensions.any? { |ext| filename.end_with?(ext) }
end

# Internal: Perform the heuristic
Expand Down Expand Up @@ -167,7 +167,7 @@ def call(data)
end
end

disambiguate ".for" do |data|
disambiguate ".for", ".f" do |data|
if /^: /.match(data)
Language["Forth"]
elsif /^([c*][^a-z]| (subroutine|program)\s|\s*!)/i.match(data)
Expand Down Expand Up @@ -217,7 +217,7 @@ def call(data)
end
end

disambiguate ".lisp" do |data|
disambiguate ".lsp", ".lisp" do |data|
if /^\s*\((defun|in-package|defpackage) /i.match(data)
Language["Common Lisp"]
elsif /^\s*\(define /.match(data)
Expand Down

0 comments on commit 656f4f4

Please sign in to comment.