Merge branch 'master' into cache-bustin

Conflicts:
	lib/linguist/version.rb
This commit is contained in:
Arfon Smith
2014-10-14 19:45:09 -05:00
5 changed files with 104 additions and 1 deletions

View File

@@ -165,7 +165,7 @@ If you are the current maintainer of this gem:
0. Ensure that tests are green: `bundle exec rake test`
0. Bump gem version in `lib/linguist/version.rb`. For example, [like this](https://github.com/github/linguist/commit/8d2ea90a5ba3b2fe6e1508b7155aa4632eea2985).
0. Make a PR to github/linguist. For example, [#1238](https://github.com/github/linguist/pull/1238).
0. Build a local gem: `gem build github-linguist.gemspec`
0. Build a local gem: `bundle exec rake build_gem`
0. Testing:
0. Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem
0. Install the new gem locally

View File

@@ -19,6 +19,9 @@ module Linguist
if languages.all? { |l| ["ECL", "Prolog"].include?(l) }
result = disambiguate_ecl(data, languages)
end
if languages.all? { |l| ["IDL", "Prolog"].include?(l) }
result = disambiguate_pro(data, languages)
end
if languages.all? { |l| ["Common Lisp", "OpenCL"].include?(l) }
result = disambiguate_cl(data, languages)
end
@@ -51,6 +54,16 @@ module Linguist
matches
end
def self.disambiguate_pro(data, languages)
matches = []
if (data.include?(":-"))
matches << Language["Prolog"]
else
matches << Language["IDL"]
end
matches
end
def self.disambiguate_ts(data, languages)
matches = []
if (data.include?("</translation>"))

View File

@@ -949,6 +949,7 @@ HTML:
HTML+Django:
type: markup
tm_scope: text.html.django
group: HTML
lexer: HTML+Django/Jinja
extensions:
@@ -957,6 +958,7 @@ HTML+Django:
HTML+ERB:
type: markup
tm_scope: text.html.erb
group: HTML
lexer: RHTML
aliases:
@@ -967,6 +969,7 @@ HTML+ERB:
HTML+PHP:
type: markup
tm_scope: text.html.php
group: HTML
extensions:
- .phtml
@@ -1102,6 +1105,7 @@ J:
JSON:
type: data
tm_scope: source.json
group: JavaScript
ace_mode: json
searchable: false
@@ -1293,6 +1297,7 @@ Literate Agda:
Literate CoffeeScript:
type: programming
tm_scope: source.litcoffee
group: CoffeeScript
lexer: Text only
ace_mode: markdown
@@ -1587,6 +1592,7 @@ Objective-C:
Objective-C++:
type: programming
tm_scope: source.objc++
color: "#4886FC"
aliases:
- obj-c++
@@ -1829,6 +1835,7 @@ Prolog:
extensions:
- .pl
- .ecl
- .pro
- .prolog
Propeller Spin:
@@ -2083,6 +2090,7 @@ SAS:
SCSS:
type: markup
tm_scope: source.scss
group: CSS
ace_mode: scss
extensions:
@@ -2123,6 +2131,7 @@ Sage:
Sass:
type: markup
tm_scope: source.sass
group: CSS
extensions:
- .sass
@@ -2597,6 +2606,7 @@ Xtend:
YAML:
type: data
tm_scope: source.yaml
aliases:
- yml
extensions:

View File

@@ -0,0 +1,68 @@
/**
* Question 1.1
* combiner(+Buddies, -Pairs)
*/
combiner([], []).
combiner([First|Buddies], Pairs):-
make_pairs(First, Buddies, Pairs1),
combiner(Buddies, Pairs2),
concat(Pairs1, Pairs2, Pairs).
/**
* make_pairs(+Buddy, +Buddies, -Pairs)
*/
make_pairs(Buddy, [], []).
make_pairs(Buddy, [First|Buddies], [(Buddy, First)|Pairs]):-
make_pairs(Buddy, Buddies, Pairs).
/**
* concat(+X, +Y, ?T)
*/
concat([], Y, Y).
concat([P|R], Y, [P|T]):-
concat(R, Y, T).
/**
* Question 1.2
* extraire(+AllPossiblePairs, +NbPairs, -Tp, -RemainingPairs)
*/
extraire(AllPossiblePairs, 0, [], AllPossiblePairs).
extraire([PossiblePair|AllPossiblePairs], NbPairs, [PossiblePair|Tp], NewRemainingPairs):-
NbPairs > 0,
NewNbPairs is NbPairs - 1,
extraire(AllPossiblePairs, NewNbPairs, Tp, RemainingPairs),
not(pair_in_array(PossiblePair, Tp)),
delete_pair(RemainingPairs, PossiblePair, NewRemainingPairs).
extraire([PossiblePair|AllPossiblePairs], NbPairs, Tp, [PossiblePair|RemainingPairs]):-
NbPairs > 0,
extraire(AllPossiblePairs, NbPairs, Tp, RemainingPairs),
pair_in_array(PossiblePair, Tp).
/**
* delete_pair(+Pairs, +Pair, -PairsWithoutPair)
*/
delete_pair([], _, []).
delete_pair([Pair|Pairs], Pair, Pairs):-!.
delete_pair([FirstPair|Pairs], Pair, [FirstPair|PairsWithoutPair]):-
delete_pair(Pairs, Pair, PairsWithoutPair).
/**
* pair_in_array(+Pair, +Pairs)
*/
pair_in_array((A, B), [(C, D)|Pairs]):-
(A == C ; B == D ; A == D ; B == C),
!.
pair_in_array(Pair, [FirstPair|Pairs]):-
pair_in_array(Pair, Pairs).
/**
* Question 1.3
* les_tps(+Buddies, -Tps)
*/
les_tps(Buddies, Tps):-
combiner(Buddies, PossiblePairs),
length(Buddies, NbBuddies),
NbPairs is integer(NbBuddies / 2),
findall(Tp, extraire(PossiblePairs, NbPairs, Tp, _), Tps).

View File

@@ -65,6 +65,18 @@ class TestHeuristcs < Test::Unit::TestCase
assert_equal Language["ECL"], results.first
end
def test_pro_prolog_by_heuristics
languages = ["IDL", "Prolog"]
results = Heuristics.disambiguate_pro(fixture("Prolog/logic-problem.pro"), languages)
assert_equal Language["Prolog"], results.first
end
def test_pro_idl_by_heuristics
languages = ["IDL", "Prolog"]
results = Heuristics.disambiguate_pro(fixture("IDL/mg_acosh.pro"), languages)
assert_equal Language["IDL"], results.first
end
def test_ts_typescript_by_heuristics
languages = ["TypeScript", "XML"]
results = Heuristics.disambiguate_ts(fixture("TypeScript/classes.ts"), languages)