diff options
| author | Joshua Peek <josh@joshpeek.com> | 2011-06-28 21:26:24 -0700 |
|---|---|---|
| committer | Joshua Peek <josh@joshpeek.com> | 2011-06-28 21:26:24 -0700 |
| commit | 302f8763b7e94faf51d306cde9be925986aed680 (patch) | |
| tree | aa90e13aa882f5b50e132b596a59062e9eefdbbf | |
| parent | 521bb9b9b249c2b8d8f8fe3855fc30f368814fea (diff) | |
| parent | 2707d1db67ed782a0e523679fa960d65a20c6a78 (diff) | |
Merge pull request #20 from earl/disambiguate-r
Guess if .r is R or REBOL
| -rw-r--r-- | lib/linguist/blob_helper.rb | 16 | ||||
| -rw-r--r-- | test/fixtures/hello-r.R | 4 | ||||
| -rw-r--r-- | test/fixtures/hello-rebol.r | 5 | ||||
| -rw-r--r-- | test/test_blob.rb | 4 |
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 |
