mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Several extensions can be associated to a heuristic rule
This commit is contained in:
@@ -41,22 +41,22 @@ module Linguist
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def self.disambiguate(extension, &heuristic)
|
def self.disambiguate(*extensions, &heuristic)
|
||||||
@heuristics << new(extension, &heuristic)
|
@heuristics << new(extensions, &heuristic)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Array of defined heuristics
|
# Internal: Array of defined heuristics
|
||||||
@heuristics = []
|
@heuristics = []
|
||||||
|
|
||||||
# Internal
|
# Internal
|
||||||
def initialize(extension, &heuristic)
|
def initialize(extensions, &heuristic)
|
||||||
@extension = extension
|
@extensions = extensions
|
||||||
@heuristic = heuristic
|
@heuristic = heuristic
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Check if this heuristic matches the candidate languages.
|
# Internal: Check if this heuristic matches the candidate languages.
|
||||||
def matches?(filename)
|
def matches?(filename)
|
||||||
filename.end_with?(@extension)
|
@extensions.any? { |ext| filename.end_with?(ext) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Perform the heuristic
|
# Internal: Perform the heuristic
|
||||||
@@ -167,7 +167,7 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
disambiguate ".for" do |data|
|
disambiguate ".for", ".f" do |data|
|
||||||
if /^: /.match(data)
|
if /^: /.match(data)
|
||||||
Language["Forth"]
|
Language["Forth"]
|
||||||
elsif /^([c*][^a-z]| (subroutine|program)\s|\s*!)/i.match(data)
|
elsif /^([c*][^a-z]| (subroutine|program)\s|\s*!)/i.match(data)
|
||||||
@@ -217,7 +217,7 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
disambiguate ".lisp" do |data|
|
disambiguate ".lsp", ".lisp" do |data|
|
||||||
if /^\s*\((defun|in-package|defpackage) /i.match(data)
|
if /^\s*\((defun|in-package|defpackage) /i.match(data)
|
||||||
Language["Common Lisp"]
|
Language["Common Lisp"]
|
||||||
elsif /^\s*\(define /.match(data)
|
elsif /^\s*\(define /.match(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user