mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-04 08:25:34 +00:00
Merge pull request #20 from earl/disambiguate-r
Guess if .r is R or REBOL
This commit is contained in:
@@ -259,6 +259,9 @@ module Linguist
|
|||||||
# If its a header file (.h) try to guess the language
|
# If its a header file (.h) try to guess the language
|
||||||
header_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
|
# See if there is a Language for the extension
|
||||||
pathname.language ||
|
pathname.language ||
|
||||||
|
|
||||||
@@ -288,6 +291,19 @@ module Linguist
|
|||||||
end
|
end
|
||||||
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
|
# Internal: Extract the script name from the shebang line
|
||||||
#
|
#
|
||||||
# Requires Blob#data
|
# Requires Blob#data
|
||||||
|
|||||||
4
test/fixtures/hello-r.R
vendored
Normal file
4
test/fixtures/hello-r.R
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
hello <- function() {
|
||||||
|
print("hello, world!")
|
||||||
|
}
|
||||||
|
hello()
|
||||||
5
test/fixtures/hello-rebol.r
vendored
Normal file
5
test/fixtures/hello-rebol.r
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
REBOL []
|
||||||
|
hello: func [] [
|
||||||
|
print "hello, world!"
|
||||||
|
]
|
||||||
|
hello
|
||||||
@@ -224,6 +224,10 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal Language['Ruby'], blob("wrong_shebang.rb").language
|
assert_equal Language['Ruby'], blob("wrong_shebang.rb").language
|
||||||
assert_nil blob("octocat.png").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
|
# ML
|
||||||
assert_equal Language['OCaml'], blob("Foo.ml").language
|
assert_equal Language['OCaml'], blob("Foo.ml").language
|
||||||
assert_equal Language['Standard ML'], blob("Foo.sig").language
|
assert_equal Language['Standard ML'], blob("Foo.sig").language
|
||||||
|
|||||||
Reference in New Issue
Block a user