aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/linguist/blob_helper.rb16
-rw-r--r--test/fixtures/hello-r.R4
-rw-r--r--test/fixtures/hello-rebol.r5
-rw-r--r--test/test_blob.rb4
4 files changed, 29 insertions, 0 deletions
diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb
index 844ac03..97b6fa0 100644
--- a/lib/linguist/blob_helper.rb
+++ b/lib/linguist/blob_helper.rb
@@ -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
diff --git a/test/fixtures/hello-r.R b/test/fixtures/hello-r.R
new file mode 100644
index 0000000..30d715c
--- /dev/null
+++ b/test/fixtures/hello-r.R
@@ -0,0 +1,4 @@
+hello <- function() {
+ print("hello, world!")
+}
+hello()
diff --git a/test/fixtures/hello-rebol.r b/test/fixtures/hello-rebol.r
new file mode 100644
index 0000000..4c1b798
--- /dev/null
+++ b/test/fixtures/hello-rebol.r
@@ -0,0 +1,5 @@
+REBOL []
+hello: func [] [
+ print "hello, world!"
+]
+hello
diff --git a/test/test_blob.rb b/test/test_blob.rb
index 6284459..bcc63a9 100644
--- a/test/test_blob.rb
+++ b/test/test_blob.rb
@@ -224,6 +224,10 @@ class TestBlob < Test::Unit::TestCase
assert_equal Language['Ruby'], blob("wrong_shebang.rb").language
assert_nil blob("octocat.png").language
+ # .r disambiguation
+ assert_equal Language['R'], blob("hello-r.R").language
+ assert_equal Language['Rebol'], blob("hello-rebol.r").language
+
# ML
assert_equal Language['OCaml'], blob("Foo.ml").language
assert_equal Language['Standard ML'], blob("Foo.sig").language