mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add Forth extensions .f and .for; add heuristics for Forth and FORTRAN.
This commit is contained in:
@@ -36,6 +36,9 @@ module Linguist
|
|||||||
if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) }
|
if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) }
|
||||||
result = disambiguate_asc(data)
|
result = disambiguate_asc(data)
|
||||||
end
|
end
|
||||||
|
if languages.all? { |l| ["FORTRAN", "Forth"].include?(l) }
|
||||||
|
result = disambiguate_f(data)
|
||||||
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -138,6 +141,16 @@ module Linguist
|
|||||||
matches
|
matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.disambiguate_f(data)
|
||||||
|
matches = []
|
||||||
|
if /^: /.match(data)
|
||||||
|
matches << Language["Forth"]
|
||||||
|
elsif /^([c*][^a-z]| subroutine\s)/i.match(data)
|
||||||
|
matches << Language["FORTRAN"]
|
||||||
|
end
|
||||||
|
matches
|
||||||
|
end
|
||||||
|
|
||||||
def self.active?
|
def self.active?
|
||||||
!!ACTIVE
|
!!ACTIVE
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -792,6 +792,9 @@ Forth:
|
|||||||
extensions:
|
extensions:
|
||||||
- .fth
|
- .fth
|
||||||
- .4th
|
- .4th
|
||||||
|
- .F
|
||||||
|
- .f
|
||||||
|
- .for
|
||||||
- .forth
|
- .forth
|
||||||
- .frt
|
- .frt
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,16 @@ class TestHeuristcs < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_f_by_heuristics
|
||||||
|
languages = ["FORTRAN", "Forth"]
|
||||||
|
languages.each do |language|
|
||||||
|
all_fixtures(language).each do |fixture|
|
||||||
|
results = Heuristics.disambiguate_f(fixture("#{language}/#{File.basename(fixture)}"))
|
||||||
|
assert_equal Language[language], results.first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Candidate languages = ["Hack", "PHP"]
|
# Candidate languages = ["Hack", "PHP"]
|
||||||
def test_hack_by_heuristics
|
def test_hack_by_heuristics
|
||||||
results = Heuristics.disambiguate_hack(fixture("Hack/funs.php"))
|
results = Heuristics.disambiguate_hack(fixture("Hack/funs.php"))
|
||||||
|
|||||||
Reference in New Issue
Block a user