mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Added detection for Prolog and disambiguation for .pl files
This commit is contained in:
@@ -262,6 +262,9 @@ module Linguist
|
||||
# If it's a .r file, try to guess the language
|
||||
r_language ||
|
||||
|
||||
# If it's a .pl file, try to guess the language
|
||||
pl_language ||
|
||||
|
||||
# See if there is a Language for the extension
|
||||
pathname.language ||
|
||||
|
||||
@@ -304,6 +307,26 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Guess language of .pl files
|
||||
#
|
||||
# Returns a Language.
|
||||
def pl_language
|
||||
return unless extname == '.pl'
|
||||
|
||||
# The rules for disambiguation are:
|
||||
#
|
||||
# 1. Many perl files begin with a shebang
|
||||
# 2. Most Prolog source files have a rule somewhere (marked by the :- operator)
|
||||
# 3. Default to Perl, because it is more popular
|
||||
if shebang_script == 'perl'
|
||||
Language['Perl']
|
||||
elsif lines.grep(/:-/).any?
|
||||
Language['Prolog']
|
||||
else
|
||||
Language['Perl']
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Extract the script name from the shebang line
|
||||
#
|
||||
# Requires Blob#data
|
||||
|
||||
Reference in New Issue
Block a user