From 1bd935b2b47db75e89e357ba8e344b4dd3308cf6 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 10 Nov 2014 11:43:30 +0100 Subject: [PATCH 1/5] Set 'lexer: GAP' for GAP My Pygments patch adding support for GAP was merged in April, and I verified that it is live on GitHub. --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 4d36d8d0..44ce9e64 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -817,6 +817,7 @@ GAMS: GAP: type: programming + lexer: GAP extensions: - .g - .gap From 6072a63f9952f8cada8e538ece4aac83d0692b0c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 10 Nov 2014 11:43:30 +0100 Subject: [PATCH 2/5] Add GAP .tst extension plus two sample files --- lib/linguist/languages.yml | 1 + samples/GAP/bugfix.tst | 161 +++++++++++++++++++++++++++++++++++++ samples/GAP/factor.tst | 21 +++++ 3 files changed, 183 insertions(+) create mode 100644 samples/GAP/bugfix.tst create mode 100644 samples/GAP/factor.tst diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 44ce9e64..b8192c26 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -823,6 +823,7 @@ GAP: - .gap - .gd - .gi + - .tst GAS: type: programming diff --git a/samples/GAP/bugfix.tst b/samples/GAP/bugfix.tst new file mode 100644 index 00000000..be4bd975 --- /dev/null +++ b/samples/GAP/bugfix.tst @@ -0,0 +1,161 @@ +gap> START_TEST("Test for various former bugs"); + + +gap> # The following used to trigger an error starting with: +gap> # "SolutionMat: matrix and vector incompatible called from" +gap> K:=AbelianPcpGroup([3,3,3]);; +gap> A:=Subgroup(K,[K.1]);; +gap> cr:=CRRecordBySubgroup(K,A);; +gap> ExtensionsCR(cr);; + + +# Comparing homomorphisms used to be broken +gap> K:=AbelianPcpGroup(1,[3]);; +gap> hom1:=GroupHomomorphismByImages(K,K,[K.1],[K.1]);; +gap> hom2:=GroupHomomorphismByImages(K,K,[K.1^2],[K.1^2]);; +gap> hom1=hom2; +true +gap> hom1=IdentityMapping(K); +true +gap> hom2=IdentityMapping(K); +true + + +gap> # The following incorrectly triggered an error at some point +gap> IsTorsionFree(ExamplesOfSomePcpGroups(5)); +true + + +gap> # Verify IsGeneratorsOfMagmaWithInverses warnings are silenced +gap> IsGeneratorsOfMagmaWithInverses(GeneratorsOfGroup(ExamplesOfSomePcpGroups(5))); +true + + +gap> # Check for a bug reported 2012-01-19 by Robert Morse +gap> g := PcGroupToPcpGroup(SmallGroup(48,1)); +Pcp-group with orders [ 2, 2, 2, 2, 3 ] +gap> # The next two commands used to trigger errors +gap> NonAbelianTensorSquare(Centre(g)); +Pcp-group with orders [ 8 ] +gap> NonAbelianExteriorSquare(Centre(g)); +Pcp-group with orders [ ] + + +gap> # Check for a bug reported 2012-01-19 by Robert Morse +gap> F := FreeGroup("x","y"); + +gap> x := F.1;; y := F.2;; +gap> G := F/[x^2/y^24, y^24, y^x/y^23]; + +gap> iso := IsomorphismPcGroup(G); +[ x, y ] -> [ f1, f2*f5 ] +gap> iso1 := IsomorphismPcpGroup(Image(iso)); +[ f1, f2, f3, f4, f5 ] -> [ g1, g2, g3, g4, g5 ] +gap> G := Image(iso*iso1); +Pcp-group with orders [ 2, 2, 2, 2, 3 ] +gap> # The next command used to trigger an error +gap> NonAbelianTensorSquare(Image(iso*iso1)); +Pcp-group with orders [ 2, 2, 3, 2, 2, 2, 2 ] + + +gap> # The problem with the previous example is/was that Igs(G) +gap> # is set to a non-standard value: +gap> Igs(G); +[ g1, g2*g5, g3*g4*g5^2, g4*g5, g5 ] +gap> # Unfortunately, it seems that a lot of code that +gap> # really should be using Ngs or Cgs is using Igs incorrectly. +gap> # For example, direct products could return *invalid* embeddings: +gap> D := DirectProduct(G, G); +Pcp-group with orders [ 2, 2, 2, 2, 3, 2, 2, 2, 2, 3 ] +gap> hom:=Embedding(D,1);; +gap> mapi:=MappingGeneratorsImages(hom);; +gap> GroupHomomorphismByImages(Source(hom),Range(hom),mapi[1],mapi[2]) <> fail; +true +gap> hom:=Projection(D,1);; +gap> mapi:=MappingGeneratorsImages(hom);; +gap> GroupHomomorphismByImages(Source(hom),Range(hom),mapi[1],mapi[2]) <> fail; +true + + +gap> # Check for bug computing Schur extension of infinite cyclic groups, +gap> # found by Max Horn 2012-05-25 +gap> G:=AbelianPcpGroup(1,[0]); +Pcp-group with orders [ 0 ] +gap> # The next command used to trigger an error +gap> SchurExtension(G); +Pcp-group with orders [ 0 ] + + +gap> # Check for bug computing Schur extensions of subgroups, found by MH 2012-05-25. +gap> G:=HeisenbergPcpGroup(2); +Pcp-group with orders [ 0, 0, 0, 0, 0 ] +gap> H:=Subgroup(G,[G.2^3*G.3^2, G.1^9]); +Pcp-group with orders [ 0, 0, 0 ] +gap> # The next command used to trigger an error +gap> SchurExtension(H); +Pcp-group with orders [ 0, 0, 0, 0, 0, 0 ] + + +gap> # Check for bug computing Schur extensions of subgroups, found by MH 2012-05-25. +gap> G:=HeisenbergPcpGroup(2); +Pcp-group with orders [ 0, 0, 0, 0, 0 ] +gap> H:=Subgroup(G,[G.1, G.2]); +Pcp-group with orders [ 0, 0 ] +gap> # The next command used to trigger an error +gap> SchurExtension(H); +Pcp-group with orders [ 0, 0, 0 ] + + +gap> # Check for bug computing normalizer of two subgroups, found by MH 2012-05-30. +gap> # The problem was caused by incorrect resp. overly restrictive use of Parent(). +gap> G:=HeisenbergPcpGroup(2); +Pcp-group with orders [ 0, 0, 0, 0, 0 ] +gap> A:=Subgroup(Subgroup(G,[G.2,G.3,G.4,G.5]), [G.3]); +Pcp-group with orders [ 0 ] +gap> B:=Subgroup(Subgroup(G,[G.1,G.4,G.5]), [G.4]); +Pcp-group with orders [ 0 ] +gap> Normalizer(A,B); +Pcp-group with orders [ 0 ] +gap> # The following used to trigger the error "arguments must have a common parent group" +gap> Normalizer(B,A); +Pcp-group with orders [ 0 ] + + +gap> # In polycyclic 2.9 and 2.10, the code for 2-cohomology computations was broken. +gap> G := UnitriangularPcpGroup(3,0); +Pcp-group with orders [ 0, 0, 0 ] +gap> mats := G!.mats; +[ [ [ 1, 1, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ], + [ [ 1, 0, 0 ], [ 0, 1, 1 ], [ 0, 0, 1 ] ], + [ [ 1, 0, 1 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ] ] +gap> C := CRRecordByMats(G,mats);; +gap> cc := TwoCohomologyCR(C);; +gap> cc.factor.rels; +[ 2, 0, 0 ] +gap> c := cc.factor.prei[2]; +[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 1 ] +gap> cc.gcb; +[ [ 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + [ 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0 ], + [ 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1 ], + [ -1, 0, 1, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ], + [ 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 1 ] ] +gap> cc.gcc; +[ [ 1, 0, 0, 0, 0, -2, -1, 0, 1, 1, -1, -1, 0, 0, 0, 0, 0, 0 ], + [ 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0 ], + [ 0, 0, 1, 0, 0, -2, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0 ], + [ 0, 0, 0, 1, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ], + [ 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0 ], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 1 ], + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1 ] ] + + +gap> # LowerCentralSeriesOfGroup for non-nilpotent pcp-groups used to trigger +gap> # an infinite recursion +gap> G := PcGroupToPcpGroup(SmallGroup(6,1)); +Pcp-group with orders [ 2, 3 ] +gap> LowerCentralSeriesOfGroup(G); +[ Pcp-group with orders [ 2, 3 ], Pcp-group with orders [ 3 ] ] + + +gap> STOP_TEST( "bugfix.tst", 10000000); diff --git a/samples/GAP/factor.tst b/samples/GAP/factor.tst new file mode 100644 index 00000000..115fe921 --- /dev/null +++ b/samples/GAP/factor.tst @@ -0,0 +1,21 @@ +gap> START_TEST("Test of factor groups and natural homomorphisms"); + +gap> G:=HeisenbergPcpGroup(2); +Pcp-group with orders [ 0, 0, 0, 0, 0 ] + +gap> H:=Subgroup(G,[G.2,G.3,G.4,G.5]); +gap> K:=G/H; +gap> NaturalHomomorphism(K); + +gap> A:=Subgroup(H, [G.3]); +Pcp-group with orders [ 0 ] +gap> B:=Subgroup(Subgroup(G,[G.1,G.4,G.5]), [G.4]); +Pcp-group with orders [ 0 ] +gap> Normalizer(A,B); +Pcp-group with orders [ 0 ] +gap> # The following used to trigger the error "arguments must have a common parent group" +gap> Normalizer(B,A); +Pcp-group with orders [ 0 ] + + +gap> STOP_TEST( "factor.tst", 10000000); From ff6a10698ea5026f92285673c9761311a2d4c449 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 10 Nov 2014 11:43:30 +0100 Subject: [PATCH 3/5] Pass name of file being analyzed to find_by_heuristics Some languages are sensitive to file names in the sense that different kinds of files contain somewhat different data. Example: GAP .tst files contain test cases, which add some extra data compared to regular code, and as a consequence are not directly interchangeable with regular source code. Heuristics may need to take this into account, thus may need to know the name of the file being analyzed. --- lib/linguist/heuristics.rb | 3 ++- lib/linguist/language.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 13f0173f..53bb10a9 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -7,11 +7,12 @@ module Linguist # apply heuristics against the given data and return an array # of matching languages, or nil. # + # name - Name of the file the data is coming from. # data - Array of tokens or String data to analyze. # languages - Array of language name Strings to restrict to. # # Returns an array of Languages or [] - def self.find_by_heuristics(data, languages) + def self.find_by_heuristics(name, data, languages) if active? result = [] diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index f4c7a62e..444c925c 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -120,7 +120,7 @@ module Linguist if possible_languages.length > 1 data = blob.data possible_language_names = possible_languages.map(&:name) - heuristic_languages = Heuristics.find_by_heuristics(data, possible_language_names) + heuristic_languages = Heuristics.find_by_heuristics(name, data, possible_language_names) if heuristic_languages.size > 1 possible_language_names = heuristic_languages.map(&:name) From f9ad5dda568ba2f476008de6f8fb0ba25622e3d5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 10 Nov 2014 11:43:30 +0100 Subject: [PATCH 4/5] Add heuristic distinguishing GAP and Scilab .tst files --- lib/linguist/heuristics.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 53bb10a9..d6c097ce 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -40,6 +40,9 @@ module Linguist if languages.all? { |l| ["FORTRAN", "Forth"].include?(l) } result = disambiguate_f(data) end + if name.end_with? ".tst" and languages.all? { |l| ["GAP", "Scilab"].include?(l) } + result = disambiguate_tst(data) + end return result end end @@ -98,6 +101,16 @@ module Linguist matches end + def self.disambiguate_tst(data) + matches = [] + if (data.include?("gap> ")) + matches << Language["GAP"] + else + matches << Language["Scilab"] + end + matches + end + def self.disambiguate_cl(data) matches = [] if data.include?("(defun ") From 97d48a204ab68e44e66591e3dd771cbc319675ff Mon Sep 17 00:00:00 2001 From: Chow Loong Jin Date: Fri, 23 Jan 2015 14:14:15 +0800 Subject: [PATCH 5/5] Specify ace_mode for OpenSCAD --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index af0472c8..5f2d806b 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2055,7 +2055,7 @@ OpenSCAD: extensions: - .scad tm_scope: none - ace_mode: text + ace_mode: scad Org: type: prose