diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 4c1bf295..837ba97b 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -25,6 +25,9 @@ module Linguist if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) } result = disambiguate_cl(data, languages) end + if languages.all? { |l| ["Scala", "SuperCollider"].include?(l) } + result = disambiguate_sc(data, languages) + end return result end end @@ -88,6 +91,17 @@ module Linguist matches end + def self.disambiguate_sc(data, languages) + matches = [] + if (/\^(this|super)\./.match(data) or /^\s*(\+|\*)\s*\w+\s*{/.match(data) or /^\s*~\w+\s*=\./.match(data)) + matches << Language["SuperCollider"] + end + if (/^\s*import (scala|java)\./.match(data) or /^\s*val\s+\w+\s*=/.match(data) or /^\s*class\b/.match(data)) + matches << Language["Scala"] + end + matches + end + def self.active? !!ACTIVE end diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index 55fb5331..5a0e9735 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -98,4 +98,16 @@ class TestHeuristcs < Test::Unit::TestCase end end end + + def test_sc_supercollider_by_heuristics + languages = ["Scala", "SuperCollider"] + results = Heuristics.disambiguate_sc(fixture("SuperCollider/WarpPreset.sc"), languages) + assert_equal Language["SuperCollider"], results.first + end + + def test_sc_scala_by_heuristics + languages = ["Scala", "SuperCollider"] + results = Heuristics.disambiguate_sc(fixture("Scala/node11.sc"), languages) + assert_equal Language["Scala"], results.first + end end