mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'Open-Turing-Project-detect-turing-language'
This commit is contained in:
@@ -468,6 +468,28 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Internal: Guess language of .t files.
|
||||||
|
#
|
||||||
|
# Returns a Language.
|
||||||
|
def guess_t_language
|
||||||
|
score = 0
|
||||||
|
score += 1 if lines.grep(/^% /).any?
|
||||||
|
score += data.gsub(/ := /).count
|
||||||
|
score += data.gsub(/proc |procedure |fcn |function /).count
|
||||||
|
score += data.gsub(/var \w+: \w+/).count
|
||||||
|
|
||||||
|
# Tell-tale signs its gotta be Perl
|
||||||
|
if lines.grep(/^(my )?(sub |\$|@|%)\w+/).any?
|
||||||
|
score = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if score >= 3
|
||||||
|
Language['Turing']
|
||||||
|
else
|
||||||
|
Language['Perl']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Internal: Guess language of .gsp files.
|
# Internal: Guess language of .gsp files.
|
||||||
#
|
#
|
||||||
# Returns a Language.
|
# Returns a Language.
|
||||||
|
|||||||
@@ -723,6 +723,7 @@ Perl:
|
|||||||
type: programming
|
type: programming
|
||||||
overrides:
|
overrides:
|
||||||
- .pl
|
- .pl
|
||||||
|
- .t
|
||||||
primary_extension: .pl
|
primary_extension: .pl
|
||||||
extensions:
|
extensions:
|
||||||
- .PL
|
- .PL
|
||||||
@@ -972,6 +973,14 @@ Textile:
|
|||||||
extensions:
|
extensions:
|
||||||
- .textile
|
- .textile
|
||||||
|
|
||||||
|
Turing:
|
||||||
|
type: programming
|
||||||
|
lexer: Text only
|
||||||
|
primary_extension: .t
|
||||||
|
extensions:
|
||||||
|
- .t
|
||||||
|
- .tu
|
||||||
|
|
||||||
Twig:
|
Twig:
|
||||||
type: markup
|
type: markup
|
||||||
group: PHP
|
group: PHP
|
||||||
|
|||||||
10
test/fixtures/perl-test.t
vendored
Normal file
10
test/fixtures/perl-test.t
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Foo::Bar
|
||||||
|
|
||||||
|
$n = 42;
|
||||||
|
$name = "world";
|
||||||
|
@array = ("1","2","3");
|
||||||
|
%hash = ("foo":"bar");
|
||||||
|
my $name = "josh";
|
||||||
19
test/fixtures/turing.t
vendored
Normal file
19
test/fixtures/turing.t
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
% Accepts a number and calculates its factorial
|
||||||
|
|
||||||
|
function factorial (n: int) : real
|
||||||
|
if n = 0 then
|
||||||
|
result 1
|
||||||
|
else
|
||||||
|
result n * factorial (n - 1)
|
||||||
|
end if
|
||||||
|
end factorial
|
||||||
|
|
||||||
|
var n: int
|
||||||
|
loop
|
||||||
|
put "Please input an integer: " ..
|
||||||
|
get n
|
||||||
|
exit when n >= 0
|
||||||
|
put "Input must be a non-negative integer."
|
||||||
|
end loop
|
||||||
|
|
||||||
|
put "The factorial of ", n, " is ", factorial (n)
|
||||||
@@ -281,6 +281,10 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal Language['R'], blob("hello-r.R").language
|
assert_equal Language['R'], blob("hello-r.R").language
|
||||||
assert_equal Language['Rebol'], blob("hello-rebol.r").language
|
assert_equal Language['Rebol'], blob("hello-rebol.r").language
|
||||||
|
|
||||||
|
# .t disambiguation
|
||||||
|
assert_equal Language['Perl'], blob("perl-test.t").language
|
||||||
|
assert_equal Language['Turing'], blob("turing.t").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
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ class TestLanguage < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert Language.ambiguous?('.r')
|
assert Language.ambiguous?('.r')
|
||||||
assert_equal Language['R'], Language.find_by_extension('r')
|
assert_equal Language['R'], Language.find_by_extension('r')
|
||||||
|
|
||||||
|
assert Language.ambiguous?('.t')
|
||||||
|
assert_equal Language['Perl'], Language.find_by_extension('t')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lexer
|
def test_lexer
|
||||||
|
|||||||
Reference in New Issue
Block a user