mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-07 20:08:48 +00:00
Guess if .r is R or REBOL
.r is the default extension used widely for both, R and REBOL. This patch attempts to guess if .r is a REBOL file by looking for the following very common REBOL code fragments: - `REBOL` - `: func [` - `make object! [` - `context [` If any of those is found in a .r file, it is identified as a REBOL file. Otherwise the language for a .r file is R. Signed-off-by: Andreas Bolka <a@bolka.at>
This commit is contained in:
@@ -259,6 +259,9 @@ module Linguist
|
||||
# If its a header file (.h) try to guess the language
|
||||
header_language ||
|
||||
|
||||
# If it's a .r file, try to guess the language
|
||||
r_language ||
|
||||
|
||||
# See if there is a Language for the extension
|
||||
pathname.language ||
|
||||
|
||||
@@ -288,6 +291,19 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Guess language of .r files.
|
||||
#
|
||||
# Returns a Language.
|
||||
def r_language
|
||||
return unless extname == '.r'
|
||||
|
||||
if lines.grep(/(rebol|(:\s+func|make\s+object!|^\s*context)\s*\[)/i).any?
|
||||
Language['Rebol']
|
||||
else
|
||||
Language['R']
|
||||
end
|
||||
end
|
||||
|
||||
# Internal: Extract the script name from the shebang line
|
||||
#
|
||||
# Requires Blob#data
|
||||
|
||||
Reference in New Issue
Block a user