From c6e891562754dc29c95f3ce9f060f60b3b9b42b2 Mon Sep 17 00:00:00 2001 From: halirutan Date: Fri, 23 Jan 2015 04:40:47 +0100 Subject: [PATCH 01/66] Added Wolfram Language extensions to the Mathematica section. I checked whether other languages have the same extensions I indroduced which is not the case. Added a sample .wlt file for a Wolfram Unit Test --- lib/linguist/languages.yml | 3 +++ samples/Mathematica/UnitTest.wlt | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 samples/Mathematica/UnitTest.wlt diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index af0472c8..e8b5b195 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1761,6 +1761,9 @@ Mathematica: - .ma - .nb - .nbp + - .wl + - .mt + - .wlt aliases: - mma ace_mode: text diff --git a/samples/Mathematica/UnitTest.wlt b/samples/Mathematica/UnitTest.wlt new file mode 100644 index 00000000..21e67951 --- /dev/null +++ b/samples/Mathematica/UnitTest.wlt @@ -0,0 +1,17 @@ +BeginTestSection["Untitled-5"] + +VerificationTest[(* 1 *) + RotationMatrix[phi] + , + List[List[Cos[phi], Times[-1, Sin[phi]]], List[Sin[phi], Cos[phi]]] +] + +VerificationTest[(* 2 *) + Times[1, Power[Plus[a, Times[-1, a]], -1]] + , + ComplexInfinity + , + {Power::infy} +] + +EndTestSection[] From e468723abc78d7aa00f6422e78ffa550701ab9e2 Mon Sep 17 00:00:00 2001 From: halirutan Date: Sat, 24 Jan 2015 01:00:41 +0100 Subject: [PATCH 02/66] Reordered the extensions entries for Mathematica Added examples for newly introduces file extensions --- lib/linguist/languages.yml | 2 +- samples/Mathematica/Predicates.wl | 150 ++++++++++++++++++++++++++++++ samples/Mathematica/UnitTest.mt | 17 ++++ 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 samples/Mathematica/Predicates.wl create mode 100644 samples/Mathematica/UnitTest.mt diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 653c4d0d..93d35b00 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1761,10 +1761,10 @@ Mathematica: - .cdf - .m - .ma + - .mt - .nb - .nbp - .wl - - .mt - .wlt aliases: - mma diff --git a/samples/Mathematica/Predicates.wl b/samples/Mathematica/Predicates.wl new file mode 100644 index 00000000..3c569691 --- /dev/null +++ b/samples/Mathematica/Predicates.wl @@ -0,0 +1,150 @@ +(* ::Package:: *) + +BeginPackage["Predicates`"]; + + +(* ::Title:: *) +(*Predicates*) + + +(* ::Section::Closed:: *) +(*Fuzzy Logic*) + + +(* ::Subsection:: *) +(*Documentation*) + + +PossiblyTrueQ::usage="Returns True if the argument is not definitely False."; +PossiblyFalseQ::usage="Returns True if the argument is not definitely True."; +PossiblyNonzeroQ::usage="Returns True if and only if its argument is not definitely zero."; + + +(* ::Subsection:: *) +(*Implimentation*) + + +Begin["`Private`"]; + + +PossiblyTrueQ[expr_]:=\[Not]TrueQ[\[Not]expr] + + +PossiblyFalseQ[expr_]:=\[Not]TrueQ[expr] + + +End[]; + + +(* ::Section::Closed:: *) +(*Numbers and Lists*) + + +(* ::Subsection:: *) +(*Documentation*) + + +AnyQ::usage="Given a predicate and a list, retuns True if and only if that predicate is True for at least one element of the list."; +AnyElementQ::usage="Returns True if cond matches any element of L."; +AllQ::usage="Given a predicate and a list, retuns True if and only if that predicate is True for all elements of the list."; +AllElementQ::usage="Returns True if cond matches any element of L."; + + +AnyNonzeroQ::usage="Returns True if L is a list such that at least one element is definitely not zero."; +AnyPossiblyNonzeroQ::usage="Returns True if expr is a list such that at least one element is not definitely zero."; + + +RealQ::usage="Returns True if and only if the argument is a real number"; +PositiveQ::usage="Returns True if and only if the argument is a positive real number"; +NonnegativeQ::usage="Returns True if and only if the argument is a non-negative real number"; +PositiveIntegerQ::usage="Returns True if and only if the argument is a positive integer"; +NonnegativeIntegerQ::usage="Returns True if and only if the argument is a non-negative integer"; + + +IntegerListQ::usage="Returns True if and only if the input is a list of integers."; +PositiveIntegerListQ::usage="Returns True if and only if the input is a list of positive integers."; +NonnegativeIntegerListQ::usage="Returns True if and only if the input is a list of non-negative integers."; +IntegerOrListQ::usage="Returns True if and only if the input is a list of integers or an integer."; +PositiveIntegerOrListQ::usage="Returns True if and only if the input is a list of positive integers or a positive integer."; +NonnegativeIntegerOrListQ::usage="Returns True if and only if the input is a list of positive integers or a positive integer."; + + +SymbolQ::usage="Returns True if argument is an unassigned symbol."; +SymbolOrNumberQ::usage="Returns True if argument is a number of has head 'Symbol'"; + + +(* ::Subsection:: *) +(*Implimentation*) + + +Begin["`Private`"]; + + +AnyQ[cond_, L_] := Fold[Or, False, cond /@ L] + + +AnyElementQ[cond_,L_]:=AnyQ[cond,Flatten[L]] + + +AllQ[cond_, L_] := Fold[And, True, cond /@ L] + + +AllElementQ[cond_, L_] := Fold[And, True, cond /@ L] + + +AnyNonzeroQ[L_]:=AnyElementQ[#!=0&,L] + + +PossiblyNonzeroQ[expr_]:=PossiblyTrueQ[expr!=0] + + +AnyPossiblyNonzeroQ[expr_]:=AnyElementQ[PossiblyNonzeroQ,expr] + + +RealQ[n_]:=TrueQ[Im[n]==0]; + + +PositiveQ[n_]:=Positive[n]; + + +PositiveIntegerQ[n_]:=PositiveQ[n]\[And]IntegerQ[n]; + + +NonnegativeQ[n_]:=TrueQ[RealQ[n]&&n>=0]; + + +NonnegativeIntegerQ[n_]:=NonnegativeQ[n]\[And]IntegerQ[n]; + + +IntegerListQ[input_]:=ListQ[input]&&Not[MemberQ[IntegerQ/@input,False]]; + + +IntegerOrListQ[input_]:=IntegerListQ[input]||IntegerQ[input]; + + +PositiveIntegerListQ[input_]:=IntegerListQ[input]&&Not[MemberQ[Positive[input],False]]; + + +PositiveIntegerOrListQ[input_]:=PositiveIntegerListQ[input]||PositiveIntegerQ[input]; + + +NonnegativeIntegerListQ[input_]:=IntegerListQ[input]&&Not[MemberQ[NonnegativeIntegerQ[input],False]]; + + +NonnegativeIntegerOrListQ[input_]:=NonnegativeIntegerListQ[input]||NonnegativeIntegerQ[input]; + + +SymbolQ[a_]:=Head[a]===Symbol; + + +SymbolOrNumberQ[a_]:=NumericQ[a]||Head[a]===Symbol; + + +End[]; + + +(* ::Section:: *) +(*Epilogue*) + + +EndPackage[]; diff --git a/samples/Mathematica/UnitTest.mt b/samples/Mathematica/UnitTest.mt new file mode 100644 index 00000000..21e67951 --- /dev/null +++ b/samples/Mathematica/UnitTest.mt @@ -0,0 +1,17 @@ +BeginTestSection["Untitled-5"] + +VerificationTest[(* 1 *) + RotationMatrix[phi] + , + List[List[Cos[phi], Times[-1, Sin[phi]]], List[Sin[phi], Cos[phi]]] +] + +VerificationTest[(* 2 *) + Times[1, Power[Plus[a, Times[-1, a]], -1]] + , + ComplexInfinity + , + {Power::infy} +] + +EndTestSection[] From aa8eb955e9ded79f402d881402e219188433a38b Mon Sep 17 00:00:00 2001 From: halirutan Date: Mon, 26 Jan 2015 01:44:45 +0100 Subject: [PATCH 03/66] Removed .mt file extension and example since there are more languages that use this. --- lib/linguist/languages.yml | 1 - samples/Mathematica/UnitTest.mt | 17 ----------------- 2 files changed, 18 deletions(-) delete mode 100644 samples/Mathematica/UnitTest.mt diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 32568987..c610c220 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1761,7 +1761,6 @@ Mathematica: - .cdf - .m - .ma - - .mt - .nb - .nbp - .wl diff --git a/samples/Mathematica/UnitTest.mt b/samples/Mathematica/UnitTest.mt deleted file mode 100644 index 21e67951..00000000 --- a/samples/Mathematica/UnitTest.mt +++ /dev/null @@ -1,17 +0,0 @@ -BeginTestSection["Untitled-5"] - -VerificationTest[(* 1 *) - RotationMatrix[phi] - , - List[List[Cos[phi], Times[-1, Sin[phi]]], List[Sin[phi], Cos[phi]]] -] - -VerificationTest[(* 2 *) - Times[1, Power[Plus[a, Times[-1, a]], -1]] - , - ComplexInfinity - , - {Power::infy} -] - -EndTestSection[] From 3e54d6651caab999f8827c46d60889c27f02af93 Mon Sep 17 00:00:00 2001 From: David Pyke Le Brun Date: Fri, 6 Feb 2015 13:36:40 +0000 Subject: [PATCH 04/66] update of old PL/SQL PLpgSQL and SQLPL patch based on current version see [linguist] add support for oracle PLSQL (#1003) --- .gitmodules | 3 + grammars.yml | 2 + lib/linguist/heuristics.rb | 25 ++++ lib/linguist/languages.yml | 29 +++++ samples/PLSQL/myobject.sql | 15 +++ samples/PLSQL/packagebody.pkb | 58 +++++++++ samples/PLSQL/packageheader.pks | 28 +++++ samples/PLSQL/who_called_me.sql | 65 ++++++++++ samples/PLpgSQL/plpgsql_lint-8.4.sql | 165 ++++++++++++++++++++++++ samples/PLpgSQL/plpgsql_lint-9.0.sql | 165 ++++++++++++++++++++++++ samples/PLpgSQL/plpgsql_lint-9.1.sql | 179 +++++++++++++++++++++++++++ samples/PLpgSQL/plpgsql_lint-9.2.sql | 166 +++++++++++++++++++++++++ samples/PLpgSQL/plpgsql_lint-9.3.sql | 166 +++++++++++++++++++++++++ samples/SQL/create_stuff.sql | 21 ++++ samples/SQL/drop_stuff.sql | 13 ++ samples/SQL/dual.sql | 3 + samples/SQLPL/check_reorg.sql | 39 ++++++ samples/SQLPL/comm_amount.db2 | 30 +++++ samples/SQLPL/drop_table.db2 | 13 ++ samples/SQLPL/runstats.sql | 18 +++ samples/SQLPL/trigger.sql | 9 ++ vendor/grammars/Oracle | 1 + 22 files changed, 1213 insertions(+) create mode 100644 samples/PLSQL/myobject.sql create mode 100644 samples/PLSQL/packagebody.pkb create mode 100644 samples/PLSQL/packageheader.pks create mode 100644 samples/PLSQL/who_called_me.sql create mode 100644 samples/PLpgSQL/plpgsql_lint-8.4.sql create mode 100644 samples/PLpgSQL/plpgsql_lint-9.0.sql create mode 100644 samples/PLpgSQL/plpgsql_lint-9.1.sql create mode 100644 samples/PLpgSQL/plpgsql_lint-9.2.sql create mode 100644 samples/PLpgSQL/plpgsql_lint-9.3.sql create mode 100644 samples/SQL/create_stuff.sql create mode 100644 samples/SQL/drop_stuff.sql create mode 100644 samples/SQL/dual.sql create mode 100644 samples/SQLPL/check_reorg.sql create mode 100644 samples/SQLPL/comm_amount.db2 create mode 100644 samples/SQLPL/drop_table.db2 create mode 100644 samples/SQLPL/runstats.sql create mode 100644 samples/SQLPL/trigger.sql create mode 160000 vendor/grammars/Oracle diff --git a/.gitmodules b/.gitmodules index 4e72920d..aefae11d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -594,3 +594,6 @@ [submodule "vendor/grammars/ec.tmbundle"] path = vendor/grammars/ec.tmbundle url = https://github.com/ecere/ec.tmbundle +[submodule "vendor/grammars/Oracle"] + path = vendor/grammars/Oracle + url = git@github.com:mulander/oracle.tmbundle.git diff --git a/grammars.yml b/grammars.yml index 00f2c9b1..398c2a35 100644 --- a/grammars.yml +++ b/grammars.yml @@ -68,6 +68,8 @@ vendor/grammars/NimLime: - source.nim - source.nim_filter - source.nimcfg +vendor/grammars/Oracle/: +- source.plsql.oracle vendor/grammars/PHP-Twig.tmbundle: - text.html.twig vendor/grammars/RDoc.tmbundle: diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index ee1a3625..3d1899ec 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -223,5 +223,30 @@ module Linguist Language["Text"] end end + disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data| + match = nil + #unique keywords for each language + plpgsqlkeywords = [/^\\i\b/i, /begin ?(work|transaction)?;/i , /AS \$\$/i, /RAISE EXCEPTION/i, /LANGUAGE plpgsql\b/i ] + plsqlkeywords = [ /pragma\b/i , /constructor\W+function\b/i] + #sqlplkeywords = [ ] + + #common keywords that are not SQL + plkeywords = [/begin\b/i,/boolean\b/i, /package\b/i,/exception\b/i, /^end;\b/i ] + + re = Regexp.union(plpgsqlkeywords) + if data.match(re) + match = Language["PLpgSQL"] + else + re = Regexp.union(plsqlkeywords) + if data.match(re) + match= Language["PLSQL"] + else + re = Regexp.union(plkeywords) + match= Language["SQL"] if ! data.match(re) + end + end + + match + end end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index e899046e..d2133a5c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2145,6 +2145,26 @@ PHP: aliases: - inc +#Oracle +PLSQL: + type: programming + ace_mode: sql + tm_scope: Oracle + extensions: + - .pls + - .pkb + - .pks + - .plb + - .sql + +#Postgres +PLpgSQL: + type: programming + ace_mode: pgsql + tm_scope: source.sql + extensions: + - .sql + Pan: type: programming color: '#cc0000' @@ -2675,6 +2695,15 @@ SQL: - .udf - .viw +#IBM DB2 +#SQLPL: + #type: programming + #ace_mode: sql + #tm_scope: source.sql + #extensions: + #- .sql + #- .db2 + STON: type: data group: Smalltalk diff --git a/samples/PLSQL/myobject.sql b/samples/PLSQL/myobject.sql new file mode 100644 index 00000000..dd2a68aa --- /dev/null +++ b/samples/PLSQL/myobject.sql @@ -0,0 +1,15 @@ +create or replace type myobject +AUTHID DEFINER +AS OBJECT +( + m_name varchar2(200), + member function toString RETURN VARCHAR2, + map member function Compare return varchar2 + +) +not instantiable not final; +/ + +prompt create type myarray +create or replace type myarray as table of myobject; +/ diff --git a/samples/PLSQL/packagebody.pkb b/samples/PLSQL/packagebody.pkb new file mode 100644 index 00000000..e5e80d99 --- /dev/null +++ b/samples/PLSQL/packagebody.pkb @@ -0,0 +1,58 @@ +CREATE OR REPLACE PACKAGE BODY linguistpackage +AS + /* + * Package: linguist pacakage body + * Purpose: a sample PLSQL file for linguist to work with + * + * Date: 03/03/2014 + * Author: david pyke le brun + * Comments: initial version + */ + +PROCEDURE proc_1 +IS +BEGIN +NULL; +END; + +-- functions with 1 arg +FUNCTION function1( param1 VARCHAR2 ) RETURN VARCHAR2 +IS +CURSOR c IS +select * from dual; +v c%ROWTYPE; +BEGIN + open c; + fetch c into v; + close c; + + return v; +end; + +FUNCTION function2( param1 NUMBER ) RETURN DATE +IS +BEGIN + return SYSDATE; +end; + +--a few more to use all basic SQL types +FUNCTION function3( param1 TIMESTAMP ) RETURN CHAR +IS +BEGIN +IF 1 = 2 THEN +return 'Y'; +ELSE +return 'N'; +END IF; +return NULL; +END; + + +FUNCTION function4( param1 CLOB ) RETURN BLOB +IS +BEGIN + return null; +END; + +END linguistpackage; +/ diff --git a/samples/PLSQL/packageheader.pks b/samples/PLSQL/packageheader.pks new file mode 100644 index 00000000..408cdca3 --- /dev/null +++ b/samples/PLSQL/packageheader.pks @@ -0,0 +1,28 @@ +CREATE OR REPLACE PACKAGE linguistpackage +AUTHID DEFINER +AS + /* + * Package: linguist pacakage + * Purpose: a sample PLSQL file for linguist to work with + * + * Date: 03/03/2014 + * Author: david pyke le brun + * Comments: initial version + */ + +k_constant CONSTANT NUMBER(10,2) := 3.14; + +--basic procedure +PROCEDURE proc_1; + +-- functions with 1 arg +FUNCTION function1( param1 VARCHAR2 ) RETURN VARCHAR2; +FUNCTION function2( param1 NUMBER ) RETURN DATE; + +--a few more to use all basic SQL types +FUNCTION function3( param1 TIMESTAMP ) RETURN CHAR; +FUNCTION function4( param1 CLOB ) RETURN BLOB; + +END linguistpackage; +/ + diff --git a/samples/PLSQL/who_called_me.sql b/samples/PLSQL/who_called_me.sql new file mode 100644 index 00000000..fee4ed9b --- /dev/null +++ b/samples/PLSQL/who_called_me.sql @@ -0,0 +1,65 @@ +CREATE OR REPLACE PROCEDURE who_called_me +( owner OUT VARCHAR2, + name OUT VARCHAR2, + lineno OUT NUMBER, + caller_t OUT VARCHAR2 , + depth NUMBER DEFAULT 1 +) +AUTHID DEFINER +AS +--depth based version of who_called_me from asktom + call_stack VARCHAR2(4096) default dbms_utility.format_call_stack; + n NUMBER; + found_stack BOOLEAN DEFAULT FALSE; + line VARCHAR2(255); + cnt NUMBER := 0; +BEGIN + LOOP + n := instr( call_stack, chr(10) ); + exit when ( n is NULL or n = 0 ); +-- + line := substr( call_stack, 1, n-1 ); + call_stack := substr( call_stack, n+1 ); +-- + if ( NOT found_stack ) then + if ( line like '%handle%number%name%' ) then + found_stack := TRUE; + end if; + else + cnt := cnt + 1; + -- cnt = 1 is ME + -- cnt = 2 is MY Caller + -- cnt = 3 is Their Caller + if ( cnt = (2+depth) ) then + lineno := to_number(substr( line, 13, 8 )); + line := substr( line, 23 ); --set to rest of line .. change from 21 to 23 + if ( line like 'pr%' ) then + n := length( 'procedure ' ); + elsif ( line like 'fun%' ) then + n := length( 'function ' ); + elsif ( line like 'package body%' ) then + n := length( 'package body ' ); + elsif ( line like 'pack%' ) then + n := length( 'package ' ); + elsif ( line like 'anonymous%' ) then + n := length( 'anonymous block ' ); + else + n := null; + end if; + if ( n is not null ) then + caller_t := ltrim(rtrim(upper(substr( line, 1, n-1 )))); + else + caller_t := 'TRIGGER'; + end if; + + line := substr( line, nvl(n,1) ); + n := instr( line, '.' ); + owner := ltrim(rtrim(substr( line, 1, n-1 ))); + name := LTRIM(RTRIM(SUBSTR( LINE, N+1 ))); + exit; + END IF; + END IF; + END LOOP; +END; +/ + diff --git a/samples/PLpgSQL/plpgsql_lint-8.4.sql b/samples/PLpgSQL/plpgsql_lint-8.4.sql new file mode 100644 index 00000000..72c84469 --- /dev/null +++ b/samples/PLpgSQL/plpgsql_lint-8.4.sql @@ -0,0 +1,165 @@ +load 'plpgsql'; +load 'plpgsql_lint'; + +create table t1(a int, b int); + +create function f1() +returns void as $$ +begin + if false then + update t1 set c = 30; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create function g1(out a int, out b int) +as $$ + select 10,20; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + r := g1(); + if false then + raise notice '%', r.c; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function g1(out a int, out b int) +returns setof record as $$ +select * from t1; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + raise notice '%', r.c; + end loop; +end; +$$ language plpgsql; + +select f1(); + +create or replace function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + r.c := 20; + end loop; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function f1() +returns int as $$ +declare r int; +begin + if false then + r := a + b; + end if; + return r; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '%', 1, 2; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '% %'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +declare r int[]; +begin + if false then + r[c+10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + + +create or replace function f1() +returns void as $$ +declare r int; +begin + if false then + r[10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create type diagnostic_info_type as ( + status text, + message text, + detail text, + row_count int); + +create or replace function f1() +returns void as $$ +declare + dg record; +begin + dg := NULL::diagnostic_info_type; + if false then + dg.status := '00000'; + dg.mistake := 'hello'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); diff --git a/samples/PLpgSQL/plpgsql_lint-9.0.sql b/samples/PLpgSQL/plpgsql_lint-9.0.sql new file mode 100644 index 00000000..72c84469 --- /dev/null +++ b/samples/PLpgSQL/plpgsql_lint-9.0.sql @@ -0,0 +1,165 @@ +load 'plpgsql'; +load 'plpgsql_lint'; + +create table t1(a int, b int); + +create function f1() +returns void as $$ +begin + if false then + update t1 set c = 30; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create function g1(out a int, out b int) +as $$ + select 10,20; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + r := g1(); + if false then + raise notice '%', r.c; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function g1(out a int, out b int) +returns setof record as $$ +select * from t1; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + raise notice '%', r.c; + end loop; +end; +$$ language plpgsql; + +select f1(); + +create or replace function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + r.c := 20; + end loop; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function f1() +returns int as $$ +declare r int; +begin + if false then + r := a + b; + end if; + return r; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '%', 1, 2; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '% %'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +declare r int[]; +begin + if false then + r[c+10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + + +create or replace function f1() +returns void as $$ +declare r int; +begin + if false then + r[10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create type diagnostic_info_type as ( + status text, + message text, + detail text, + row_count int); + +create or replace function f1() +returns void as $$ +declare + dg record; +begin + dg := NULL::diagnostic_info_type; + if false then + dg.status := '00000'; + dg.mistake := 'hello'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); diff --git a/samples/PLpgSQL/plpgsql_lint-9.1.sql b/samples/PLpgSQL/plpgsql_lint-9.1.sql new file mode 100644 index 00000000..2cc532a1 --- /dev/null +++ b/samples/PLpgSQL/plpgsql_lint-9.1.sql @@ -0,0 +1,179 @@ +load 'plpgsql'; +load 'plpgsql_lint'; + +create table t1(a int, b int); + +create function f1() +returns void as $$ +begin + if false then + update t1 set c = 30; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create function g1(out a int, out b int) +as $$ + select 10,20; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + r := g1(); + if false then + raise notice '%', r.c; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function g1(out a int, out b int) +returns setof record as $$ +select * from t1; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + raise notice '%', r.c; + end loop; +end; +$$ language plpgsql; + +select f1(); + +create or replace function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + r.c := 20; + end loop; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function f1() +returns int as $$ +declare r int; +begin + if false then + r := a + b; + end if; + return r; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '%', 1, 2; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '% %'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +declare r int[]; +begin + if false then + r[c+10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + + +create or replace function f1() +returns void as $$ +declare r int; +begin + if false then + r[10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create type diagnostic_info_type as ( + status text, + message text, + detail text, + row_count int); + +create or replace function f1() +returns void as $$ +declare dg record; +begin + dg := NULL::diagnostic_info_type; + if false then + dg.status := '00000'; + dg.mistake := 'hello'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +declare dg record; +begin + if false then + dg := 10,20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + diff --git a/samples/PLpgSQL/plpgsql_lint-9.2.sql b/samples/PLpgSQL/plpgsql_lint-9.2.sql new file mode 100644 index 00000000..73da6e67 --- /dev/null +++ b/samples/PLpgSQL/plpgsql_lint-9.2.sql @@ -0,0 +1,166 @@ +load 'plpgsql'; +load 'plpgsql_lint'; + +create table t1(a int, b int); + +create function f1() +returns void as $$ +begin + if false then + update t1 set c = 30; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create function g1(out a int, out b int) +as $$ + select 10,20; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + r := g1(); + if false then + raise notice '%', r.c; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function g1(out a int, out b int) +returns setof record as $$ +select * from t1; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + raise notice '%', r.c; + end loop; +end; +$$ language plpgsql; + +select f1(); + +create or replace function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + r.c := 20; + end loop; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function f1() +returns int as $$ +declare r int; +begin + if false then + r := a + b; + end if; + return r; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '%', 1, 2; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '% %'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +declare r int[]; +begin + if false then + r[c+10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + + +create or replace function f1() +returns void as $$ +declare r int; +begin + if false then + r[10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create type _exception_type as ( + state text, + message text, + detail text); + +create or replace function f1() +returns void as $$ +declare + _exception record; +begin + _exception := NULL::_exception_type; +exception when others then + get stacked diagnostics + _exception.state = RETURNED_SQLSTATE, + _exception.message = MESSAGE_TEXT, + _exception.detail = PG_EXCEPTION_DETAIL, + _exception.hint = PG_EXCEPTION_HINT; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); diff --git a/samples/PLpgSQL/plpgsql_lint-9.3.sql b/samples/PLpgSQL/plpgsql_lint-9.3.sql new file mode 100644 index 00000000..73da6e67 --- /dev/null +++ b/samples/PLpgSQL/plpgsql_lint-9.3.sql @@ -0,0 +1,166 @@ +load 'plpgsql'; +load 'plpgsql_lint'; + +create table t1(a int, b int); + +create function f1() +returns void as $$ +begin + if false then + update t1 set c = 30; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create function g1(out a int, out b int) +as $$ + select 10,20; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + r := g1(); + if false then + raise notice '%', r.c; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function g1(out a int, out b int) +returns setof record as $$ +select * from t1; +$$ language sql; + +create function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + raise notice '%', r.c; + end loop; +end; +$$ language plpgsql; + +select f1(); + +create or replace function f1() +returns void as $$ +declare r record; +begin + for r in select * from g1() + loop + r.c := 20; + end loop; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); +drop function g1(); + +create function f1() +returns int as $$ +declare r int; +begin + if false then + r := a + b; + end if; + return r; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '%', 1, 2; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +begin + if false then + raise notice '% %'; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create or replace function f1() +returns void as $$ +declare r int[]; +begin + if false then + r[c+10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + + +create or replace function f1() +returns void as $$ +declare r int; +begin + if false then + r[10] := 20; + end if; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); + +create type _exception_type as ( + state text, + message text, + detail text); + +create or replace function f1() +returns void as $$ +declare + _exception record; +begin + _exception := NULL::_exception_type; +exception when others then + get stacked diagnostics + _exception.state = RETURNED_SQLSTATE, + _exception.message = MESSAGE_TEXT, + _exception.detail = PG_EXCEPTION_DETAIL, + _exception.hint = PG_EXCEPTION_HINT; +end; +$$ language plpgsql; + +select f1(); + +drop function f1(); diff --git a/samples/SQL/create_stuff.sql b/samples/SQL/create_stuff.sql new file mode 100644 index 00000000..edfb569c --- /dev/null +++ b/samples/SQL/create_stuff.sql @@ -0,0 +1,21 @@ + +CREATE TABLE x AS SELECT * FROM DUAL; + +CREATE TABLE y ( +col1 NUMBER NOT NULL , +col2 VARCHAR2(200), +col3 DATE, +col4 TIMESTAMP WITH TIME ZONE NOT NULL +); + + +CREATE USER username IDENTIFIED BY password; + +GRANT CONNECT, RESOURCE TO username; + + +GRANT CREATE TYPE TO username; +GRANT CREATE PROCEDURE TO username; +GRANT CREATE TABLE TO username; +GRANT CREATE VIEW TO username; + diff --git a/samples/SQL/drop_stuff.sql b/samples/SQL/drop_stuff.sql new file mode 100644 index 00000000..7d638eed --- /dev/null +++ b/samples/SQL/drop_stuff.sql @@ -0,0 +1,13 @@ +drop procedure who_called_me; +drop package body linguist_package; +drop package linguist_package; +drop function functionname1; + +drop table x; +drop table y cascade; + +drop type typename1; +drop type typename2; + +drop view viewname1; +drop view viewname2; diff --git a/samples/SQL/dual.sql b/samples/SQL/dual.sql new file mode 100644 index 00000000..8ef5c624 --- /dev/null +++ b/samples/SQL/dual.sql @@ -0,0 +1,3 @@ +--this is the most basic oracle sql command +select * from dual; + diff --git a/samples/SQLPL/check_reorg.sql b/samples/SQLPL/check_reorg.sql new file mode 100644 index 00000000..f8906465 --- /dev/null +++ b/samples/SQLPL/check_reorg.sql @@ -0,0 +1,39 @@ +create procedure check_reorg_tables (in v_schema varchar(128), out v_reorg_counter integer) +begin + + declare loc result_set_locator varying; + + declare schema_out varchar(128); + declare table_out varchar(128); + declare card_out integer; + declare overflow_out integer; + declare npages_out integer; + declare fpages_out integer; + declare active_blocks_out integer; + declare tsize_out integer; + declare f1_out integer; + declare f2_out integer; + declare f3_out integer; + declare reorg_out varchar(3); + declare cursor_end smallint default 0; + + declare continue handler for NOT FOUND + + set cursor_end = 1; + set v_reorg_counter = 0; + + call reorgchk_tb_stats('S', v_schema); + associate result set locator(loc) with procedure reorgchk_tb_stats; + allocate mycursor cursor for result set loc; + + open mycursor; + repeat + fetch from mycursor into schema_out, table_out, card_out, overflow_out, npages_out, fpages_out, active_blocks_out, tsize_out, f1_out, f2_out, f3_out, reorg_out; + if reorg_out <> '---' then + set v_reorg_counter = v_reorg_counter + 1; + end if; + until cursor_end = 1 + end repeat; + close mycursor; + +end! diff --git a/samples/SQLPL/comm_amount.db2 b/samples/SQLPL/comm_amount.db2 new file mode 100644 index 00000000..66efc97c --- /dev/null +++ b/samples/SQLPL/comm_amount.db2 @@ -0,0 +1,30 @@ +DROP FUNCTION COMM_AMOUNT; +CREATE FUNCTION COMM_AMOUNT(SALARY DEC(9,2)) + RETURNS DEC(9,2) + LANGUAGE SQL READS SQL DATA + BEGIN ATOMIC + DECLARE REMAINDER DEC(9,2) DEFAULT 0.0;-- + DECLARE COMM_PAID DEC(9,2) DEFAULT 0.0;-- + DECLARE COMM_INCR INT DEFAULT 1;-- + DECLARE MAX_COMM DEC(9,2) DEFAULT 0.0;-- + + IF (SALARY <= 0) THEN + SIGNAL SQLSTATE '75000' + SET MESSAGE_TEXT = 'Bad Salary';-- + END IF;-- + + SET REMAINDER = SALARY;-- + +L1: WHILE REMAINDER > 0.0 DO + SET COMM_PAID = COMM_PAID + (COMM_INCR * 500.00);-- + SET REMAINDER = REMAINDER-(COMM_INCR * 5000.00);-- + SET COMM_INCR = COMM_INCR + 1;-- + END WHILE L1;-- + + SET MAX_COMM = + (SELECT SUM(SALARY)/100.00 FROM EMPLOYEE);-- + IF (COMM_PAID > MAX_COMM) THEN + SET COMM_PAID = MAX_COMM;-- + END IF;-- + RETURN COMM_PAID;-- +END; diff --git a/samples/SQLPL/drop_table.db2 b/samples/SQLPL/drop_table.db2 new file mode 100644 index 00000000..60e34d8e --- /dev/null +++ b/samples/SQLPL/drop_table.db2 @@ -0,0 +1,13 @@ +DROP TABLE TDEPT; +CREATE TABLE TDEPT (DEPTNO CHAR(4)); + +--#SET TERMINATOR @ +BEGIN ATOMIC + DECLARE COUNT INT DEFAULT 5; + + WHILE COUNT > 0 DO + INSERT INTO TDEPT VALUES 'F'|| + RTRIM(CHAR(COUNT)); + SET COUNT = COUNT - 1; + END WHILE; +END@ diff --git a/samples/SQLPL/runstats.sql b/samples/SQLPL/runstats.sql new file mode 100644 index 00000000..fcd8a46d --- /dev/null +++ b/samples/SQLPL/runstats.sql @@ -0,0 +1,18 @@ +create procedure runstats (out nr_tables integer, out nr_ok integer) +begin + declare SQLCODE integer; + declare stmt varchar(100); + + set nr_tables = 0; + set nr_ok = 0; + + for line as select tabschema, tabname from syscat.tables where type='T' and tabschema='SPODEN' + do + set nr_tables = nr_tables + 1; + set stmt = 'CALL SYSPROC.ADMIN_CMD (RUNSTATS ON TABLE ' concat rtrim(line.tabschema) concat '.' concat line.tabname concat ')'; + execute immediate stmt; + if SQLCODE = 0 then + set nr_ok = nr_ok + 1; + end if; + end for; +end! diff --git a/samples/SQLPL/trigger.sql b/samples/SQLPL/trigger.sql new file mode 100644 index 00000000..5002fa80 --- /dev/null +++ b/samples/SQLPL/trigger.sql @@ -0,0 +1,9 @@ +create trigger CHECK_HIREDATE +no cascade before insert on EMPLOYEE +referencing new as N +for each row mode db2sql +if n.hiredate > current date +then + signal SQLSTATE '75000' + set MESSAGE_TEXT = 'Hire date must be in the past'; +end if! diff --git a/vendor/grammars/Oracle b/vendor/grammars/Oracle new file mode 160000 index 00000000..f5308c9a --- /dev/null +++ b/vendor/grammars/Oracle @@ -0,0 +1 @@ +Subproject commit f5308c9abe377210145ffe606bd8b3ac0088608a From 41e1b7bd4e68261aa33ab425b30ee815e6247259 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 6 Feb 2015 22:14:22 +0100 Subject: [PATCH 05/66] Detection by extension made case-insensitive --- lib/linguist/file_blob.rb | 2 +- lib/linguist/language.rb | 8 +-- lib/linguist/languages.yml | 23 +------- samples/Eiffel/application.e | 44 ++++++++++++++ samples/Eiffel/book_collection.e | 82 +++++++++++++++++++++++++++ samples/Eiffel/git_checkout_command.e | 41 ++++++++++++++ test/test_pedantic.rb | 2 +- test/test_samples.rb | 4 +- 8 files changed, 176 insertions(+), 30 deletions(-) create mode 100644 samples/Eiffel/application.e create mode 100644 samples/Eiffel/book_collection.e create mode 100644 samples/Eiffel/git_checkout_command.e diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 04441935..cf142ef5 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -67,7 +67,7 @@ module Linguist # # Returns an Array def extensions - basename, *segments = File.basename(name).split(".") + basename, *segments = File.basename(name).downcase.split(".") segments.map.with_index do |segment, index| "." + segments[index..-1].join(".") diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 7fbf8a96..21cfc6ff 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -80,7 +80,7 @@ module Linguist raise ArgumentError, "Extension is missing a '.': #{extension.inspect}" end - @extension_index[extension] << language + @extension_index[extension.downcase] << language end language.interpreters.each do |interpreter| @@ -198,7 +198,7 @@ module Linguist # Returns all matching Languages or [] if none were found. def self.find_by_extension(extname) extname = ".#{extname}" unless extname.start_with?(".") - @extension_index[extname] + @extension_index[extname.downcase] end # DEPRECATED @@ -535,8 +535,8 @@ module Linguist if extnames = extensions[name] extnames.each do |extname| - if !options['extensions'].index { |x| x.end_with? extname } - warn "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" unless extname == '.script!' + if !options['extensions'].index { |x| x.downcase.end_with? extname.downcase } + warn "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml" unless extname == '.script!' options['extensions'] << extname end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index e899046e..bf4b6660 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -204,7 +204,6 @@ Assembly: - nasm extensions: - .asm - - .ASM - .a51 tm_scope: source.asm.x86 ace_mode: assembly_x86 @@ -349,8 +348,6 @@ C: color: "#555" extensions: - .c - - .C - - .H - .cats - .h - .idc @@ -429,8 +426,6 @@ COBOL: type: programming extensions: - .cob - - .COB - - .CPY - .cbl - .ccp - .cobol @@ -867,14 +862,6 @@ FORTRAN: color: "#4d41b1" extensions: - .f90 - - .F - - .F03 - - .F08 - - .F77 - - .F90 - - .F95 - - .FOR - - .FPP - .f - .f03 - .f08 @@ -918,9 +905,7 @@ Forth: color: "#341708" extensions: - .fth - - .4TH - .4th - - .F - .f - .for - .forth @@ -969,7 +954,6 @@ GAS: group: Assembly extensions: - .s - - .S tm_scope: source.asm.x86 ace_mode: assembly_x86 @@ -1127,7 +1111,6 @@ Graphviz (DOT): tm_scope: source.dot extensions: - .dot - - .DOT - .gv ace_mode: text @@ -2210,7 +2193,6 @@ Perl: color: "#0298c3" extensions: - .pl - - .PL - .cgi - .fcgi - .perl @@ -2442,8 +2424,6 @@ R: - splus extensions: - .r - - .R - - .Rd - .rd - .rsx filenames: @@ -2496,7 +2476,6 @@ RMarkdown: ace_mode: markdown extensions: - .rmd - - .Rmd tm_scope: none Racket: @@ -3201,11 +3180,11 @@ XML: - .svg - .targets - .tmCommand + - .tml - .tmLanguage - .tmPreferences - .tmSnippet - .tmTheme - - .tml - .ts - .ui - .urdf diff --git a/samples/Eiffel/application.e b/samples/Eiffel/application.e new file mode 100644 index 00000000..16426905 --- /dev/null +++ b/samples/Eiffel/application.e @@ -0,0 +1,44 @@ +note + description : "nino application root class" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION + +inherit + ARGUMENTS + + HTTP_SERVER_SHARED_CONFIGURATION + +create + make + +feature {NONE} -- Initialization + + make + -- Run application. + local + l_server : HTTP_SERVER + l_cfg: HTTP_SERVER_CONFIGURATION + l_http_handler : HTTP_HANDLER + do + create l_cfg.make + l_cfg.http_server_port := 9_000 + l_cfg.document_root := default_document_root + set_server_configuration (l_cfg) + debug ("nino") + l_cfg.set_is_verbose (True) + end + + create l_server.make (l_cfg) + create {APPLICATION_CONNECTION_HANDLER} l_http_handler.make (l_server) + l_server.setup (l_http_handler) + end + +feature -- Access + + default_document_root: STRING = "webroot" + +end + diff --git a/samples/Eiffel/book_collection.e b/samples/Eiffel/book_collection.e new file mode 100644 index 00000000..8959455a --- /dev/null +++ b/samples/Eiffel/book_collection.e @@ -0,0 +1,82 @@ +class + BOOK_COLLECTION + +create + make + +feature {NONE} -- Initialization + + make (a_name: STRING_32) + -- Create a book collection with `a_name' as `name'. + do + set_name (a_name) + create book_index.make (10) + ensure + name_set: name = a_name + end + +feature -- Access + + name: STRING_32 + -- Name. + + books: LIST [BOOK] + -- collection of book. + do + create {LINKED_LIST [BOOK]} Result.make + across + book_index as it + loop + Result.append (it.item) + end + end + + books_by_author (a_author: STRING_32): LIST [BOOK] + -- Books wrote by `a_author' in this collection. + do + if attached book_index [a_author] as l_result then + Result := l_result + else + create {LINKED_LIST [BOOK]} Result.make + end + end + +feature -- Change + + set_name (a_name: STRING_32) + -- Set `name' with `a_name'. + do + name := a_name + ensure + name_set: name = a_name + end + + add_book (a_book: BOOK) + -- Extend collection with `a_book'. + local + l: detachable LIST [BOOK] + do + l := book_index.at (a_book.author.name) + if l = Void then + create {LINKED_LIST [BOOK]} l.make + book_index.put (l, a_book.author.name) + end + l.force (a_book) + end + + add_books (book_list: like books) + -- Append collection with `book_list'. + do + across + book_list as it + loop + add_book (it.item) + end + end + +feature {NONE} -- Implementation + + book_index: HASH_TABLE [LIST [BOOK], STRING_32] + -- Association of author name and its books. + +end -- class BOOK_COLLECTION diff --git a/samples/Eiffel/git_checkout_command.e b/samples/Eiffel/git_checkout_command.e new file mode 100644 index 00000000..f78747d2 --- /dev/null +++ b/samples/Eiffel/git_checkout_command.e @@ -0,0 +1,41 @@ +note + description: "Git checkout command." + author: "Olivier Ligot" + +class + GIT_CHECKOUT_COMMAND + +inherit + GIT_COMMAND + +create + make, + make_master + +feature {NONE} -- Initialization + + make (a_branch: STRING) + -- Checkout the branch `a_branch'. + do + initialize + arguments.force_last (a_branch) + branch := a_branch + ensure + branch_set: branch = a_branch + end + + make_master + -- Checkout the master branch. + do + make ("master") + end + +feature -- Access + + branch: STRING + -- Branch to checkout + + name: STRING = "checkout" + -- Git subcommand name + +end diff --git a/test/test_pedantic.rb b/test/test_pedantic.rb index 0861b8d8..29b673ab 100644 --- a/test/test_pedantic.rb +++ b/test/test_pedantic.rb @@ -12,7 +12,7 @@ class TestPedantic < Minitest::Test def test_extensions_are_sorted LANGUAGES.each do |name, language| extensions = language['extensions'] - assert_sorted extensions[1..-1] if extensions && extensions.size > 1 + assert_sorted extensions[1..-1].map(&:downcase) if extensions && extensions.size > 1 end end diff --git a/test/test_samples.rb b/test/test_samples.rb index 0b0722dc..6de1c7e9 100644 --- a/test/test_samples.rb +++ b/test/test_samples.rb @@ -43,7 +43,7 @@ class TestSamples < Minitest::Test if extnames = Samples.cache['extnames'][name] extnames.each do |extname| next if extname == '.script!' - assert options['extensions'].index { |x| x.end_with? extname }, "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" + assert options['extensions'].index { |x| x.downcase.end_with? extname.downcase }, "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml" end end @@ -67,7 +67,7 @@ class TestSamples < Minitest::Test if language_matches.length > 1 language_matches.each do |match| samples = "samples/#{match.name}/*#{extension}" - assert Dir.glob(samples).any?, "Missing samples in #{samples.inspect}. See https://github.com/github/linguist/blob/master/CONTRIBUTING.md" + assert Dir.glob(samples, File::FNM_CASEFOLD).any?, "Missing samples in #{samples.inspect}. See https://github.com/github/linguist/blob/master/CONTRIBUTING.md" end end end From fb6ec8aaa76f58cd047de44dcf8f6389638b9a24 Mon Sep 17 00:00:00 2001 From: David Pyke Le Brun Date: Mon, 9 Feb 2015 11:46:14 +0000 Subject: [PATCH 06/66] remove oracle grammer. (to be readded) --- .gitmodules | 3 --- vendor/grammars/Oracle | 1 - 2 files changed, 4 deletions(-) delete mode 160000 vendor/grammars/Oracle diff --git a/.gitmodules b/.gitmodules index aefae11d..4e72920d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -594,6 +594,3 @@ [submodule "vendor/grammars/ec.tmbundle"] path = vendor/grammars/ec.tmbundle url = https://github.com/ecere/ec.tmbundle -[submodule "vendor/grammars/Oracle"] - path = vendor/grammars/Oracle - url = git@github.com:mulander/oracle.tmbundle.git diff --git a/vendor/grammars/Oracle b/vendor/grammars/Oracle deleted file mode 160000 index f5308c9a..00000000 --- a/vendor/grammars/Oracle +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f5308c9abe377210145ffe606bd8b3ac0088608a From 7ecf65551e6f112bae5119dbd3eb62055f02ca82 Mon Sep 17 00:00:00 2001 From: David Pyke Le Brun Date: Mon, 9 Feb 2015 11:58:50 +0000 Subject: [PATCH 07/66] re-add oracle grammer module using https --- .gitmodules | 3 +++ grammars.yml | 4 ++-- lib/linguist/languages.yml | 2 +- vendor/grammars/oracle.tmbundle | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) create mode 160000 vendor/grammars/oracle.tmbundle diff --git a/.gitmodules b/.gitmodules index 4e72920d..d1bee979 100644 --- a/.gitmodules +++ b/.gitmodules @@ -594,3 +594,6 @@ [submodule "vendor/grammars/ec.tmbundle"] path = vendor/grammars/ec.tmbundle url = https://github.com/ecere/ec.tmbundle +[submodule "vendor/grammars/oracle.tmbundle"] + path = vendor/grammars/oracle.tmbundle + url = https://github.com/mulander/oracle.tmbundle.git diff --git a/grammars.yml b/grammars.yml index 398c2a35..696f27ff 100644 --- a/grammars.yml +++ b/grammars.yml @@ -68,8 +68,6 @@ vendor/grammars/NimLime: - source.nim - source.nim_filter - source.nimcfg -vendor/grammars/Oracle/: -- source.plsql.oracle vendor/grammars/PHP-Twig.tmbundle: - text.html.twig vendor/grammars/RDoc.tmbundle: @@ -364,6 +362,8 @@ vendor/grammars/ooc.tmbundle: - source.ooc vendor/grammars/opa.tmbundle: - source.opa +vendor/grammars/oracle.tmbundle: +- source.plsql.oracle vendor/grammars/oz-tmbundle/Syntaxes/Oz.tmLanguage: - source.oz vendor/grammars/pascal.tmbundle: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index d2133a5c..534b2fdc 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2149,7 +2149,7 @@ PHP: PLSQL: type: programming ace_mode: sql - tm_scope: Oracle + tm_scope: source.plsql.oracle extensions: - .pls - .pkb diff --git a/vendor/grammars/oracle.tmbundle b/vendor/grammars/oracle.tmbundle new file mode 160000 index 00000000..f5308c9a --- /dev/null +++ b/vendor/grammars/oracle.tmbundle @@ -0,0 +1 @@ +Subproject commit f5308c9abe377210145ffe606bd8b3ac0088608a From e9691725430bf553b452c6f8892c235e3d4f157a Mon Sep 17 00:00:00 2001 From: David Pyke Le Brun Date: Mon, 9 Feb 2015 14:16:25 +0000 Subject: [PATCH 08/66] recode heuristic to use existing style. add additional sample --- lib/linguist/heuristics.rb | 33 +++++++++++++-------------------- lib/linguist/languages.yml | 14 +++++++------- samples/SQLPL/sleep.sql | 9 +++++++++ 3 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 samples/SQLPL/sleep.sql diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 3d1899ec..85b013eb 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -224,29 +224,22 @@ module Linguist end end disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data| - match = nil - #unique keywords for each language - plpgsqlkeywords = [/^\\i\b/i, /begin ?(work|transaction)?;/i , /AS \$\$/i, /RAISE EXCEPTION/i, /LANGUAGE plpgsql\b/i ] - plsqlkeywords = [ /pragma\b/i , /constructor\W+function\b/i] - #sqlplkeywords = [ ] + #only return value if a definite positive - #common keywords that are not SQL - plkeywords = [/begin\b/i,/boolean\b/i, /package\b/i,/exception\b/i, /^end;\b/i ] - - re = Regexp.union(plpgsqlkeywords) - if data.match(re) - match = Language["PLpgSQL"] - else - re = Regexp.union(plsqlkeywords) - if data.match(re) - match= Language["PLSQL"] - else - re = Regexp.union(plkeywords) - match= Language["SQL"] if ! data.match(re) - end + if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN (WORK|TRANSACTION)+;/i.match(data) + #postgres + Language["PLpgSQL"] + elsif /(alter module)|(language sql)|(begin( NOT)+ atomic)/i.match(data) || /signal SQLSTATE '[0-9]+'/i.match(data) + #ibm db2 + Language["SQLPL"] + elsif /pragma|\$\$PLSQL_|XMLTYPE|sysdate|systimestamp|\.nextval|connect by|AUTHID (DEFINER|CURRENT_USER)/i.match(data) || /constructor\W+function/i.match(data) + #oraclestuff + Language["PLSQL"] + elsif ! /begin|boolean|package|exception/i.match(data) + #generic sql + Language["SQL"] end - match end end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 2ea132d5..c26884b4 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2696,13 +2696,13 @@ SQL: - .viw #IBM DB2 -#SQLPL: - #type: programming - #ace_mode: sql - #tm_scope: source.sql - #extensions: - #- .sql - #- .db2 +SQLPL: + type: programming + ace_mode: sql + tm_scope: source.sql + extensions: + - .sql + - .db2 STON: type: data diff --git a/samples/SQLPL/sleep.sql b/samples/SQLPL/sleep.sql new file mode 100644 index 00000000..18f72055 --- /dev/null +++ b/samples/SQLPL/sleep.sql @@ -0,0 +1,9 @@ +create procedure sleep (in sleeptime integer) +begin + declare wait_until timestamp; + + set wait_until = (current timestamp + sleeptime seconds); + while (wait_until > current timestamp) + do + end while; +end! From 5e9bb67d10f0670ba1278c130fe66d44b682b90b Mon Sep 17 00:00:00 2001 From: David Pyke Le Brun Date: Mon, 9 Feb 2015 14:27:14 +0000 Subject: [PATCH 09/66] temporary add grammer to whitelist until license gets added --- lib/linguist/heuristics.rb | 2 +- test/test_grammars.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 85b013eb..a4d31626 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -226,7 +226,7 @@ module Linguist disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data| #only return value if a definite positive - if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN (WORK|TRANSACTION)+;/i.match(data) + if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN( WORK| TRANSACTION)?;/i.match(data) #postgres Language["PLpgSQL"] elsif /(alter module)|(language sql)|(begin( NOT)+ atomic)/i.match(data) || /signal SQLSTATE '[0-9]+'/i.match(data) diff --git a/test/test_grammars.rb b/test/test_grammars.rb index 188bc187..48f6d83c 100644 --- a/test/test_grammars.rb +++ b/test/test_grammars.rb @@ -9,6 +9,7 @@ class TestGrammars < Minitest::Test vendor/grammars/Sublime-Lasso vendor/grammars/Sublime-REBOL vendor/grammars/x86-assembly-textmate-bundle + vendor/grammars/oracle.tmbundle ].freeze def setup From dc852b63987b6abaed20f4e478ee5979e92e3f6c Mon Sep 17 00:00:00 2001 From: Phillip Berndt Date: Wed, 11 Feb 2015 12:58:07 +0100 Subject: [PATCH 10/66] Added a sample of a C header file that is currently recognized as C++ See https://github.com/github/linguist/issues/1626#issuecomment-73870081 Taken from https://github.com/phillipberndt/pqiv/blob/469fe63df4b27463f8accf8a45ae515a17c202e7/pqiv.h --- samples/C/pqiv.h | 166 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 samples/C/pqiv.h diff --git a/samples/C/pqiv.h b/samples/C/pqiv.h new file mode 100644 index 00000000..ea535125 --- /dev/null +++ b/samples/C/pqiv.h @@ -0,0 +1,166 @@ +/** + * pqiv + * + * Copyright (c) 2013-2014, Phillip Berndt + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +// This file contains the definition of files, image types and +// the plugin infrastructure. It should be included in file type +// handlers. + +#ifndef _PQIV_H_INCLUDED +#define _PQIV_H_INCLUDED + +#include +#include +#include +#include "lib/bostree.h" + +#ifndef PQIV_VERSION +#define PQIV_VERSION "2.3" +#endif + +#define FILE_FLAGS_ANIMATION (guint)(1) +#define FILE_FLAGS_MEMORY_IMAGE (guint)(1<<1) + +// The structure for images {{{ +typedef struct file_type_handler_struct_t file_type_handler_t; +typedef struct { + // File type + const file_type_handler_t *file_type; + + // Special flags + // FILE_FLAGS_ANIMATION -> Animation functions are invoked + // Set by file type handlers + // FILE_FLAGS_MEMORY_IMAGE -> File lives in memory + guint file_flags; + + // The file name to display and to sort by + gchar *display_name; + + // The URI or file name of the file + gchar *file_name; + + // If the file is a memory image, the actual image data + GBytes *file_data; + + // The file monitor structure is used for inotify-watching of + // the files + GFileMonitor *file_monitor; + + // This flag stores whether this image is currently loaded + // and valid. i.e. if it is set, you can assume that + // private_data contains a representation of the image; + // if not, you can NOT assume that it does not. + gboolean is_loaded; + + // Cached image size + guint width; + guint height; + + // File-type specific data, allocated and freed by the file type handlers + void *private; +} file_t; +// }}} +// Definition of the built-in file types {{{ + +// If you want to implement your own file type, you'll have to implement the +// following functions and a non-static initialization function named +// file_type_NAME_initializer that fills a file_type_handler_t with pointers to +// the functions. Store the file in backends/NAME.c and adjust the Makefile to +// add the required libraries if your backend is listed in the $(BACKENDS) +// variable. + +typedef enum { PARAMETER, RECURSION, INOTIFY, BROWSE_ORIGINAL_PARAMETER, FILTER_OUTPUT } load_images_state_t; +// Allocation function: Allocate the ->private structure within a file and add the +// image(s) to the list of available images via load_images_handle_parameter_add_file() +// If an image is not to be loaded for any reason, the file structure should be +// deallocated using file_free() +// Returns a pointer to the first added image +// Optional, you can also set the pointer to this function to NULL. +typedef BOSNode *(*file_type_alloc_fn_t)(load_images_state_t state, file_t *file); + +// Deallocation, if a file is removed from the images list. Free the ->private structure. +// Only called if ->private is non-NULL. +typedef void (*file_type_free_fn_t)(file_t *file); + +// Actually load a file into memory +typedef void (*file_type_load_fn_t)(file_t *file, GInputStream *data, GError **error_pointer); + +// Unload a file +typedef void (*file_type_unload_fn_t)(file_t *file); + +// Animation support: Initialize memory for animations, return ms until first frame +// Optional, you can also set the pointer to this function to NULL. +typedef double (*file_type_animation_initialize_fn_t)(file_t *file); + +// Animation support: Advance to the next frame, return ms until next frame +// Optional, you can also set the pointer to this function to NULL. +typedef double (*file_type_animation_next_frame_fn_t)(file_t *file); + +// Draw the current view to a cairo context +typedef void (*file_type_draw_fn_t)(file_t *file, cairo_t *cr); + +struct file_type_handler_struct_t { + // All files will be filtered with this filter. If it lets it pass, + // a handler is assigned to a file. If none do, the file is + // discarded if it was found during directory traversal or + // loaded using the first image backend if it was an explicit + // parameter. + GtkFileFilter *file_types_handled; + + // Pointers to the functions defined above + file_type_alloc_fn_t alloc_fn; + file_type_free_fn_t free_fn; + file_type_load_fn_t load_fn; + file_type_unload_fn_t unload_fn; + file_type_animation_initialize_fn_t animation_initialize_fn; + file_type_animation_next_frame_fn_t animation_next_frame_fn; + file_type_draw_fn_t draw_fn; +}; + +// Initialization function: Tell pqiv about a backend +typedef void (*file_type_initializer_fn_t)(file_type_handler_t *info); + +// pqiv symbols available to plugins {{{ + +// Global cancellable that should be used for every i/o operation +extern GCancellable *image_loader_cancellable; + +// Current scale level. For backends that don't support cairo natively. +extern gdouble current_scale_level; + +// Load a file from disc/memory/network +GInputStream *image_loader_stream_file(file_t *file, GError **error_pointer); + +// Add a file to the list of loaded files +// Should be called at least once in a file_type_alloc_fn_t, with the state being +// forwarded unaltered. +BOSNode *load_images_handle_parameter_add_file(load_images_state_t state, file_t *file); + +// Load all data from an input stream into memory, conveinience function +GBytes *g_input_stream_read_completely(GInputStream *input_stream, GCancellable *cancellable, GError **error_pointer); + +// Free a file +void file_free(file_t *file); + +// }}} + +// File type handlers, used in the initializer and file type guessing +extern file_type_handler_t file_type_handlers[]; + +/* }}} */ + +#endif From 7cdb5ccba865da5053673a090db6097ebe076b66 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 13 Feb 2015 15:37:39 +0100 Subject: [PATCH 11/66] Mark XS files as "type: programming" I'd actually prefer to treat Perl XS files as C code, but this fix shouldn't be controversial. --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 33a22975..099f1ab1 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3257,6 +3257,7 @@ XQuery: ace_mode: xquery XS: + type: programming extensions: - .xs tm_scope: source.c From 8420e4b04467a3e85139bbcb07721c593ea4a3f8 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 22 Feb 2015 10:23:48 -0800 Subject: [PATCH 12/66] Test that languages have a type --- test/test_language.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_language.rb b/test/test_language.rb index 1a39744e..e12b16b8 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -358,6 +358,15 @@ class TestLanguage < Minitest::Test assert missing.empty?, message end + def test_all_languages_have_type + missing = Language.all.select { |language| language.type.nil? } + message = "The following languages' types are not listed in grammars.yml. Please add types for all new languages.\n" + + width = missing.map { |language| language.name.length }.max + message << missing.map { |language| sprintf("%-#{width}s %s", language.name, language.tm_scope) }.sort.join("\n") + assert missing.empty?, message + end + def test_all_languages_have_a_valid_ace_mode ace_fixture_path = File.join('test', 'fixtures', 'ace_modes.json') skip("No ace_modes.json file") unless File.exist?(ace_fixture_path) From 507d191d7d2b8d3ae65d2e135d715e627db1537f Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 22 Feb 2015 10:27:24 -0800 Subject: [PATCH 13/66] Add missing types --- lib/linguist/languages.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0ac757f6..0c09026a 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -271,6 +271,7 @@ Batchfile: ace_mode: batchfile Befunge: + type: programming extensions: - .befunge ace_mode: text @@ -326,6 +327,7 @@ Boo: ace_mode: text Brainfuck: + type: programming extensions: - .b - .bf @@ -419,6 +421,7 @@ CLIPS: ace_mode: text CMake: + type: programming extensions: - .cmake - .cmake.in @@ -478,6 +481,7 @@ Chapel: ace_mode: text ChucK: + type: programming extensions: - .ck tm_scope: source.java @@ -639,6 +643,7 @@ Crystal: - crystal Cucumber: + type: programming extensions: - .feature tm_scope: text.gherkin.feature @@ -698,6 +703,7 @@ DM: ace_mode: c_cpp Darcs Patch: + type: programming search_term: dpatch aliases: - dpatch @@ -715,6 +721,7 @@ Dart: ace_mode: dart Diff: + type: programming extensions: - .diff - .patch @@ -1012,6 +1019,7 @@ Game Maker Language: ace_mode: c_cpp Genshi: + type: programming extensions: - .kid tm_scope: text.xml.genshi @@ -1021,6 +1029,7 @@ Genshi: ace_mode: xml Gentoo Ebuild: + type: programming group: Shell extensions: - .ebuild @@ -1028,6 +1037,7 @@ Gentoo Ebuild: ace_mode: sh Gentoo Eclass: + type: programming group: Shell extensions: - .eclass @@ -1035,6 +1045,7 @@ Gentoo Eclass: ace_mode: sh Gettext Catalog: + type: programming search_term: pot searchable: false aliases: @@ -1135,6 +1146,7 @@ Graphviz (DOT): ace_mode: text Groff: + type: programming extensions: - .man - '.1' @@ -1162,6 +1174,7 @@ Groovy: - groovy Groovy Server Pages: + type: programming group: Groovy aliases: - gsp @@ -1318,6 +1331,7 @@ INI: ace_mode: ini IRC log: + type: data search_term: irc aliases: - irc @@ -1348,6 +1362,7 @@ Inform 7: ace_mode: text Inno Setup: + type: programming extensions: - .iss tm_scope: source.inno @@ -1442,6 +1457,7 @@ Java: - .java Java Server Pages: + type: programming group: Java search_term: jsp aliases: @@ -1537,6 +1553,7 @@ LFE: ace_mode: lisp LLVM: + type: programming extensions: - .ll ace_mode: text @@ -1597,6 +1614,7 @@ Less: ace_mode: less LilyPond: + type: programming extensions: - .ly - .ily @@ -1735,6 +1753,7 @@ Makefile: ace_mode: makefile Mako: + type: programming extensions: - .mako - .mao @@ -1827,6 +1846,7 @@ Mercury: ace_mode: prolog MiniD: # Legacy + type: programming searchable: false extensions: - .minid # Dummy extension @@ -1874,12 +1894,14 @@ MoonScript: ace_mode: text Myghty: + type: programming extensions: - .myt tm_scope: none ace_mode: text NSIS: + type: programming extensions: - .nsi - .nsh @@ -1971,6 +1993,7 @@ Nu: - nush NumPy: + type: programming group: Python extensions: - .numpy @@ -2430,6 +2453,7 @@ QML: ace_mode: text QMake: + type: programming extensions: - .pro - .pri @@ -2526,6 +2550,7 @@ Ragel in Ruby Host: ace_mode: text Raw token data: + type: data search_term: raw aliases: - raw @@ -2557,6 +2582,7 @@ Red: ace_mode: text Redcode: + type: programming extensions: - .cw tm_scope: none @@ -2843,6 +2869,7 @@ Smalltalk: ace_mode: text Smarty: + type: programming extensions: - .tpl ace_mode: smarty @@ -3266,6 +3293,7 @@ XQuery: ace_mode: xquery XS: + type: programming extensions: - .xs tm_scope: source.c @@ -3362,6 +3390,7 @@ fish: ace_mode: text mupad: + type: programming extensions: - .mu ace_mode: text From fecf0cc137c1e180d4318749cf1c267f84179792 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 22 Feb 2015 10:32:01 -0800 Subject: [PATCH 14/66] There is no "other" --- test/test_language.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/test_language.rb b/test/test_language.rb index e12b16b8..d347bb69 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -155,10 +155,6 @@ class TestLanguage < Minitest::Test assert_equal :prose, Language['Org'].type end - def test_other - assert_nil Language['Brainfuck'].type - end - def test_searchable assert Language['Ruby'].searchable? assert !Language['Gettext Catalog'].searchable? From e592381a5476825157fb9629d245e76f70140a7e Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sun, 22 Feb 2015 19:33:06 +0100 Subject: [PATCH 15/66] Support for .pro INI files (KiCad project files) Update the heuristic for .pro to include both INI and QMake files Fixes #2116 --- lib/linguist/heuristics.rb | 8 +++- lib/linguist/languages.yml | 1 + samples/INI/MouseKeyboard.pro | 71 +++++++++++++++++++++++++++++++++++ test/test_heuristics.rb | 10 +++-- 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 samples/INI/MouseKeyboard.pro diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index b82a5de4..b2a61bfa 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -107,10 +107,14 @@ module Linguist end end - disambiguate "IDL", "Prolog" do |data| + disambiguate "IDL", "Prolog", "INI", "QMake" do |data| if data.include?(":-") Language["Prolog"] - else + elsif data.include?("last_client=") + Language["INI"] + elsif data.include?("HEADERS") && data.include?("SOURCES") + Language["QMake"] + elsif /^\s*function[ \w,]+$/.match(data) Language["IDL"] end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0ac757f6..26cbe2c3 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1311,6 +1311,7 @@ INI: - .ini - .cfg - .prefs + - .pro - .properties tm_scope: source.ini aliases: diff --git a/samples/INI/MouseKeyboard.pro b/samples/INI/MouseKeyboard.pro new file mode 100644 index 00000000..0bc4ff8f --- /dev/null +++ b/samples/INI/MouseKeyboard.pro @@ -0,0 +1,71 @@ +update=Sun 15 Feb 2015 01:10:10 PM EST +last_client=eeschema +[pcbnew] +version=1 +PageLayoutDescrFile= +LastNetListRead= +UseCmpFile=1 +PadDrill=0.6 +PadDrillOvalY=0.6 +PadSizeH=1.5 +PadSizeV=1.5 +PcbTextSizeV=1.5 +PcbTextSizeH=1.5 +PcbTextThickness=0.3 +ModuleTextSizeV=1 +ModuleTextSizeH=1 +ModuleTextSizeThickness=0.15 +SolderMaskClearance=0 +SolderMaskMinWidth=0 +DrawSegmentWidth=0.2 +BoardOutlineThickness=0.09999999999999999 +ModuleOutlineThickness=0.15 +[pcbnew/libraries] +LibDir= +[general] +version=1 +[eeschema] +version=1 +PageLayoutDescrFile= +SubpartIdSeparator=0 +SubpartFirstId=65 +LibDir=/home/hschmale/KiCad/LibMods-3rdParty +NetFmtName= +RptD_X=0 +RptD_Y=100 +RptLab=1 +LabSize=60 +[eeschema/libraries] +LibName1=power +LibName2=device +LibName3=transistors +LibName4=conn +LibName5=linear +LibName6=regul +LibName7=74xx +LibName8=cmos4000 +LibName9=adc-dac +LibName10=memory +LibName11=xilinx +LibName12=special +LibName13=microcontrollers +LibName14=dsp +LibName15=microchip +LibName16=analog_switches +LibName17=motorola +LibName18=texas +LibName19=intel +LibName20=audio +LibName21=interface +LibName22=digital-audio +LibName23=philips +LibName24=display +LibName25=cypress +LibName26=siliconi +LibName27=opto +LibName28=atmel +LibName29=contrib +LibName30=valves +LibName31=arduino_shieldsNCL +LibName32=con-usb-2 +LibName33=2axispotwselect diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index cadb35f6..dcdf3328 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -60,11 +60,13 @@ class TestHeuristcs < Minitest::Test }) end - # Candidate languages = ["IDL", "Prolog"] - def test_pro_prolog_idl_by_heuristics + # Candidate languages = ["IDL", "Prolog", "QMake", "INI"] + def test_pro_by_heuristics assert_heuristics({ - "Prolog" => "Prolog/logic-problem.pro", - "IDL" => "IDL/mg_acosh.pro" + "Prolog" => all_fixtures("Prolog", "*.pro"), + "IDL" => all_fixtures("IDL", "*.pro"), + "INI" => all_fixtures("INI", "*.pro"), + "QMake" => all_fixtures("QMake", "*.pro") }) end From 05f73df064080a20630a33576766329c4f5999c3 Mon Sep 17 00:00:00 2001 From: CodingAnarchy Date: Fri, 20 Feb 2015 21:19:07 -0700 Subject: [PATCH 16/66] Brainfuck samples --- samples/Brainfuck/fib100.bf | 11 +++++++++++ samples/Brainfuck/hello.bf | 4 ++++ samples/Brainfuck/helloworld.bf | 3 +++ samples/Brainfuck/rot13.bf | 30 ++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 samples/Brainfuck/fib100.bf create mode 100644 samples/Brainfuck/hello.bf create mode 100644 samples/Brainfuck/helloworld.bf create mode 100644 samples/Brainfuck/rot13.bf diff --git a/samples/Brainfuck/fib100.bf b/samples/Brainfuck/fib100.bf new file mode 100644 index 00000000..fe3f3ce5 --- /dev/null +++ b/samples/Brainfuck/fib100.bf @@ -0,0 +1,11 @@ ++++++++++++ +>+>>>>++++++++++++++++++++++++++++++++++++++++++++ +>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+> ++<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[- +<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<< +-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]] +>[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++ ++++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++ +++++++++++++++++++++++++++++++++++++++++++++.[-]<< +<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<< +[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-] \ No newline at end of file diff --git a/samples/Brainfuck/hello.bf b/samples/Brainfuck/hello.bf new file mode 100644 index 00000000..6a93a155 --- /dev/null +++ b/samples/Brainfuck/hello.bf @@ -0,0 +1,4 @@ +// More complex version of hello world + +>++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.> +>+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++. \ No newline at end of file diff --git a/samples/Brainfuck/helloworld.bf b/samples/Brainfuck/helloworld.bf new file mode 100644 index 00000000..c7bde23a --- /dev/null +++ b/samples/Brainfuck/helloworld.bf @@ -0,0 +1,3 @@ +// Hello World + +++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. \ No newline at end of file diff --git a/samples/Brainfuck/rot13.bf b/samples/Brainfuck/rot13.bf new file mode 100644 index 00000000..3b9d8e7f --- /dev/null +++ b/samples/Brainfuck/rot13.bf @@ -0,0 +1,30 @@ +# ROT13 cipher + +-,+[ Read first character and start outer character reading loop + -[ Skip forward if character is 0 + >>++++[>++++++++<-] Set up divisor (32) for division loop + (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero) + <+<-[ Set up dividend (x minus 1) and enter division loop + >+>+>-[>>>] Increase copy and remainder / reduce divisor / Normal case: skip forward + <[[>+<-]>>+>] Special case: move remainder back to divisor and increase quotient + <<<<<- Decrement dividend + ] End division loop + ]>>>[-]+ End skip loop; zero former divisor and reuse space for a flag + >--[-[<->+++[-]]]<[ Zero that flag unless quotient was 2 or 3; zero quotient; check flag + ++++++++++++<[ If flag then set up divisor (13) for second division loop + (MEMORY LAYOUT: zero copy dividend divisor remainder quotient zero zero) + >-[>+>>] Reduce divisor; Normal case: increase remainder + >[+[<+>-]>+>>] Special case: increase remainder / move it back to divisor / increase quotient + <<<<<- Decrease dividend + ] End division loop + >>[<+>-] Add remainder back to divisor to get a useful 13 + >[ Skip forward if quotient was 0 + -[ Decrement quotient and skip forward if quotient was 1 + -<<[-]>> Zero quotient and divisor if quotient was 2 + ]<<[<<->>-]>> Zero divisor and subtract 13 from copy if quotient was 1 + ]<<[<<+>>-] Zero divisor and add 13 to copy if quotient was 0 + ] End outer skip loop (jump to here if ((character minus 1)/32) was not 2 or 3) + <[-] Clear remainder from first division if second division was skipped + <.[-] Output ROT13ed character from copy and clear it + <-,+ Read next character +] End character reading loop \ No newline at end of file From 525e886d79674bf58e21d8cf37219d95434ffa9e Mon Sep 17 00:00:00 2001 From: CodingAnarchy Date: Fri, 20 Feb 2015 21:19:54 -0700 Subject: [PATCH 17/66] Comments added to one sample --- samples/Brainfuck/fib100.bf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/Brainfuck/fib100.bf b/samples/Brainfuck/fib100.bf index fe3f3ce5..3359588a 100644 --- a/samples/Brainfuck/fib100.bf +++ b/samples/Brainfuck/fib100.bf @@ -1,3 +1,5 @@ +# Calculate and output all fibonacci numbers under 100 + +++++++++++ >+>>>>++++++++++++++++++++++++++++++++++++++++++++ >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+> From 6b26386a817cd758acf9d50373f49456266e799c Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 22 Feb 2015 20:21:02 -0800 Subject: [PATCH 18/66] Improve "no type found" error message --- test/test_language.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_language.rb b/test/test_language.rb index d347bb69..31be9a82 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -356,10 +356,10 @@ class TestLanguage < Minitest::Test def test_all_languages_have_type missing = Language.all.select { |language| language.type.nil? } - message = "The following languages' types are not listed in grammars.yml. Please add types for all new languages.\n" + message = "The following languages do not have a type listed in grammars.yml. Please add types for all new languages.\n" width = missing.map { |language| language.name.length }.max - message << missing.map { |language| sprintf("%-#{width}s %s", language.name, language.tm_scope) }.sort.join("\n") + message << missing.map { |language| sprintf("%-#{width}s", language.name) }.sort.join("\n") assert missing.empty?, message end From 2d15ea54cb61e98a6cc51e74690f5620b1ebe93b Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Sun, 22 Feb 2015 02:58:57 -0500 Subject: [PATCH 19/66] add support for Lean Theorem Prover --- .gitmodules | 3 ++ grammars.yml | 2 + lib/linguist/languages.yml | 7 ++++ samples/Lean/binary.lean | 75 +++++++++++++++++++++++++++++++++++ samples/Lean/set.hlean | 70 ++++++++++++++++++++++++++++++++ vendor/grammars/Lean.tmbundle | 1 + 6 files changed, 158 insertions(+) create mode 100644 samples/Lean/binary.lean create mode 100644 samples/Lean/set.hlean create mode 160000 vendor/grammars/Lean.tmbundle diff --git a/.gitmodules b/.gitmodules index 9fefaa4c..136013b2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -627,3 +627,6 @@ [submodule "vendor/grammars/sublime-text-pig-latin"] path = vendor/grammars/sublime-text-pig-latin url = https://github.com/goblindegook/sublime-text-pig-latin +[submodule "vendor/grammars/Lean.tmbundle"] + path = vendor/grammars/Lean.tmbundle + url = https://github.com/leanprover/Lean.tmbundle diff --git a/grammars.yml b/grammars.yml index 109f61cf..6d933a09 100644 --- a/grammars.yml +++ b/grammars.yml @@ -63,6 +63,8 @@ vendor/grammars/JSyntax/: - source.j vendor/grammars/Julia.tmbundle: - source.julia +vendor/grammars/Lean.tmbundle: +- source.lean vendor/grammars/LiveScript.tmbundle: - source.livescript vendor/grammars/Modelica/: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0ac757f6..c269bf93 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1588,6 +1588,13 @@ Latte: tm_scope: source.smarty ace_mode: smarty +Lean: + type: programming + extensions: + - .lean + - .hlean + ace_mode: text + Less: type: markup group: CSS diff --git a/samples/Lean/binary.lean b/samples/Lean/binary.lean new file mode 100644 index 00000000..060a8cb0 --- /dev/null +++ b/samples/Lean/binary.lean @@ -0,0 +1,75 @@ +/- +Copyright (c) 2014 Microsoft Corporation. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. + +Module: algebra.binary +Authors: Leonardo de Moura, Jeremy Avigad + +General properties of binary operations. +-/ + +import logic.eq +open eq.ops + +namespace binary + section + variable {A : Type} + variables (op₁ : A → A → A) (inv : A → A) (one : A) + + local notation a * b := op₁ a b + local notation a ⁻¹ := inv a + local notation 1 := one + + definition commutative := ∀a b, a * b = b * a + definition associative := ∀a b c, (a * b) * c = a * (b * c) + definition left_identity := ∀a, 1 * a = a + definition right_identity := ∀a, a * 1 = a + definition left_inverse := ∀a, a⁻¹ * a = 1 + definition right_inverse := ∀a, a * a⁻¹ = 1 + definition left_cancelative := ∀a b c, a * b = a * c → b = c + definition right_cancelative := ∀a b c, a * b = c * b → a = c + + definition inv_op_cancel_left := ∀a b, a⁻¹ * (a * b) = b + definition op_inv_cancel_left := ∀a b, a * (a⁻¹ * b) = b + definition inv_op_cancel_right := ∀a b, a * b⁻¹ * b = a + definition op_inv_cancel_right := ∀a b, a * b * b⁻¹ = a + + variable (op₂ : A → A → A) + + local notation a + b := op₂ a b + + definition left_distributive := ∀a b c, a * (b + c) = a * b + a * c + definition right_distributive := ∀a b c, (a + b) * c = a * c + b * c + end + + context + variable {A : Type} + variable {f : A → A → A} + variable H_comm : commutative f + variable H_assoc : associative f + infixl `*` := f + theorem left_comm : ∀a b c, a*(b*c) = b*(a*c) := + take a b c, calc + a*(b*c) = (a*b)*c : H_assoc + ... = (b*a)*c : H_comm + ... = b*(a*c) : H_assoc + + theorem right_comm : ∀a b c, (a*b)*c = (a*c)*b := + take a b c, calc + (a*b)*c = a*(b*c) : H_assoc + ... = a*(c*b) : H_comm + ... = (a*c)*b : H_assoc + end + + context + variable {A : Type} + variable {f : A → A → A} + variable H_assoc : associative f + infixl `*` := f + theorem assoc4helper (a b c d) : (a*b)*(c*d) = a*((b*c)*d) := + calc + (a*b)*(c*d) = a*(b*(c*d)) : H_assoc + ... = a*((b*c)*d) : H_assoc + end + +end binary diff --git a/samples/Lean/set.hlean b/samples/Lean/set.hlean new file mode 100644 index 00000000..761cd67d --- /dev/null +++ b/samples/Lean/set.hlean @@ -0,0 +1,70 @@ +-- Copyright (c) 2015 Jakob von Raumer. All rights reserved. +-- Released under Apache 2.0 license as described in the file LICENSE. +-- Authors: Jakob von Raumer +-- Category of sets + +import .basic types.pi trunc + +open truncation sigma sigma.ops pi function eq morphism precategory +open equiv + +namespace precategory + + universe variable l + + definition set_precategory : precategory.{l+1 l} (Σ (A : Type.{l}), is_hset A) := + begin + fapply precategory.mk.{l+1 l}, + intros, apply (a.1 → a_1.1), + intros, apply trunc_pi, intros, apply b.2, + intros, intro x, exact (a_1 (a_2 x)), + intros, exact (λ (x : a.1), x), + intros, apply funext.path_pi, intro x, apply idp, + intros, apply funext.path_pi, intro x, apply idp, + intros, apply funext.path_pi, intro x, apply idp, + end + +end precategory + +namespace category + + universe variable l + local attribute precategory.set_precategory.{l+1 l} [instance] + + definition set_category_equiv_iso (a b : (Σ (A : Type.{l}), is_hset A)) + : (a ≅ b) = (a.1 ≃ b.1) := + /-begin + apply ua, fapply equiv.mk, + intro H, + apply (isomorphic.rec_on H), intros (H1, H2), + apply (is_iso.rec_on H2), intros (H3, H4, H5), + fapply equiv.mk, + apply (isomorphic.rec_on H), intros (H1, H2), + exact H1, + fapply is_equiv.adjointify, exact H3, + exact sorry, + exact sorry, + end-/ sorry + + definition set_category : category.{l+1 l} (Σ (A : Type.{l}), is_hset A) := + /-begin + assert (C : precategory.{l+1 l} (Σ (A : Type.{l}), is_hset A)), + apply precategory.set_precategory, + apply category.mk, + assert (p : (λ A B p, (set_category_equiv_iso A B) ▹ iso_of_path p) = (λ A B p, @equiv_path A.1 B.1 p)), + apply is_equiv.adjointify, + intros, + apply (isomorphic.rec_on a_1), intros (iso', is_iso'), + apply (is_iso.rec_on is_iso'), intros (f', f'sect, f'retr), + fapply sigma.path, + apply ua, fapply equiv.mk, exact iso', + fapply is_equiv.adjointify, + exact f', + intros, apply (f'retr ▹ _), + intros, apply (f'sect ▹ _), + apply (@is_hprop.elim), + apply is_trunc_is_hprop, + intros, + end -/ sorry + +end category diff --git a/vendor/grammars/Lean.tmbundle b/vendor/grammars/Lean.tmbundle new file mode 160000 index 00000000..dc33b945 --- /dev/null +++ b/vendor/grammars/Lean.tmbundle @@ -0,0 +1 @@ +Subproject commit dc33b9450f71cb1cfb5b9b1ad53d5afd6f62fbef From c2e894c48c0f222e30b6a9e75520abfe153c65ec Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Tue, 24 Feb 2015 14:45:15 -0500 Subject: [PATCH 20/66] add ace-mode support for Lean --- 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 c269bf93..28c9a5a4 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1593,7 +1593,7 @@ Lean: extensions: - .lean - .hlean - ace_mode: text + ace_mode: lean Less: type: markup From fd7633518f1aff15eee5338fd6715fa2717341fe Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Wed, 25 Feb 2015 12:34:07 +1100 Subject: [PATCH 21/66] add instrumentation to detection and classification --- lib/linguist.rb | 12 ++++++++++++ lib/linguist/classifier.rb | 8 +++++--- lib/linguist/language.rb | 28 +++++++++++++++------------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/linguist.rb b/lib/linguist.rb index ff9fc3a2..4419ff5b 100644 --- a/lib/linguist.rb +++ b/lib/linguist.rb @@ -6,3 +6,15 @@ require 'linguist/repository' require 'linguist/samples' require 'linguist/shebang' require 'linguist/version' + +class << Linguist + attr_accessor :instrumenter + + def instrument(*args, &bk) + if instrumenter + instrumenter.instrument(*args, &bk) + else + yield + end + end +end diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index 89a0df2f..208467e4 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -16,9 +16,11 @@ module Linguist # # Returns an Array of Language objects, most probable first. def self.call(blob, possible_languages) - language_names = possible_languages.map(&:name) - classify(Samples.cache, blob.data, language_names).map do |name, _| - Language[name] # Return the actual Language objects + Linguist.instrument("linguist.bayesian_classification") do + language_names = possible_languages.map(&:name) + classify(Samples.cache, blob.data, language_names).map do |name, _| + Language[name] # Return the actual Language objects + end end end diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 2490a9f6..68b4c4fc 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -105,19 +105,21 @@ module Linguist # Bail early if the blob is binary or empty. return nil if blob.likely_binary? || blob.binary? || blob.empty? - # Call each strategy until one candidate is returned. - STRATEGIES.reduce([]) do |languages, strategy| - candidates = strategy.call(blob, languages) - if candidates.size == 1 - return candidates.first - elsif candidates.size > 1 - # More than one candidate was found, pass them to the next strategy. - candidates - else - # No candiates were found, pass on languages from the previous strategy. - languages - end - end.first + Linguist.instrument("linguist.detection") do + # Call each strategy until one candidate is returned. + STRATEGIES.reduce([]) do |languages, strategy| + candidates = strategy.call(blob, languages) + if candidates.size == 1 + return candidates.first + elsif candidates.size > 1 + # More than one candidate was found, pass them to the next strategy. + candidates + else + # No candiates were found, pass on languages from the previous strategy. + languages + end + end.first + end end # Public: Get all Languages From 71e0e2bc8e4c3f026823ac6699a34778ae1f0f23 Mon Sep 17 00:00:00 2001 From: Brandon Wamboldt Date: Tue, 24 Feb 2015 16:49:59 -0800 Subject: [PATCH 22/66] Use actual VCL syntax highlighting --- .gitmodules | 3 +++ grammars.yml | 2 ++ lib/linguist/languages.yml | 4 ++-- vendor/grammars/sublime-varnish | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) create mode 160000 vendor/grammars/sublime-varnish diff --git a/.gitmodules b/.gitmodules index 136013b2..25cb0da8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -630,3 +630,6 @@ [submodule "vendor/grammars/Lean.tmbundle"] path = vendor/grammars/Lean.tmbundle url = https://github.com/leanprover/Lean.tmbundle +[submodule "vendor/grammars/sublime-varnish"] + path = vendor/grammars/sublime-varnish + url = https://github.com/brandonwamboldt/sublime-varnish diff --git a/grammars.yml b/grammars.yml index 6d933a09..72ae874c 100644 --- a/grammars.yml +++ b/grammars.yml @@ -490,6 +490,8 @@ vendor/grammars/sublime-text-ox/: - source.ox vendor/grammars/sublime-text-pig-latin/: - source.pig_latin +vendor/grammars/sublime-varnish: +- source.varnish.vcl vendor/grammars/sublime_cobol: - source.acucobol - source.cobol diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 413683e5..124ea9f6 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3102,11 +3102,11 @@ UnrealScript: VCL: type: programming - ace_mode: perl color: "#0298c3" extensions: - .vcl - tm_scope: source.perl + tm_scope: source.varnish.vcl + ace_mode: text VHDL: type: programming diff --git a/vendor/grammars/sublime-varnish b/vendor/grammars/sublime-varnish new file mode 160000 index 00000000..9f0710bc --- /dev/null +++ b/vendor/grammars/sublime-varnish @@ -0,0 +1 @@ +Subproject commit 9f0710bc4ea5f2915a2ff9c34977a57904a4a0c6 From 649a5987e73fe0e87f03df1fd1eb20156a10cf27 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Wed, 25 Feb 2015 08:49:07 -0500 Subject: [PATCH 23/66] Issue #2140: Note that only modelines control syntax highlighting. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a2447a9..8e3781ad 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Linguist supports a number of different custom overrides strategies for language ### Using gitattributes -Add a `.gitattributes` file to your project and use standard git-style path matchers for the files you want to override to set `linguist-documentation`, `linguist-language`, and `linguist-vendored`. +Add a `.gitattributes` file to your project and use standard git-style path matchers for the files you want to override to set `linguist-documentation`, `linguist-language`, and `linguist-vendored`. `.gitattributes` will be used to determine language stats, but will not be used to syntax highlight files. To manually set syntax highlighting, use [Vim or Emacs modelines](#using-emacs-and-vim-modelines). ``` $ cat .gitattributes From 2e1161e061e03111e9167fb6c037463846d34f5a Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 25 Feb 2015 15:14:34 +0100 Subject: [PATCH 24/66] Add sample XS file --- samples/XS/CommonMark.xs | 466 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 466 insertions(+) create mode 100644 samples/XS/CommonMark.xs diff --git a/samples/XS/CommonMark.xs b/samples/XS/CommonMark.xs new file mode 100644 index 00000000..6a0e321e --- /dev/null +++ b/samples/XS/CommonMark.xs @@ -0,0 +1,466 @@ +/* + * This software is copyright (C) by Nick Wellnhofer . + * + * This is free software; you can redistribute it and/or modify it under + * the same terms as the Perl 5 programming language system itself. + * + * Terms of the Perl programming language system itself + * + * a) the GNU General Public License as published by the Free + * Software Foundation; either version 1, or (at your option) any + * later version, or + * b) the "Artistic License" + */ + +/* + * Notes on memory management + * + * - A pointer to the Perl SV representing a node is stored in the + * user data slot of `struct cmark_node`, so there's a 1:1 mapping + * between Perl and C objects. + * - Every node SV keeps a reference to the parent SV. This is done + * indirectly by looking up the parent SV and increasing its refcount. + * - This makes sure that a document isn't freed if the last reference + * from Perl to the root node is dropped, as references to child nodes + * might still exist. + * - As a consequence, as long as a node is referenced from Perl, all its + * ancestor nodes will also be associated with a Perl object. + */ + +#define PERL_NO_GET_CONTEXT + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include +#include + +#if CMARK_VERSION < 0x001000 + #error libcmark 0.16.0 is required. +#endif + +/* Fix prefixes of render functions. */ +#define cmark_node_render_html cmark_render_html +#define cmark_node_render_xml cmark_render_xml +#define cmark_node_render_man cmark_render_man + +static SV* +S_create_or_incref_node_sv(pTHX_ cmark_node *node) { + SV *new_obj = NULL; + + while (node) { + SV *obj; + HV *stash; + + /* Look for existing object. */ + obj = (SV*)cmark_node_get_user_data(node); + + if (obj) { + /* Incref if found. */ + SvREFCNT_inc_simple_void_NN(obj); + if (!new_obj) { + new_obj = obj; + } + break; + } + + /* Create a new SV. */ + obj = newSViv(PTR2IV(node)); + cmark_node_set_user_data(node, obj); + if (!new_obj) { + new_obj = obj; + } + + /* + * Unfortunately, Perl doesn't offer an API function to bless an SV + * without a reference. The following code is mostly copied from + * sv_bless. + */ + SvOBJECT_on(obj); +#if (PERL_VERSION <= 16) + PL_sv_objcount++; +#endif + SvUPGRADE(obj, SVt_PVMG); + stash = gv_stashpvn("CommonMark::Node", 16, GV_ADD); + SvSTASH_set(obj, (HV*)SvREFCNT_inc(stash)); + + /* Recurse into parent. */ + node = cmark_node_parent(node); + } + + return new_obj; +} + +static void +S_decref_node_sv(pTHX_ cmark_node *node) { + SV *obj; + + if (!node) { + return; + } + + obj = (SV*)cmark_node_get_user_data(node); + if (!obj) { + /* Should never happen. */ + croak("Internal error: node SV not found"); + } + + SvREFCNT_dec_NN(obj); +} + +/* Find or create an SV for a cmark_node. */ +static SV* +S_node2sv(pTHX_ cmark_node *node) { + SV *obj; + + if (!node) { + return &PL_sv_undef; + } + + obj = S_create_or_incref_node_sv(aTHX_ node); + + return newRV_noinc(obj); +} + +/* Transfer refcount from a node to another. */ +static void +S_transfer_refcount(pTHX_ cmark_node *from, cmark_node *to) { + if (from != to) { + S_create_or_incref_node_sv(aTHX_ to); + S_decref_node_sv(aTHX_ from); + } +} + +/* Get C struct pointer from an SV argument. */ +static void* +S_sv2c(pTHX_ SV *sv, const char *class_name, STRLEN len, CV *cv, + const char *var_name) { + if (!SvROK(sv) || !sv_derived_from_pvn(sv, class_name, len, 0)) { + const char *sub_name = GvNAME(CvGV(cv)); + croak("%s: %s is not of type %s", sub_name, var_name, class_name); + } + return INT2PTR(void*, SvIV(SvRV(sv))); +} + + +MODULE = CommonMark PACKAGE = CommonMark PREFIX = cmark_ + +PROTOTYPES: DISABLE + +BOOT: + if (cmark_version != CMARK_VERSION) { + warn("Compiled against libcmark %s, but runtime version is %s", + CMARK_VERSION_STRING, cmark_version_string); + } + +char* +cmark_markdown_to_html(package, string) + SV *package = NO_INIT + SV *string +PREINIT: + STRLEN len; + const char *buffer; +CODE: + (void)package; + buffer = SvPVutf8(string, len); + RETVAL = cmark_markdown_to_html(buffer, len); +OUTPUT: + RETVAL + +cmark_node* +cmark_parse_document(package, string) + SV *package = NO_INIT + SV *string +PREINIT: + STRLEN len; + const char *buffer; +CODE: + (void)package; + buffer = SvPVutf8(string, len); + RETVAL = cmark_parse_document(buffer, len); +OUTPUT: + RETVAL + +cmark_node* +cmark_parse_file(package, file) + SV *package = NO_INIT + SV *file +PREINIT: + PerlIO *perl_io; + FILE *stream = NULL; +CODE: + (void)package; + perl_io = IoIFP(sv_2io(file)); + if (perl_io) { + stream = PerlIO_findFILE(perl_io); + } + if (!stream) { + croak("parse_file: file is not a file handle"); + } + RETVAL = cmark_parse_file(stream); +OUTPUT: + RETVAL + +int +cmark_version(package) + SV *package = NO_INIT +CODE: + (void)package; + RETVAL = cmark_version; +OUTPUT: + RETVAL + +const char* +cmark_version_string(package) + SV *package = NO_INIT +CODE: + (void)package; + RETVAL = cmark_version_string; +OUTPUT: + RETVAL + +int +cmark_compile_time_version(package) + SV *package = NO_INIT +CODE: + (void)package; + RETVAL = CMARK_VERSION; +OUTPUT: + RETVAL + +const char* +cmark_compile_time_version_string(package) + SV *package = NO_INIT +CODE: + (void)package; + RETVAL = CMARK_VERSION_STRING; +OUTPUT: + RETVAL + + +MODULE = CommonMark PACKAGE = CommonMark::Node PREFIX = cmark_node_ + +cmark_node* +new(package, type) + SV *package = NO_INIT + cmark_node_type type +CODE: + (void)package; + RETVAL = cmark_node_new(type); +OUTPUT: + RETVAL + +void +DESTROY(cmark_node *node) +CODE: + cmark_node *parent = cmark_node_parent(node); + if (parent) { + cmark_node_set_user_data(node, NULL); + S_decref_node_sv(aTHX_ parent); + } + else { + cmark_node_free(node); + } + +cmark_iter* +iterator(cmark_node *node) +CODE: + S_create_or_incref_node_sv(aTHX_ node); + RETVAL = cmark_iter_new(node); +OUTPUT: + RETVAL + +cmark_node* +interface_get_node(cmark_node *node) +INTERFACE: + cmark_node_next + cmark_node_previous + cmark_node_parent + cmark_node_first_child + cmark_node_last_child + +int +interface_get_int(cmark_node *node) +INTERFACE: + cmark_node_get_type + cmark_node_get_header_level + cmark_node_get_list_type + cmark_node_get_list_delim + cmark_node_get_list_start + cmark_node_get_list_tight + cmark_node_get_start_line + cmark_node_get_start_column + cmark_node_get_end_line + cmark_node_get_end_column + +NO_OUTPUT int +interface_set_int(cmark_node *node, int value) +INTERFACE: + cmark_node_set_header_level + cmark_node_set_list_type + cmark_node_set_list_delim + cmark_node_set_list_start + cmark_node_set_list_tight +POSTCALL: + if (!RETVAL) { + croak("%s: invalid operation", GvNAME(CvGV(cv))); + } + +const char* +interface_get_utf8(cmark_node *node) +INTERFACE: + cmark_node_get_type_string + cmark_node_get_literal + cmark_node_get_title + cmark_node_get_url + cmark_node_get_fence_info + +NO_OUTPUT int +interface_set_utf8(cmark_node *node, const char *value) +INTERFACE: + cmark_node_set_literal + cmark_node_set_title + cmark_node_set_url + cmark_node_set_fence_info +POSTCALL: + if (!RETVAL) { + croak("%s: invalid operation", GvNAME(CvGV(cv))); + } + +void +cmark_node_unlink(cmark_node *node) +PREINIT: + cmark_node *old_parent; +INIT: + old_parent = cmark_node_parent(node); +POSTCALL: + S_decref_node_sv(aTHX_ old_parent); + +NO_OUTPUT int +interface_move_node(cmark_node *node, cmark_node *other) +PREINIT: + cmark_node *old_parent; + cmark_node *new_parent; +INIT: + old_parent = cmark_node_parent(other); +INTERFACE: + cmark_node_insert_before + cmark_node_insert_after + cmark_node_prepend_child + cmark_node_append_child +POSTCALL: + if (!RETVAL) { + croak("%s: invalid operation", GvNAME(CvGV(cv))); + } + new_parent = cmark_node_parent(other); + S_transfer_refcount(aTHX_ old_parent, new_parent); + +char* +interface_render(cmark_node *root, long options = 0) +INTERFACE: + cmark_node_render_html + cmark_node_render_xml + cmark_node_render_man + + +MODULE = CommonMark PACKAGE = CommonMark::Iterator PREFIX = cmark_iter_ + +void +DESTROY(cmark_iter *iter) +CODE: + S_decref_node_sv(aTHX_ cmark_iter_get_node(iter)); + S_decref_node_sv(aTHX_ cmark_iter_get_root(iter)); + cmark_iter_free(iter); + +void +cmark_iter_next(cmark_iter *iter) +PREINIT: + I32 gimme; + cmark_node *old_node; + cmark_event_type ev_type; +PPCODE: + gimme = GIMME_V; + old_node = cmark_iter_get_node(iter); + ev_type = cmark_iter_next(iter); + + if (ev_type != CMARK_EVENT_DONE) { + cmark_node *node = cmark_iter_get_node(iter); + + ST(0) = sv_2mortal(newSViv((IV)ev_type)); + + if (gimme == G_ARRAY) { + SV *obj = S_create_or_incref_node_sv(aTHX_ node); + + /* A bit more efficient than S_transfer_refcount. */ + if (old_node != node) { + S_decref_node_sv(aTHX_ old_node); + SvREFCNT_inc_simple_void_NN(obj); + } + + ST(1) = sv_2mortal(newRV_noinc(obj)); + XSRETURN(2); + } + else { + S_transfer_refcount(aTHX_ old_node, node); + XSRETURN(1); + } + } + else { + S_decref_node_sv(aTHX_ old_node); + + if (gimme == G_ARRAY) { + XSRETURN_EMPTY; + } + else { + ST(0) = sv_2mortal(newSViv((IV)ev_type)); + XSRETURN(1); + } + } + +cmark_node* +cmark_iter_get_node(cmark_iter *iter) + +cmark_event_type +cmark_iter_get_event_type(cmark_iter *iter) + +void +cmark_iter_reset(iter, node, event_type) + cmark_iter *iter + cmark_node *node + cmark_event_type event_type +PREINIT: + cmark_node *old_node; +INIT: + old_node = cmark_iter_get_node(iter); + S_transfer_refcount(aTHX_ old_node, node); + + +MODULE = CommonMark PACKAGE = CommonMark::Parser PREFIX = cmark_parser_ + +cmark_parser* +cmark_parser_new(package) + SV *package = NO_INIT +CODE: + (void)package; + RETVAL = cmark_parser_new(); +OUTPUT: + RETVAL + +void +DESTROY(cmark_parser *parser) +CODE: + cmark_parser_free(parser); + +void +cmark_parser_feed(cmark_parser *parser, SV *string) +PREINIT: + STRLEN len; + const char *buffer; +CODE: + buffer = SvPVutf8(string, len); + cmark_parser_feed(parser, buffer, len); + +cmark_node* +cmark_parser_finish(cmark_parser *parser) + From 739b512ceef87f1255a2acb20e850e80f6d5f602 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Wed, 25 Feb 2015 08:18:45 -0600 Subject: [PATCH 25/66] Prefer 'statistics' --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e3781ad..9df9f6fe 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Linguist supports a number of different custom overrides strategies for language ### Using gitattributes -Add a `.gitattributes` file to your project and use standard git-style path matchers for the files you want to override to set `linguist-documentation`, `linguist-language`, and `linguist-vendored`. `.gitattributes` will be used to determine language stats, but will not be used to syntax highlight files. To manually set syntax highlighting, use [Vim or Emacs modelines](#using-emacs-and-vim-modelines). +Add a `.gitattributes` file to your project and use standard git-style path matchers for the files you want to override to set `linguist-documentation`, `linguist-language`, and `linguist-vendored`. `.gitattributes` will be used to determine language statistics, but will not be used to syntax highlight files. To manually set syntax highlighting, use [Vim or Emacs modelines](#using-emacs-and-vim-modelines). ``` $ cat .gitattributes From e791a7156686e5567c22543366918616b3f7f6c0 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Mon, 16 Feb 2015 19:20:06 +0100 Subject: [PATCH 26/66] Add DTrace and Makefile dependency includes. Sample file mpq.d by Georg Lukas; license GPL 2. Sample file counts.d by Kate Turner; public domain. Sample file javascript-race.d by unknown; license MPL 1.1/GPL 2.0/LGPL 2.1. Sample file probes.d by momjian; license TBD. --- lib/linguist/heuristics.rb | 10 + lib/linguist/languages.yml | 10 + samples/D/mpq.d | 318 ++++++++++++++++++++++++++++++ samples/DTrace/counts.d | 23 +++ samples/DTrace/javascript-trace.d | 73 +++++++ samples/DTrace/probes.d | 93 +++++++++ samples/Makefile/foo.o.d | 5 + 7 files changed, 532 insertions(+) create mode 100644 samples/D/mpq.d create mode 100644 samples/DTrace/counts.d create mode 100644 samples/DTrace/javascript-trace.d create mode 100644 samples/DTrace/probes.d create mode 100644 samples/Makefile/foo.o.d diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index b82a5de4..58766ecc 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -229,5 +229,15 @@ module Linguist Language["Text"] end end + + disambiguate "D", "DTrace", "Makefile" do |data| + if /^module /.match(data) + Language["D"] + elsif /^((dtrace:::)?BEGIN|provider |#pragma (D (option|attributes)|ident)\s)/.match(data) + Language["DTrace"] + elsif /(\/.*:( .* \\)$| : \\$|^ : |: \\$)/.match(data) + Language["Makefile"] + end + end end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 413683e5..47df1cde 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -704,6 +704,15 @@ DM: tm_scope: source.c++ ace_mode: c_cpp +DTrace: + type: programming + extensions: + - .d + interpreters: + - dtrace + tm_scope: source.c + ace_mode: c_cpp + Darcs Patch: type: programming search_term: dpatch @@ -1753,6 +1762,7 @@ Makefile: - mf extensions: - .mak + - .d - .mk filenames: - GNUmakefile diff --git a/samples/D/mpq.d b/samples/D/mpq.d new file mode 100644 index 00000000..d72c2d2a --- /dev/null +++ b/samples/D/mpq.d @@ -0,0 +1,318 @@ +/* + * mpq.d -- D programming language module for libmpq + * + * Copyright (c) 2008 Georg Lukas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * This module is written to support Phobos. Patches to allow binding to + * Tango are welcome. + */ + +module mpq; + +/* the following pragma does not work on DMD/Linux, generates a warning on + * GDC/Linux and has not been tested on Windows. Commented out for now. */ +// pragma(lib, "libmpq"); + +import std.string; // for format() and toStringz() +import std.traits; // for ParameterTypeTuple!() + +/* XXX: this assumes that libmpq is compiled with Large File Support on */ +alias long off_t; + +/* libmpq error return values */ +const LIBMPQ_ERROR_OPEN = -1; /* open error on file. */ +const LIBMPQ_ERROR_CLOSE = -2; /* close error on file. */ +const LIBMPQ_ERROR_SEEK = -3; /* lseek error on file. */ +const LIBMPQ_ERROR_READ = -4; /* read error on file. */ +const LIBMPQ_ERROR_WRITE = -5; /* write error on file. */ +const LIBMPQ_ERROR_MALLOC = -6; /* memory allocation error. */ +const LIBMPQ_ERROR_FORMAT = -7; /* format errror. */ +const LIBMPQ_ERROR_NOT_INITIALIZED = -8; /* init() wasn't called. */ +const LIBMPQ_ERROR_SIZE = -9; /* buffer size is to small. */ +const LIBMPQ_ERROR_EXIST = -10; /* file or block does not exist in archive. */ +const LIBMPQ_ERROR_DECRYPT = -11; /* we don't know the decryption seed. */ +const LIBMPQ_ERROR_UNPACK = -12; /* error on unpacking file. */ + +/** libmpq internal meta-data for an archive */ +extern struct mpq_archive_s; + +extern(C) { + +/* libmpq__generic information about library. */ +char *libmpq__version(); + +/* libmpq__generic mpq archive information. */ +int libmpq__archive_open(mpq_archive_s **mpq_archive, char *mpq_filename, off_t archive_offset); +int libmpq__archive_close(mpq_archive_s *mpq_archive); +int libmpq__archive_packed_size(mpq_archive_s *mpq_archive, off_t *packed_size); +int libmpq__archive_unpacked_size(mpq_archive_s *mpq_archive, off_t *unpacked_size); +int libmpq__archive_offset(mpq_archive_s *mpq_archive, off_t *offset); +int libmpq__archive_version(mpq_archive_s *mpq_archive, uint *version_); +int libmpq__archive_files(mpq_archive_s *mpq_archive, uint *files); + +/* libmpq__generic file processing functions. */ +int libmpq__file_packed_size(mpq_archive_s *mpq_archive, uint file_number, off_t *packed_size); +int libmpq__file_unpacked_size(mpq_archive_s *mpq_archive, uint file_number, off_t *unpacked_size); +int libmpq__file_offset(mpq_archive_s *mpq_archive, uint file_number, off_t *offset); +int libmpq__file_blocks(mpq_archive_s *mpq_archive, uint file_number, uint *blocks); +int libmpq__file_encrypted(mpq_archive_s *mpq_archive, uint file_number, uint *encrypted); +int libmpq__file_compressed(mpq_archive_s *mpq_archive, uint file_number, uint *compressed); +int libmpq__file_imploded(mpq_archive_s *mpq_archive, uint file_number, uint *imploded); +int libmpq__file_number(mpq_archive_s *mpq_archive, char *filename, uint *number); +int libmpq__file_read(mpq_archive_s *mpq_archive, uint file_number, ubyte *out_buf, off_t out_size, off_t *transferred); + +/* libmpq__generic block processing functions. */ +int libmpq__block_open_offset(mpq_archive_s *mpq_archive, uint file_number); +int libmpq__block_close_offset(mpq_archive_s *mpq_archive, uint file_number); +int libmpq__block_unpacked_size(mpq_archive_s *mpq_archive, uint file_number, uint block_number, off_t *unpacked_size); +int libmpq__block_read(mpq_archive_s *mpq_archive, uint file_number, uint block_number, ubyte *out_buf, off_t out_size, off_t *transferred); + +} + + +/** exception class for failed libmpq calls */ +class MPQException : Exception { + const string[] Errors = [ + "unknown error", + "open error on file", + "close error on file", + "lseek error on file", + "read error on file", + "write error on file", + "memory allocation error", + "format errror", + "init() wasn't called", + "buffer size is to small", + "file or block does not exist in archive", + "we don't know the decryption seed", + "error on unpacking file"]; + + public int errno; + this(char[] fnname = "unknown_function", int errno = 0) { + + this.errno = errno; + if (-errno >= Errors.length) + errno = 0; + super(std.string.format("Error in %s(): %s (%d)", + fnname, Errors[-errno], errno)); + } +} + + +/** template to wrap function calls and throw exceptions in case of error + * + * thanks for the idea to while(nan) blog, + * http://while-nan.blogspot.com/2007/06/wrapping-functions-for-fun-and-profit.html + * + * use: MPQ_CHECKERR(libmpq__archive_open)(&m, "foo.mpq", -1); + * returns the retval of archive_open on success; + * throws an MPQException on failure. + * + * @param Fn libmpq__function reference + * @param args libmpq__function parameters + * @return return value of libmpq__function on success + * @throw MPQException on error + */ +int MPQ_CHECKERR(alias Fn)(ParameterTypeTuple!(Fn) args) +{ + int result = Fn(args); + if (result < 0) { + /* XXX: relying on non-specified stringof() behaviour */ + throw new MPQException((&Fn).stringof[2..$], result); + } + return result; +} + + +/** mixin alias to wrap library functions into MPQ_CHECKERR. + * + * alias mpq.func_name(...) to MPQ_CHECKERR(libmpq__func_name)(...) + * @param func_name name of the function to be wrapped + */ +template MPQ_FUNC(char[] func_name) { + const char[] MPQ_FUNC = "alias MPQ_CHECKERR!(libmpq__" ~ func_name ~ ") " ~ func_name ~ ";"; +} + +alias libmpq__version libversion; /* must be direct alias because it returns char*, not error int */ +mixin(MPQ_FUNC!("archive_open")); +mixin(MPQ_FUNC!("archive_close")); +mixin(MPQ_FUNC!("archive_packed_size")); +mixin(MPQ_FUNC!("archive_unpacked_size")); +mixin(MPQ_FUNC!("archive_offset")); +mixin(MPQ_FUNC!("archive_version")); +mixin(MPQ_FUNC!("archive_files")); +mixin(MPQ_FUNC!("file_packed_size")); +mixin(MPQ_FUNC!("file_unpacked_size")); +mixin(MPQ_FUNC!("file_offset")); +mixin(MPQ_FUNC!("file_blocks")); +mixin(MPQ_FUNC!("file_encrypted")); +mixin(MPQ_FUNC!("file_compressed")); +mixin(MPQ_FUNC!("file_imploded")); +mixin(MPQ_FUNC!("file_number")); +mixin(MPQ_FUNC!("file_read")); +mixin(MPQ_FUNC!("block_open_offset")); +mixin(MPQ_FUNC!("block_close_offset")); +mixin(MPQ_FUNC!("block_unpacked_size")); +mixin(MPQ_FUNC!("block_read")); + +/** getter function named name for returning archive_* single values: + * + * Archive.() { return libmpq__archive_() } + * + * @param type return type for the original function reference + * @param name name of the original function + * @param name2 name for the prototype (defaults to name, used for "version") + * @return getter function mixin + */ +template MPQ_A_GET(char[] type, char[] name, char[] name2 = name) { + const char[] MPQ_A_GET = type ~ " " ~ name2 ~ "() { " ~ + type ~ " ret; " ~ + "archive_" ~ name ~ "(m, &ret); return ret;" ~ + "}"; +} + +/** wrapper class for an MPQ Archive + * + * syntax: auto a = new mpq.Archive("somefile.mpq"); + */ +class Archive { + mpq_archive_s *m; + File listfile; + char[][] listfiledata; + + this(char[] archivename, off_t offset = -1) { + archive_open(&m, toStringz(archivename), offset); + } + + mixin(MPQ_A_GET!("off_t", "packed_size")); + mixin(MPQ_A_GET!("off_t", "unpacked_size")); + mixin(MPQ_A_GET!("off_t", "offset")); + mixin(MPQ_A_GET!("uint", "version", "version_")); + mixin(MPQ_A_GET!("uint", "files")); + + ~this() { + archive_close(m); + } + + mpq_archive_s* archive() { + return m; + } + + File opIndex(char[] fname) { + return new File(this, fname); + } + File opIndex(int fno) { + return new File(this, fno); + } + + char[][] filelist() { + try { + if (!listfile) { + listfile = this["(listfile)"]; + listfiledata = (cast(char[])listfile.read()).splitlines(); + } + return listfiledata; + } catch (MPQException e) { + return []; + } + } + + /+uint filenumber(char[] filename) { + try { + if (!listfile) { + listfile = this["(listfile)"]; + listfiledata = (cast(char[])listfile.read()).splitlines(); + } + return listfiledata; + } catch (MPQException e) { + return []; + } + }+/ + +} + + +/** getter function named name for returning file_* single values: + * + * File.() { return libmpq__file_() } + * + * @param type return type for the original function reference + * @param name name of the original function + * @param name2 name for the prototype (defaults to name, used for "version") + * @return getter function mixin + */ +template MPQ_F_GET(char[] type, char[] name, char[] name2 = name) { + const char[] MPQ_F_GET = type ~ " " ~ name2 ~ "() { " ~ + type ~ " ret; " ~ + "file_" ~ name ~ "(am, fileno, &ret); " ~ + "return ret;" ~ + "}"; +} + +/** wrapper class for a single file in an MPQ Archive + * + * syntax: + * auto a = new mpq.Archive("somefile.mpq"); + * auto f = a["(listfile)"]; + * auto f2 = a[0]; + * auto f3 = new File(a, "(listfile)"); + */ +class File { + Archive a; + mpq_archive_s* am; + char[] filename; + uint fileno; + + this(Archive a, int fileno) { + this.a = a; + this.am = a.archive(); + if (fileno >= a.files) { + throw new MPQException(format("File(%d)", fileno), + LIBMPQ_ERROR_EXIST); + } + this.filename = format("file%04d.xxx", fileno); + this.fileno = fileno; + } + + this(Archive a, char[] filename) { + this.a = a; + this.am = a.archive(); + this.filename = filename; + /* this line will throw an exception when the file is not there */ + mpq.file_number(am, toStringz(filename), &this.fileno); + } + + mixin(MPQ_F_GET!("off_t", "packed_size")); + mixin(MPQ_F_GET!("off_t", "unpacked_size")); + mixin(MPQ_F_GET!("off_t", "offset")); + mixin(MPQ_F_GET!("uint", "blocks")); + mixin(MPQ_F_GET!("uint", "encrypted")); + mixin(MPQ_F_GET!("uint", "compressed")); + mixin(MPQ_F_GET!("uint", "imploded")); + + uint no() { return fileno; } + char[] name() { return filename; } + + ubyte[] read() { + ubyte[] content; + content.length = this.unpacked_size(); + off_t trans; + mpq.file_read(am, fileno, content.ptr, content.length, &trans); + content.length = trans; + return content; + } +} diff --git a/samples/DTrace/counts.d b/samples/DTrace/counts.d new file mode 100644 index 00000000..13725d99 --- /dev/null +++ b/samples/DTrace/counts.d @@ -0,0 +1,23 @@ +/* + * This software is in the public domain. + * + * $Id: counts.d 10510 2005-08-15 01:46:19Z kateturner $ + */ + +#pragma D option quiet + +self int tottime; +BEGIN { + tottime = timestamp; +} + +php$target:::function-entry + @counts[copyinstr(arg0)] = count(); +} + +END { + printf("Total time: %dus\n", (timestamp - tottime) / 1000); + printf("# calls by function:\n"); + printa("%-40s %@d\n", @counts); +} + diff --git a/samples/DTrace/javascript-trace.d b/samples/DTrace/javascript-trace.d new file mode 100644 index 00000000..258c6cd2 --- /dev/null +++ b/samples/DTrace/javascript-trace.d @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Copyright (C) 2007 Sun Microsystems, Inc. All Rights Reserved. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* + * javascript provider probes + * + * function-entry (filename, classname, funcname) + * function-info (filename, classname, funcname, lineno, + * runfilename, runlineno) + * function-args (filename, classname, funcname, argc, argv, argv0, + * argv1, argv2, argv3, argv4) + * function-rval (filename, classname, funcname, lineno, rval, rval0) + * function-return (filename, classname, funcname) + * object-create-start (filename, classname) + * object-create (filename, classname, *object, rlineno) + * object-create-done (filename, classname) + * object-finalize (NULL, classname, *object) + * execute-start (filename, lineno) + * execute-done (filename, lineno) + */ + +provider javascript { + probe function__entry(char *, char *, char *); + probe function__info(char *, char *, char *, int, char *, int); + probe function__args(char *, char *, char *, int, void *, void *, void *, + void *, void *, void *); + probe function__rval(char *, char *, char *, int, void *, void *); + probe function__return(char *, char *, char *); + probe object__create__start(char *, char *); + probe object__create__done(char *, char *); + /* XXX must use unsigned longs here instead of uintptr_t for OS X + (Apple radar: 5194316 & 5565198) */ + probe object__create(char *, char *, unsigned long, int); + probe object__finalize(char *, char *, unsigned long); + probe execute__start(char *, int); + probe execute__done(char *, int); +}; + +/* +#pragma D attributes Unstable/Unstable/Common provider mozilla provider +#pragma D attributes Private/Private/Unknown provider mozilla module +#pragma D attributes Private/Private/Unknown provider mozilla function +#pragma D attributes Unstable/Unstable/Common provider mozilla name +#pragma D attributes Unstable/Unstable/Common provider mozilla args +*/ + diff --git a/samples/DTrace/probes.d b/samples/DTrace/probes.d new file mode 100644 index 00000000..483f174d --- /dev/null +++ b/samples/DTrace/probes.d @@ -0,0 +1,93 @@ +/* ---------- + * DTrace probes for PostgreSQL backend + * + * Copyright (c) 2006-2009, PostgreSQL Global Development Group + * + * $PostgreSQL: pgsql/src/backend/utils/probes.d,v 1.11 2009/04/02 20:59:10 momjian Exp $ + * ---------- + */ + + +/* + * Typedefs used in PostgreSQL. + * + * NOTE: Do not use system-provided typedefs (e.g. uintptr_t, uint32_t, etc) + * in probe definitions, as they cause compilation errors on Mac OS X 10.5. + */ +#define LocalTransactionId unsigned int +#define LWLockId int +#define LWLockMode int +#define LOCKMODE int +#define BlockNumber unsigned int +#define Oid unsigned int +#define ForkNumber int +#define bool char + +provider postgresql { + + probe transaction__start(LocalTransactionId); + probe transaction__commit(LocalTransactionId); + probe transaction__abort(LocalTransactionId); + + probe lwlock__acquire(LWLockId, LWLockMode); + probe lwlock__release(LWLockId); + probe lwlock__wait__start(LWLockId, LWLockMode); + probe lwlock__wait__done(LWLockId, LWLockMode); + probe lwlock__condacquire(LWLockId, LWLockMode); + probe lwlock__condacquire__fail(LWLockId, LWLockMode); + + probe lock__wait__start(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE); + probe lock__wait__done(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, LOCKMODE); + + probe query__parse__start(const char *); + probe query__parse__done(const char *); + probe query__rewrite__start(const char *); + probe query__rewrite__done(const char *); + probe query__plan__start(); + probe query__plan__done(); + probe query__execute__start(); + probe query__execute__done(); + probe query__start(const char *); + probe query__done(const char *); + probe statement__status(const char *); + + probe sort__start(int, bool, int, int, bool); + probe sort__done(bool, long); + + probe buffer__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid, bool, bool); + probe buffer__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, bool, bool, bool); + probe buffer__flush__start(ForkNumber, BlockNumber, Oid, Oid, Oid); + probe buffer__flush__done(ForkNumber, BlockNumber, Oid, Oid, Oid); + + probe buffer__checkpoint__start(int); + probe buffer__checkpoint__sync__start(); + probe buffer__checkpoint__done(); + probe buffer__sync__start(int, int); + probe buffer__sync__written(int); + probe buffer__sync__done(int, int, int); + probe buffer__write__dirty__start(ForkNumber, BlockNumber, Oid, Oid, Oid); + probe buffer__write__dirty__done(ForkNumber, BlockNumber, Oid, Oid, Oid); + + probe deadlock__found(); + + probe checkpoint__start(int); + probe checkpoint__done(int, int, int, int, int); + probe clog__checkpoint__start(bool); + probe clog__checkpoint__done(bool); + probe subtrans__checkpoint__start(bool); + probe subtrans__checkpoint__done(bool); + probe multixact__checkpoint__start(bool); + probe multixact__checkpoint__done(bool); + probe twophase__checkpoint__start(); + probe twophase__checkpoint__done(); + + probe smgr__md__read__start(ForkNumber, BlockNumber, Oid, Oid, Oid); + probe smgr__md__read__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int); + probe smgr__md__write__start(ForkNumber, BlockNumber, Oid, Oid, Oid); + probe smgr__md__write__done(ForkNumber, BlockNumber, Oid, Oid, Oid, int, int); + + probe xlog__insert(unsigned char, unsigned char); + probe xlog__switch(); + probe wal__buffer__write__dirty__start(); + probe wal__buffer__write__dirty__done(); +}; diff --git a/samples/Makefile/foo.o.d b/samples/Makefile/foo.o.d new file mode 100644 index 00000000..cf0ba55c --- /dev/null +++ b/samples/Makefile/foo.o.d @@ -0,0 +1,5 @@ +bar/foo.o: \ + bar/foo.c \ + bar/baz.h + +bar/baz.h: From 2b25bb6d1cdaa2e9133712cff4ae50d007c11e6a Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Fri, 20 Feb 2015 20:44:54 +0100 Subject: [PATCH 27/66] Add MUF language - Multi-user Forth. --- lib/linguist/heuristics.rb | 4 +++- lib/linguist/languages.yml | 9 +++++++++ test/test_language.rb | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index b82a5de4..bc9a0f53 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -178,11 +178,13 @@ module Linguist end end - disambiguate "M", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data| + disambiguate "M", "MUF", "Mathematica", "Matlab", "Mercury", "Objective-C" do |data| if ObjectiveCRegex.match(data) Language["Objective-C"] elsif data.include?(":- module") Language["Mercury"] + elsif /^: /.match(data) + Language["MUF"] elsif /^\s*;/.match(data) Language["M"] elsif /^\s*\(\*/.match(data) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 413683e5..2f96958c 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1745,6 +1745,15 @@ MTML: tm_scope: text.html.basic ace_mode: html +MUF: + type: programming + group: Forth + extensions: + - .muf + - .m + tm_scope: none + ace_mode: forth + Makefile: type: programming aliases: diff --git a/test/test_language.rb b/test/test_language.rb index 31be9a82..f3847a77 100644 --- a/test/test_language.rb +++ b/test/test_language.rb @@ -188,7 +188,7 @@ class TestLanguage < Minitest::Test assert_equal [], Language.find_by_extension('foo.rb') assert_equal [Language['Ruby']], Language.find_by_extension('rb') assert_equal [Language['Ruby']], Language.find_by_extension('.rb') - assert_equal [Language['M'], Language['Mathematica'], Language['Matlab'], Language['Mercury'], Language['Objective-C']], Language.find_by_extension('.m') + assert_equal [Language['M'], Language['MUF'], Language['Mathematica'], Language['Matlab'], Language['Mercury'], Language['Objective-C']], Language.find_by_extension('.m') end def test_find_all_by_extension From c6e16ee6bd3525d8cf90f5e8ce27d84cc3dc5121 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Sat, 21 Feb 2015 12:49:52 +0100 Subject: [PATCH 28/66] MUF sample files. 39.m by Revar; license GPL v2. cmd-say.muf by Natasha Snunkemeox; license MIT. --- samples/MUF/39.m | 278 ++++++++++++++++++++++++++++++++++++++++ samples/MUF/cmd-say.muf | 275 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 553 insertions(+) create mode 100644 samples/MUF/39.m create mode 100644 samples/MUF/cmd-say.muf diff --git a/samples/MUF/39.m b/samples/MUF/39.m new file mode 100644 index 00000000..16dd9970 --- /dev/null +++ b/samples/MUF/39.m @@ -0,0 +1,278 @@ +$include $lib/strings +$include $lib/match +lvar check-obj-addr + +: check-next-loop (d -- ) + dup not if pop exit then + dup exit? over thing? or + me @ 3 pick .controls and if + dup check-obj-addr @ execute + then + next check-next-loop +; + +: check-contents (d -- ) + contents check-next-loop +; + +: check-exits (d -- ) + exits check-next-loop +; + +: exec-err (d mtypestr warnstr -- ) + "On " 4 rotate unparseobj strcat + ", in it's " strcat rot strcat + ", " strcat swap strcat .tell +; + +: can-linkto? (player object -- i) + dup "link_ok" flag? if pop pop 1 exit then + .controls +; + +: check-exec (d mtype execstr -- ) + dup "@" 1 strncmp if pop pop pop exit then + 1 strcut swap pop + " " .split pop + dup "$" 1 strncmp not if + dup match ok? not if + " is not a known registered program." strcat + exec-err exit + then + dup match program? not if + " is not a program." strcat + exec-err exit + then + 3 pick owner over match can-linkto? not if + " is not Link_OK." strcat + exec-err exit + then + else + dup number? not if + " is not a program dbref." strcat + "@" swap strcat exec-err exit + then + dup atoi dbref ok? not if + " is not a valid program reference." strcat + "@" swap strcat exec-err exit + then + dup atoi dbref program? not if + " is not a valid program reference." strcat + "@" swap strcat exec-err exit + then + 3 pick owner over atoi dbref can-linkto? not if + " is not Link_OK." strcat + "@" swap strcat exec-err exit + then + then + pop pop pop +; + + +: missing-err ( d s -- ) + swap unparseobj + " is missing an " + strcat swap strcat + " message." strcat .tell +; + +: colon-err ( d s -- ) + swap unparseobj + " has an unnecesary ':' at the start of its " + strcat swap strcat + " message." strcat .tell +; + +: check-desc (d -- ) + dup desc not if + "@description" missing-err + else + "@description" over + desc check-exec + then +; + +: check-succ (d -- ) + dup succ not if + "@success" missing-err + else + "@success" over + succ check-exec + then +; + +: check-fail (d -- ) + dup fail not if + "@fail" missing-err + else + "@fail" over + fail check-exec + then +; + +: check-drop (d -- ) + dup drop not if + "@drop" missing-err + else + "@drop" over + drop check-exec + then +; + +: check-osucc (d -- ) + dup osucc not if + "@osuccess" missing-err + else + dup osucc ":" 1 strncmp not if + "@osuccess" colon-err + else pop + then + then +; + +: check-ofail (d -- ) + dup ofail not if + "@ofail" missing-err + else + dup ofail ":" 1 strncmp not if + "@ofail" colon-err + else pop + then + then +; + +: check-odrop (d -- ) + dup odrop not if + "@odrop" missing-err + else + dup odrop ":" 1 strncmp not if + "@odrop" colon-err + else pop + then + then +; + + +$define islocked? (d -- i) getlockstr "*UNLOCKED*" stringcmp $enddef + +: islocked_always? (d -- i) + getlockstr dup "#0" stringcmp not if pop 1 exit then + dup "#" STRsplit swap pop atoi + "#" swap intostr strcat + (lockstr "#dbref") + dup "&!" over strcat strcat + 3 pick stringcmp not if pop pop 1 exit then + "&" over strcat strcat "!" swap strcat + stringcmp not if 1 exit then + 0 +; + +: check-link ( d -- ) + dup getlink not if + dup unparseobj " is unlinked." strcat .tell + else + dup getlink over location dbcmp if + dup islocked? not if + dup unparseobj + " is linked to it's location, but is unlocked." + strcat .tell + then + else (is not linked to it's location) + dup getlink program? if + dup dup owner swap getlink can-linkto? not if + dup unparseobj + " is linked to a program which is not Link_OK." + strcat .tell + then + then + then + then + pop +; + +: check-room (d -- ) + dup check-desc + dup islocked? if + dup islocked_always? not if + dup check-succ + then + dup check-fail + then + dup getlink if + dup check-drop + dup check-odrop + then + dup check-contents + check-exits +; + +: check-exit ( d -- ) + dup check-link + dup check-desc + dup getlink dup ok? if + program? not if + dup islocked_always? not if + dup check-succ + dup check-osucc + dup check-odrop + then + dup islocked? if + dup check-fail + dup check-ofail + then + then + else pop + then + pop +; + +: check-thing ( d -- ) + dup check-desc + dup islocked_always? not if + dup check-succ + dup check-osucc + then + dup islocked? if + dup check-fail + dup check-ofail + then + dup check-drop + dup check-odrop + check-exits +; + +: check-player ( d -- ) + dup check-desc + dup islocked_always? not if + dup check-succ + dup check-osucc + then + dup islocked? if + dup check-fail + dup check-ofail + then + dup check-contents + check-exits +; + +: check-program ( d -- ) + check-desc +; + +: check-obj (d -- ) + dup room? if check-room exit then + dup exit? if check-exit exit then + dup thing? if check-thing exit then + dup player? if check-player exit then + check-program +; + +: main + 'check-obj check-obj-addr ! + .strip dup not if pop "here" then + .match_controlled + dup #-3 dbcmp if pop me @ getlink then + dup ok? not if pop exit then + check-obj + me @ "Check done." notify +; diff --git a/samples/MUF/cmd-say.muf b/samples/MUF/cmd-say.muf new file mode 100644 index 00000000..6d27c65e --- /dev/null +++ b/samples/MUF/cmd-say.muf @@ -0,0 +1,275 @@ +@program cmd-say.muf +1 1000 d +i +( cmd-say.muf by Natasha@HLM + + Copyright 2002-2004 Natasha Snunkmeox. Copyright 2002-2004 Here Lie Monsters. + "@view $box/mit" for license information. +) +$author Natasha Snunkmeox +$note Say for Fuzzball 6. +$version 1.0 + +$include $lib/ignore +$include $lib/strings +$include $lib/match + +$def str_program "saypose" +$def prop_third "_prefs/say/third" +$def prop_quotes "_say/def/quotes" +$def prop_overb "_say/def/osay" +$def prop_verb "_say/def/say" +$def prop_split "_prefs/say/split" +$def prop_color "_prefs/say/color" +$def prop_meow "_prefs/say/meow" + +lvar randomWord + +lvar verb +lvar overb +lvar lquo +lvar rquo +lvar splitsay + +: rtn-getThirdVerb[ var:overb -- ] + ( Get the third-person verb. ) + me @ prop_overb getpropstr dup if ( str strOverb ) + strip dup dup "," instr not and if "," strcat then + else pop "says," then ( str strOverb ) + me @ "%D %s" fmtstring overb @ ! ( str ) +; + +: rtn-getFirstVerb[ var:verb var:overb -- ] + me @ prop_third getpropstr .yes? not if ( str ) + ( Get the first-person verb. ) + me @ prop_verb getpropstr dup if ( str strVerb ) + strip dup dup "," instr not and if "," strcat then + else pop "say," then ( str strVerb ) + splitsay @ if "you %s" else "You %s" then fmtstring ( str strVerb ) + else overb @ @ then verb @ ! ( str ) +; + +: rtn-getQuotes[ var:lquo var:rquo -- ] + me @ prop_quotes getpropstr dup "%m" instr if ( strQuotes ) + "%m" split ( strLquo strRquo ) + else pop "\"" dup then ( strLquo strRquo ) + rquo @ ! lquo @ ! ( ) +; + +: do-say ( str -- ) + "" randomWord ! + + var who + var exclude + + ( Ignoring? Get 'em outta here. ) + loc @ contents_array ( str arrHere ) + dup me @ str_program array_get_ignorers ( str arrHere arrIgnorers ) + dup exclude ! + swap array_diff who ! + + + ( Anyone #meowing this player? Go ahead and notify before special formatting. ) + who @ prop_meow me @ owner "*{%d}*" fmtstring array_filter_prop ( str arrMeow ) + dup if ( str arrMeow ) + dup who @ array_diff who ! ( str arrMeow ) + dup exclude @ array_union exclude ! ( str arrMeow ) + + over ansi_strip ( str arrMeow str ) + "\\b[A-Z0-9_]+\\b" "MEOW" REG_ALL regsub ( str arrMeow str' ) + "\\b[A-Z0-9_][A-Za-z0-9_]*[a-z][A-Za-z0-9_]*\\b" "Meow" REG_ALL regsub ( str arrMeow str' ) + "\\b[a-z_][A-Za-z0-9_]*\\b" "meow" REG_ALL regsub ( str arrMeow str' ) + me @ "%D meows, \"%s\"" fmtstring ( str arrMeow str" ) + 1 array_make swap array_notify ( str ) + else pop then ( str ) + + + var msg + + dup ",," instr ( str boolCommas ) + me @ prop_split getpropstr .no? not ( str boolCommas boolSplitOK ) + and if ( str ) + ",," split ( str- -str ) + + ( User-supplied verb? ) + dup ",," instr if + ",," split ( str- strVerb -str ) + swap dup if ( str- -str strVerb ) + strip ( str- -str strVerb ) + dup me @ name instr over tolower "%n" instr or if ( str- -str strVerb ) + "%n" "%N" subst me @ name "%n" subst ( str- -str strVerb ) + else + me @ swap "%s %D," fmtstring ( str- -str -str- ) + then ( str- -str -str- ) + dup "*[-!.,:;]" smatch not if "," strcat then ( str- -str -str- ) + dup verb ! overb ! ( str- -str ) + else pop then ( str- -str ) + then ( str- -str ) + + 2 array_make ( arrMsg ) + 1 + else 0 then splitsay ! msg ! + + + verb @ string? not if + overb rtn-getThirdVerb + verb overb rtn-getFirstVerb + then + lquo rquo rtn-getQuotes ( str ) + + + ( Say. ) + msg @ string? if + rquo @ msg @ lquo @ ( strRquo strMsg strLquo ) + "%s %s%s%s" ( strRquo strMsg strLquo strFormat ) + + 4 dupn + verb @ swap fmtstring .tell ( strRquo strMsg strLquo strFormat ) + overb @ swap fmtstring ( strOsay ) + else + rquo @ msg @ array_vals pop ( strRquo strMsg strMsg2 ) + swap dup "*[-!.,:;]" smatch not if "," strcat then swap ( strRquo strMsg strMsg2 ) + ( Only handle strMsg if there's no strMsg2. ) + dup if ( strRquo strMsg strMsg2 ) + swap ( strRquo strMsg2 strMsg ) + lquo @ swap rquo @ swap lquo @ ( strRquo strMsg2 strLquo strRquo strMsg' strLquo ) + "%s%s%s %s %s%s%s" ( strRquo strMsg2 strLquo strRquo strMsg' strLquo strFormat ) + + 7 + else ( strRquo strMsg strMsg2 ) + pop lquo @ ( strRquo strMsg' strLquo ) + "%s%s%s %s" ( strRquo strMsg' strLquo strFormat ) + + verb @ ",$" "." 0 regsub verb ! + overb @ ",$" "." 0 regsub overb ! + + 4 + then ( ... strRquo strMsg strLquo strFormat intDepth ) + + dupn + verb @ -5 rotate fmtstring .tell ( ... strRquo strMsg strLquo strFormat ) + overb @ -5 rotate fmtstring ( strOsay ) + then ( strOsay ) + + + ( Is there color to avoid? ) + dup "\[[" instr if + who @ prop_color "{n*|0}" array_filter_prop ( strOsay arrGreyed ) + dup if ( strOsay arrGreyed ) + over ansi_strip 1 array_make ( strOsay arrGreyed arrMsg ) + over array_notify ( strOsay arrGreyed ) + + exclude @ array_union exclude ! ( strOsay ) + else pop then ( strOsay ) + then ( strOsay ) + + loc @ ( strOsay db ) + exclude @ array_vals ( strOsay db dbExcludeN..dbExclude1 intN ) + me @ swap ++ ( strOsay db dbGreyedN..dbGreyed1' intN' ) + dup 3 + rotate ( db dbGreyedN..dbGreyed1 intN strOsay ) + notify_exclude ( ) +; + +: do-help pop pop .showhelp ; +: do-ignore pop str_program cmd-ignore-add ; +: do-unignore pop str_program cmd-ignore-del ; + +: do-third ( strY strZ -- ) + pop pop ( ) + me @ prop_third "yes" setprop + me @ "You will see your own says in the third person (\"%D says\")." fmtstring .tellgood +; +: do-unthird ( strY strZ -- ) + pop pop ( ) + me @ prop_third remove_prop + "You will see your own says in the second person (\"You say\")." .tellgood +; + +: do-grey ( strY strZ -- ) + pop pop ( ) + me @ prop_color "no" setprop + me @ "You will not see color in any says. Note you will see color in your own says." fmtstring .tellgood +; +: do-ungrey ( strY strZ -- ) + pop pop ( ) + me @ prop_color remove_prop + "You will see color in says." .tellgood +; + +: do-meow ( strY strZ -- ) + pop ( strY ) + dup if + .noisy_pmatch dup ok? not if pop exit then ( db ) + me @ prop_meow 3 pick reflist_find if ( db ) + "%D is already in your #meow list." fmtstring .tellbad exit ( ) + then ( db ) + me @ prop_meow 3 pick reflist_add ( db ) + "%D added." fmtstring .tellgood + else + me @ prop_meow array_get_reflist ( arr ) + "" swap foreach swap pop "%D %s" fmtstring repeat + "Your meowlist: " swap strcat .tellgood + then +; +: do-unmeow ( strY strZ -- ) + pop ( strY ) + .noisy_pmatch dup ok? not if pop exit then ( db ) + me @ prop_meow 3 pick reflist_find not if ( db ) + "%D is not in your #meow list." fmtstring .tellbad exit ( ) + then ( db ) + me @ prop_meow 3 pick reflist_del ( db ) + "%D removed." fmtstring .tellgood +; + +$define dict_commands { + "help" 'do-help + "ignore" 'do-ignore + "!ignore" 'do-unignore + "meow" 'do-meow + "!meow" 'do-unmeow + "third" 'do-third + "!third" 'do-unthird + "grey" 'do-grey + "gray" 'do-grey + "!grey" 'do-ungrey + "!gray" 'do-ungrey +}dict $enddef + +: main ( str -- ) + dup STRparse ( str strX strY strZ ) + 3 pick string? if 3 pick "#" stringpfx if ( str strX strY strZ ) + pop pop pop ( str ) + "#" split strcat ( str' ) + do-say exit ( ) + then then + 3 pick int? if pop pop pop do-say exit then + 4 rotate pop ( strX strY strZ ) + + rot dict_commands over array_getitem ( strY strZ strX ? ) + dup address? if ( strY strZ strX adr ) + swap pop ( strY strZ adr ) + execute ( ) + else pop ( strY strZ strX ) + "I don't recognize the command '#%s'. Try 'say #help' for help, or using '##' to say something starting with '#'." fmtstring .tellbad ( strY strZ ) + pop pop ( ) + then ( ) +; +. +c +q + +lsedit #257=_help +.del 1 $ +say +." +say #[!]ignore +say #[!]third +say #[!]grey +say #[!]meow + +Speaks to the room. Use #ignore to not see 's says, poses, and spoofs; use #meow to see 's says with all the words replaced with "meow." Use #third to see your own says in the third person (that is, "Puck says" instead of the normal "You say"). Use #grey to turn off color in others' says and poses. + +Say supports a "split" say if you put two consecutive commas in your message. For example, if CobaltBlue typed '"Hello,,how are you?' everyone would see '"Hello," says CobaltBlue, "how are you?"' You can also specify an "ad-hoc" verb by putting a message with your name or '%N' between pairs of commas: '"Hello,,%N welcomes Weiran,,how are you?' would display '"Hello," CobaltBlue welcomes Weiran, "how are you?"' +.format 10=78 +.format 8=78 +.end From 0bccf97d16241a2044288623114c17a97a6f54a7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 3 Feb 2015 08:56:30 -0800 Subject: [PATCH 29/66] Add support for the AMPL modeling and script language --- lib/linguist/languages.yml | 10 ++++++++++ samples/AMPL/diet.dat | 32 ++++++++++++++++++++++++++++++++ samples/AMPL/diet.mod | 27 +++++++++++++++++++++++++++ samples/AMPL/diet.run | 25 +++++++++++++++++++++++++ samples/AMPL/toy.ampl | 25 +++++++++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 samples/AMPL/diet.dat create mode 100644 samples/AMPL/diet.mod create mode 100644 samples/AMPL/diet.run create mode 100644 samples/AMPL/toy.ampl diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 413683e5..b5062fd9 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -41,6 +41,16 @@ AGS Script: tm_scope: source.c++ ace_mode: c_cpp +AMPL: + type: programming + color: "#00008B" + extensions: + - .ampl + - .dat + - .mod + - .run + ace_mode: text + ANTLR: type: programming color: "#9DC3FF" diff --git a/samples/AMPL/diet.dat b/samples/AMPL/diet.dat new file mode 100644 index 00000000..c263803c --- /dev/null +++ b/samples/AMPL/diet.dat @@ -0,0 +1,32 @@ + +param: FOOD: cost f_min f_max := + "Quarter Pounder w/ Cheese" 1.84 . . + "McLean Deluxe w/ Cheese" 2.19 . . + "Big Mac" 1.84 . . + "Filet-O-Fish" 1.44 . . + "McGrilled Chicken" 2.29 . . + "Fries, small" .77 . . + "Sausage McMuffin" 1.29 . . + "1% Lowfat Milk" .60 . . + "Orange Juice" .72 . . ; + +param: NUTR: n_min n_max := + Cal 2000 . + Carbo 350 375 + Protein 55 . + VitA 100 . + VitC 100 . + Calc 100 . + Iron 100 . ; + +param amt (tr): + Cal Carbo Protein VitA VitC Calc Iron := + "Quarter Pounder w/ Cheese" 510 34 28 15 6 30 20 + "McLean Deluxe w/ Cheese" 370 35 24 15 10 20 20 + "Big Mac" 500 42 25 6 2 25 20 + "Filet-O-Fish" 370 38 14 2 0 15 10 + "McGrilled Chicken" 400 42 31 8 15 15 8 + "Fries, small" 220 26 3 0 15 0 2 + "Sausage McMuffin" 345 27 15 4 0 20 15 + "1% Lowfat Milk" 110 12 9 10 4 30 0 + "Orange Juice" 80 20 1 2 120 2 2 ; diff --git a/samples/AMPL/diet.mod b/samples/AMPL/diet.mod new file mode 100644 index 00000000..c831a6c6 --- /dev/null +++ b/samples/AMPL/diet.mod @@ -0,0 +1,27 @@ + +set NUTR ordered; +set FOOD ordered; + +param cost {FOOD} >= 0; +param f_min {FOOD} >= 0, default 0; +param f_max {j in FOOD} >= f_min[j], default Infinity; + +param n_min {NUTR} >= 0, default 0; +param n_max {i in NUTR} >= n_min[i], default Infinity; + +param amt {NUTR,FOOD} >= 0; + +# -------------------------------------------------------- + +var Buy {j in FOOD} integer >= f_min[j], <= f_max[j]; + +# -------------------------------------------------------- + +minimize Total_Cost: sum {j in FOOD} cost[j] * Buy[j]; + +minimize Nutr_Amt {i in NUTR}: sum {j in FOOD} amt[i,j] * Buy[j]; + +# -------------------------------------------------------- + +subject to Diet {i in NUTR}: + n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i]; diff --git a/samples/AMPL/diet.run b/samples/AMPL/diet.run new file mode 100644 index 00000000..ded2786d --- /dev/null +++ b/samples/AMPL/diet.run @@ -0,0 +1,25 @@ +model diet.mod; +data diet2.dat; + +param N symbolic in NUTR; +param nstart > 0; +param nstep > 0; +read N, nstart, nstep <- ; # read data interactively + +set N_MAX default {}; +param N_obj {N_MAX}; +param N_dual {N_MAX}; +option solver_msg 0; + +for {i in nstart .. 0 by -nstep} { + let n_max[N] := i; + solve; + if solve_result = "infeasible" then { + printf "--- infeasible at %d ---\n\n", i; + break; + } + let N_MAX := N_MAX union {i}; + let N_obj[i] := Total_Cost; + let N_dual[i] := Diet[N].dual; +} +display N_obj, N_dual; diff --git a/samples/AMPL/toy.ampl b/samples/AMPL/toy.ampl new file mode 100644 index 00000000..0ca0c7cf --- /dev/null +++ b/samples/AMPL/toy.ampl @@ -0,0 +1,25 @@ +# A toy knapsack problem from the LocalSolver docs written in AMPL. + +set I; +param Value{I}; +param Weight{I}; +param KnapsackBound; +var Take{I} binary; + +maximize TotalValue: sum{i in I} Take[i] * Value[i]; +s.t. WeightLimit: sum{i in I} Take[i] * Weight[i] <= KnapsackBound; + +data; + +param: +I: Weight Value := +0 10 1 +1 60 10 +2 30 15 +3 40 40 +4 30 60 +5 20 90 +6 20 100 +7 2 15; + +param KnapsackBound := 102; From 407dbbb7fb7ed7a91f26896466fdf6e1fbc9bf98 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 3 Feb 2015 09:52:06 -0800 Subject: [PATCH 30/66] Mark AMPL with `tm_scope: none` because it doesn't have grammar info --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b5062fd9..feaa1280 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -49,6 +49,7 @@ AMPL: - .dat - .mod - .run + tm_scope: none ace_mode: text ANTLR: From 1cdd3c55aba439733ab1df7e3acc4b70bf6523c0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 25 Feb 2015 11:37:40 -0800 Subject: [PATCH 31/66] Add AMPL grammar --- .gitmodules | 3 +++ grammars.yml | 2 ++ vendor/grammars/ampl | 1 + 3 files changed, 6 insertions(+) create mode 160000 vendor/grammars/ampl diff --git a/.gitmodules b/.gitmodules index 136013b2..134004a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -630,3 +630,6 @@ [submodule "vendor/grammars/Lean.tmbundle"] path = vendor/grammars/Lean.tmbundle url = https://github.com/leanprover/Lean.tmbundle +[submodule "vendor/grammars/ampl"] + path = vendor/grammars/ampl + url = https://github.com/ampl/sublime-ampl diff --git a/grammars.yml b/grammars.yml index 6d933a09..3b40a3b9 100644 --- a/grammars.yml +++ b/grammars.yml @@ -143,6 +143,8 @@ vendor/grammars/actionscript3-tmbundle: - text.xml.flex-config vendor/grammars/ada.tmbundle: - source.ada +vendor/grammars/ampl: +- source.ampl vendor/grammars/ant.tmbundle: - text.xml.ant vendor/grammars/antlr.tmbundle: diff --git a/vendor/grammars/ampl b/vendor/grammars/ampl new file mode 160000 index 00000000..2e399ebf --- /dev/null +++ b/vendor/grammars/ampl @@ -0,0 +1 @@ +Subproject commit 2e399ebf4aec6b5b81f01d4cbee965f77852ce86 From 13eb7c796ed965f49df0d8a58f05b615a4815669 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 25 Feb 2015 12:59:23 -0800 Subject: [PATCH 32/66] Remove .dat, .mod and .run AMPL extensions as they are ambiguous As discussed in #2073 adding these extensions will require more work to avoid incorrect language detection. --- lib/linguist/languages.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index feaa1280..57777f64 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -46,9 +46,6 @@ AMPL: color: "#00008B" extensions: - .ampl - - .dat - - .mod - - .run tm_scope: none ace_mode: text From e093ac843f92b698340d1953b9bdc9f77701cd3d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 25 Feb 2015 14:22:45 -0800 Subject: [PATCH 33/66] Remove AMPL samples using .mod, .dat and .run extensions --- samples/AMPL/diet.dat | 32 -------------------------------- samples/AMPL/diet.mod | 27 --------------------------- samples/AMPL/diet.run | 25 ------------------------- 3 files changed, 84 deletions(-) delete mode 100644 samples/AMPL/diet.dat delete mode 100644 samples/AMPL/diet.mod delete mode 100644 samples/AMPL/diet.run diff --git a/samples/AMPL/diet.dat b/samples/AMPL/diet.dat deleted file mode 100644 index c263803c..00000000 --- a/samples/AMPL/diet.dat +++ /dev/null @@ -1,32 +0,0 @@ - -param: FOOD: cost f_min f_max := - "Quarter Pounder w/ Cheese" 1.84 . . - "McLean Deluxe w/ Cheese" 2.19 . . - "Big Mac" 1.84 . . - "Filet-O-Fish" 1.44 . . - "McGrilled Chicken" 2.29 . . - "Fries, small" .77 . . - "Sausage McMuffin" 1.29 . . - "1% Lowfat Milk" .60 . . - "Orange Juice" .72 . . ; - -param: NUTR: n_min n_max := - Cal 2000 . - Carbo 350 375 - Protein 55 . - VitA 100 . - VitC 100 . - Calc 100 . - Iron 100 . ; - -param amt (tr): - Cal Carbo Protein VitA VitC Calc Iron := - "Quarter Pounder w/ Cheese" 510 34 28 15 6 30 20 - "McLean Deluxe w/ Cheese" 370 35 24 15 10 20 20 - "Big Mac" 500 42 25 6 2 25 20 - "Filet-O-Fish" 370 38 14 2 0 15 10 - "McGrilled Chicken" 400 42 31 8 15 15 8 - "Fries, small" 220 26 3 0 15 0 2 - "Sausage McMuffin" 345 27 15 4 0 20 15 - "1% Lowfat Milk" 110 12 9 10 4 30 0 - "Orange Juice" 80 20 1 2 120 2 2 ; diff --git a/samples/AMPL/diet.mod b/samples/AMPL/diet.mod deleted file mode 100644 index c831a6c6..00000000 --- a/samples/AMPL/diet.mod +++ /dev/null @@ -1,27 +0,0 @@ - -set NUTR ordered; -set FOOD ordered; - -param cost {FOOD} >= 0; -param f_min {FOOD} >= 0, default 0; -param f_max {j in FOOD} >= f_min[j], default Infinity; - -param n_min {NUTR} >= 0, default 0; -param n_max {i in NUTR} >= n_min[i], default Infinity; - -param amt {NUTR,FOOD} >= 0; - -# -------------------------------------------------------- - -var Buy {j in FOOD} integer >= f_min[j], <= f_max[j]; - -# -------------------------------------------------------- - -minimize Total_Cost: sum {j in FOOD} cost[j] * Buy[j]; - -minimize Nutr_Amt {i in NUTR}: sum {j in FOOD} amt[i,j] * Buy[j]; - -# -------------------------------------------------------- - -subject to Diet {i in NUTR}: - n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i]; diff --git a/samples/AMPL/diet.run b/samples/AMPL/diet.run deleted file mode 100644 index ded2786d..00000000 --- a/samples/AMPL/diet.run +++ /dev/null @@ -1,25 +0,0 @@ -model diet.mod; -data diet2.dat; - -param N symbolic in NUTR; -param nstart > 0; -param nstep > 0; -read N, nstart, nstep <- ; # read data interactively - -set N_MAX default {}; -param N_obj {N_MAX}; -param N_dual {N_MAX}; -option solver_msg 0; - -for {i in nstart .. 0 by -nstep} { - let n_max[N] := i; - solve; - if solve_result = "infeasible" then { - printf "--- infeasible at %d ---\n\n", i; - break; - } - let N_MAX := N_MAX union {i}; - let N_obj[i] := Total_Cost; - let N_dual[i] := Diet[N].dual; -} -display N_obj, N_dual; From 51af1bd162eccaddf3f5d224dd4cbbbb3385d28e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 26 Feb 2015 10:40:56 -0800 Subject: [PATCH 34/66] Use AMPL grammar --- 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 57777f64..d1348dc0 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -46,7 +46,7 @@ AMPL: color: "#00008B" extensions: - .ampl - tm_scope: none + tm_scope: source.ampl ace_mode: text ANTLR: From 65260e3aaa536d7e68ef42248e29f3ed705b6224 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Thu, 26 Feb 2015 21:59:03 +0100 Subject: [PATCH 35/66] Grammar for OpenScad from TextMate bundle --- .gitmodules | 3 +++ grammars.yml | 2 ++ lib/linguist/languages.yml | 2 +- vendor/grammars/openscad.tmbundle | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 160000 vendor/grammars/openscad.tmbundle diff --git a/.gitmodules b/.gitmodules index 136013b2..985b81d3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -630,3 +630,6 @@ [submodule "vendor/grammars/Lean.tmbundle"] path = vendor/grammars/Lean.tmbundle url = https://github.com/leanprover/Lean.tmbundle +[submodule "vendor/grammars/openscad.tmbundle"] + path = vendor/grammars/openscad.tmbundle + url = https://github.com/tbuser/openscad.tmbundle diff --git a/grammars.yml b/grammars.yml index 6d933a09..7f4f89ee 100644 --- a/grammars.yml +++ b/grammars.yml @@ -383,6 +383,8 @@ vendor/grammars/ooc.tmbundle: - source.ooc vendor/grammars/opa.tmbundle: - source.opa +vendor/grammars/openscad.tmbundle/: +- source.scad vendor/grammars/oz-tmbundle/Syntaxes/Oz.tmLanguage: - source.oz vendor/grammars/pascal.tmbundle: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 413683e5..73abc785 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2117,7 +2117,7 @@ OpenSCAD: type: programming extensions: - .scad - tm_scope: none + tm_scope: source.scad ace_mode: scad Org: diff --git a/vendor/grammars/openscad.tmbundle b/vendor/grammars/openscad.tmbundle new file mode 160000 index 00000000..4b2bc0a8 --- /dev/null +++ b/vendor/grammars/openscad.tmbundle @@ -0,0 +1 @@ +Subproject commit 4b2bc0a8e100d8f0350fd74f6c40dd956c118355 From 9a86b9ad753c6073825dff543cdf38496243a59b Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 26 Feb 2015 15:27:33 -0600 Subject: [PATCH 36/66] Instrument all calls and pass the blob, strategy and language candidates in the payload. --- lib/linguist/classifier.rb | 8 +++----- lib/linguist/language.rb | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index 208467e4..89a0df2f 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -16,11 +16,9 @@ module Linguist # # Returns an Array of Language objects, most probable first. def self.call(blob, possible_languages) - Linguist.instrument("linguist.bayesian_classification") do - language_names = possible_languages.map(&:name) - classify(Samples.cache, blob.data, language_names).map do |name, _| - Language[name] # Return the actual Language objects - end + language_names = possible_languages.map(&:name) + classify(Samples.cache, blob.data, language_names).map do |name, _| + Language[name] # Return the actual Language objects end end diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 68b4c4fc..bf0dfc33 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -107,18 +107,27 @@ module Linguist Linguist.instrument("linguist.detection") do # Call each strategy until one candidate is returned. - STRATEGIES.reduce([]) do |languages, strategy| - candidates = strategy.call(blob, languages) + languages = [] + strategy = nil + + STRATEGIES.each do |strategy| + candidates = Linguist.instrument("linguist.strategy", :blob => blob, :strategy => strategy, :candidates => languages) do + strategy.call(blob, languages) + end if candidates.size == 1 - return candidates.first + languages = candidates + break elsif candidates.size > 1 # More than one candidate was found, pass them to the next strategy. - candidates + languages = candidates else - # No candiates were found, pass on languages from the previous strategy. - languages + # No candidates, try the next strategy end - end.first + end + + Linguist.instrument("linguist.detected", :blob => blob, :strategy => strategy, :language => languages.first) do + languages.first + end end end From e24a9ba602604ae55ac982e0ef797e4f72ac3eab Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 27 Feb 2015 13:36:12 -0600 Subject: [PATCH 37/66] Ordering --- grammars.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars.yml b/grammars.yml index 827e61cf..311bb226 100644 --- a/grammars.yml +++ b/grammars.yml @@ -383,10 +383,10 @@ vendor/grammars/ooc.tmbundle: - source.ooc vendor/grammars/opa.tmbundle: - source.opa -vendor/grammars/oracle.tmbundle: -- source.plsql.oracle vendor/grammars/openscad.tmbundle/: - source.scad +vendor/grammars/oracle.tmbundle: +- source.plsql.oracle vendor/grammars/oz-tmbundle/Syntaxes/Oz.tmLanguage: - source.oz vendor/grammars/pascal.tmbundle: From b350f1572be21c4b8f2fc156f769abd5fb0b3cb4 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 27 Feb 2015 13:36:20 -0600 Subject: [PATCH 38/66] Reformatting --- lib/linguist/heuristics.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 885d578c..2ff8d9fb 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -237,20 +237,18 @@ module Linguist end disambiguate "PLSQL", "SQLPL", "PLpgSQL", "SQL" do |data| - #only return value if a definite positive - if /^\\i\b|AS \$\$|LANGUAGE '+plpgsql'+/i.match(data) || /SECURITY (DEFINER|INVOKER)/i.match(data) || /BEGIN( WORK| TRANSACTION)?;/i.match(data) - #postgres - Language["PLpgSQL"] + #Postgres + Language["PLpgSQL"] elsif /(alter module)|(language sql)|(begin( NOT)+ atomic)/i.match(data) || /signal SQLSTATE '[0-9]+'/i.match(data) - #ibm db2 - Language["SQLPL"] + #IBM db2 + Language["SQLPL"] elsif /pragma|\$\$PLSQL_|XMLTYPE|sysdate|systimestamp|\.nextval|connect by|AUTHID (DEFINER|CURRENT_USER)/i.match(data) || /constructor\W+function/i.match(data) - #oraclestuff - Language["PLSQL"] + #Oracle + Language["PLSQL"] elsif ! /begin|boolean|package|exception/i.match(data) - #generic sql - Language["SQL"] + #Generic SQL + Language["SQL"] end end From 63fc9dd6a5d0a551e73b5ce1c4c0861d3e88c624 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 27 Feb 2015 13:50:29 -0600 Subject: [PATCH 39/66] Updating grammars --- vendor/grammars/Stylus | 2 +- vendor/grammars/Sublime-VimL | 2 +- vendor/grammars/SublimePapyrus | 2 +- vendor/grammars/dart-sublime-bundle | 2 +- vendor/grammars/factor | 2 +- vendor/grammars/fsharpbinding | 2 +- vendor/grammars/grace-tmbundle | 2 +- vendor/grammars/language-clojure | 2 +- vendor/grammars/language-javascript | 2 +- vendor/grammars/latex.tmbundle | 2 +- vendor/grammars/oracle.tmbundle | 2 +- vendor/grammars/powershell | 2 +- vendor/grammars/sublime-nginx | 2 +- vendor/grammars/toml.tmbundle | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vendor/grammars/Stylus b/vendor/grammars/Stylus index b9214d1f..c060554e 160000 --- a/vendor/grammars/Stylus +++ b/vendor/grammars/Stylus @@ -1 +1 @@ -Subproject commit b9214d1ffd5031b60d77d07a6f315a934d4a473e +Subproject commit c060554eb82ed253969457b2609d9eb5c7739c6e diff --git a/vendor/grammars/Sublime-VimL b/vendor/grammars/Sublime-VimL index 366fdc64..4b23352c 160000 --- a/vendor/grammars/Sublime-VimL +++ b/vendor/grammars/Sublime-VimL @@ -1 +1 @@ -Subproject commit 366fdc64e3655207a0b2672f630d7167e6aac2c3 +Subproject commit 4b23352ce5e48a191d55d61883a9478211df91fd diff --git a/vendor/grammars/SublimePapyrus b/vendor/grammars/SublimePapyrus index 27313007..e1b78aac 160000 --- a/vendor/grammars/SublimePapyrus +++ b/vendor/grammars/SublimePapyrus @@ -1 +1 @@ -Subproject commit 27313007d94fd4ae802702e5ca6b454e8a5e9468 +Subproject commit e1b78aacb6b0ab8b4c26ea897b128335f8ed939c diff --git a/vendor/grammars/dart-sublime-bundle b/vendor/grammars/dart-sublime-bundle index d55b1d42..21096f24 160000 --- a/vendor/grammars/dart-sublime-bundle +++ b/vendor/grammars/dart-sublime-bundle @@ -1 +1 @@ -Subproject commit d55b1d427845aa4c2f2fe5947121616b7f1160fa +Subproject commit 21096f24d8a34668d54ad31b8902ab5c709c1c07 diff --git a/vendor/grammars/factor b/vendor/grammars/factor index ec896cd5..fe2c2d23 160000 --- a/vendor/grammars/factor +++ b/vendor/grammars/factor @@ -1 +1 @@ -Subproject commit ec896cd5ad05d4ae9b837fa5a64cd9431d2a14d6 +Subproject commit fe2c2d23de9e300d7cd1b04e139dfbdd2069d00a diff --git a/vendor/grammars/fsharpbinding b/vendor/grammars/fsharpbinding index 0cd6439b..a008fe9c 160000 --- a/vendor/grammars/fsharpbinding +++ b/vendor/grammars/fsharpbinding @@ -1 +1 @@ -Subproject commit 0cd6439b513631c469d69b0e02a26804b068674b +Subproject commit a008fe9c64d454132941eb72334c52e4ad93266e diff --git a/vendor/grammars/grace-tmbundle b/vendor/grammars/grace-tmbundle index acbf9a24..6bea212a 160000 --- a/vendor/grammars/grace-tmbundle +++ b/vendor/grammars/grace-tmbundle @@ -1 +1 @@ -Subproject commit acbf9a247c6fae57d0e51c712669933b93ca4251 +Subproject commit 6bea212a5843e152cd605ec6075eb7352cbeaf0d diff --git a/vendor/grammars/language-clojure b/vendor/grammars/language-clojure index bae6eee8..51978f7d 160000 --- a/vendor/grammars/language-clojure +++ b/vendor/grammars/language-clojure @@ -1 +1 @@ -Subproject commit bae6eee8557c2158592ac485a7168ccd10fc6dfb +Subproject commit 51978f7d1b1a7b92f77ccf02b042b768946844bd diff --git a/vendor/grammars/language-javascript b/vendor/grammars/language-javascript index d58edec6..da1fdb69 160000 --- a/vendor/grammars/language-javascript +++ b/vendor/grammars/language-javascript @@ -1 +1 @@ -Subproject commit d58edec65539e014fa13579461df6bebc24250c0 +Subproject commit da1fdb6949eea5d107c8f30063437d14a3c3a677 diff --git a/vendor/grammars/latex.tmbundle b/vendor/grammars/latex.tmbundle index 669040b8..610ee6ef 160000 --- a/vendor/grammars/latex.tmbundle +++ b/vendor/grammars/latex.tmbundle @@ -1 +1 @@ -Subproject commit 669040b8936375e54fb208dfb56e2ed4a3945d76 +Subproject commit 610ee6ef0d6162249374a480c1209c1ddd46a955 diff --git a/vendor/grammars/oracle.tmbundle b/vendor/grammars/oracle.tmbundle index f5308c9a..b41e6d33 160000 --- a/vendor/grammars/oracle.tmbundle +++ b/vendor/grammars/oracle.tmbundle @@ -1 +1 @@ -Subproject commit f5308c9abe377210145ffe606bd8b3ac0088608a +Subproject commit b41e6d33d6a71649d97e497fb1504aa01e7ceb41 diff --git a/vendor/grammars/powershell b/vendor/grammars/powershell index 84fd9726..0d9478d1 160000 --- a/vendor/grammars/powershell +++ b/vendor/grammars/powershell @@ -1 +1 @@ -Subproject commit 84fd97265c93abcd52de5915b4cf1179cc508373 +Subproject commit 0d9478d1175969291741ee46a85445dd34f38d04 diff --git a/vendor/grammars/sublime-nginx b/vendor/grammars/sublime-nginx index eee371d7..872afddd 160000 --- a/vendor/grammars/sublime-nginx +++ b/vendor/grammars/sublime-nginx @@ -1 +1 @@ -Subproject commit eee371d7f4d688c6ccac0322c63506080e873131 +Subproject commit 872afddd2d61acae85560fa009658257f4030244 diff --git a/vendor/grammars/toml.tmbundle b/vendor/grammars/toml.tmbundle index cda2b74d..d261ef63 160000 --- a/vendor/grammars/toml.tmbundle +++ b/vendor/grammars/toml.tmbundle @@ -1 +1 @@ -Subproject commit cda2b74d0d40c841c573eae9c5e9edd7621d8d90 +Subproject commit d261ef630a6025c6ee518762715086bc22209c41 From 7ba4f0c57131de5b9ab4e3f8ae98431465575661 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 27 Feb 2015 13:51:23 -0600 Subject: [PATCH 40/66] Oracle grammar now has a license --- test/test_grammars.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_grammars.rb b/test/test_grammars.rb index 9026b7ce..c5fbee4e 100644 --- a/test/test_grammars.rb +++ b/test/test_grammars.rb @@ -14,8 +14,7 @@ class TestGrammars < Minitest::Test # must have a license that allows redistribution. "vendor/grammars/Sublime-Lasso", "vendor/grammars/Sublime-REBOL", - "vendor/grammars/x86-assembly-textmate-bundle", - "vendor/grammars/oracle.tmbundle" + "vendor/grammars/x86-assembly-textmate-bundle" ].freeze def setup From b358a22d320190d5724797e3a7fc85a39181b894 Mon Sep 17 00:00:00 2001 From: Zach Munro-Cape Date: Fri, 27 Feb 2015 23:02:13 -0400 Subject: [PATCH 41/66] Standardized color hexcode length to 6 C was the only language to have a hex code length of 3. #555555 == #555 == rgb(85, 85, 85) --- 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 4bd9f71c..f93bdbc3 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -356,7 +356,7 @@ Bro: C: type: programming - color: "#555" + color: "#555555" extensions: - .c - .cats From 7c593899e7a596d283c4ce81faf0b7205a5c287d Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sun, 1 Mar 2015 12:43:35 +0100 Subject: [PATCH 42/66] Make heuristic for Prolog more specific --- lib/linguist/heuristics.rb | 8 +- samples/Perl/exception_handler.pl | 117 ++++++++++++++++++++++++++++++ test/test_heuristics.rb | 6 +- 3 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 samples/Perl/exception_handler.pl diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 2ff8d9fb..eb39a925 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -33,7 +33,7 @@ module Linguist # disambiguate "Perl", "Prolog" do |data| # if data.include?("use strict") # Language["Perl"] - # elsif data.include?(":-") + # elsif /^[^#]+:-/.match(data) # Language["Prolog"] # end # end @@ -94,13 +94,13 @@ module Linguist Language["Perl6"] elsif data.match(/use strict|use\s+v?5\./) Language["Perl"] - elsif data.include?(":-") + elsif /^[^#]+:-/.match(data) Language["Prolog"] end end disambiguate "ECL", "Prolog" do |data| - if data.include?(":-") + if /^[^#]+:-/.match(data) Language["Prolog"] elsif data.include?(":=") Language["ECL"] @@ -108,7 +108,7 @@ module Linguist end disambiguate "IDL", "Prolog", "INI", "QMake" do |data| - if data.include?(":-") + if /^[^#]+:-/.match(data) Language["Prolog"] elsif data.include?("last_client=") Language["INI"] diff --git a/samples/Perl/exception_handler.pl b/samples/Perl/exception_handler.pl new file mode 100644 index 00000000..14807ced --- /dev/null +++ b/samples/Perl/exception_handler.pl @@ -0,0 +1,117 @@ +package exception_handler; +use sigtrap qw(die normal-signals); +use IO::Handle; +use Carp; +use File::Spec; +use File::Basename; +use Data::Dumper; + +use sigtrap 'handler', \&tm_die; + +$Carp::CarpLevel = 1; # How many extra package levels to skip on carp. + +BEGIN { + *CORE::GLOBAL::die = \&tm_die; + $main::SIG{__DIE__} = \&tm_die; + my $error_fd = $ENV{"TM_ERROR_FD"}; + open (TM_ERROR_FD, ">&=$error_fd"); + TM_ERROR_FD->autoflush(1); +} + +sub realwarn { CORE::warn(@_); } +sub realdie { CORE::die(@_); } + +sub longmess { + my ($arg, @rest) = shift; + { + local $@; + # XXX fix require to not clear $@? + # don't use require unless we need to (for Safe compartments) + require Carp::Heavy unless $INC{"Carp/Heavy.pm"}; + } + # Icky backwards compatibility wrapper. :-( + my $call_pack = caller(); + if ($Internal{$call_pack} or $Carp::CarpInternal{$call_pack}) { + return longmess_heavy($arg, @rest); + } + else { + local $Carp::CarpLevel = $Carp::CarpLevel + 1; + return longmess_heavy($arg, @rest); + } +} + +sub longmess_heavy { + return @_ if ref($_[0]); # don't break references as exceptions + my $i = Carp::long_error_loc(); + my ($arg, @rest) = @_; + return ret_backtrace($i, $arg, @rest); +} + +sub quote { + my $str = shift; + $str =~ s/([^A-Za-z0-9\/_.-])/sprintf("%%%02X", ord($1))/seg; + return $str; +} + +sub url_and_display_name { + my $file = shift; + my $url = ""; + my $display_name = ""; + $display_name = basename($file); + $url = 'url=file://' . quote($file); + return ($url, $display_name); +} + +# Returns a full stack backtrace starting from where it is +# told. +sub ret_backtrace { + my ($i, $arg, @rest) = @_; + my $mess; + $i++; + + my $tid_msg = ''; + if (defined &Thread::tid) { + my $tid = Thread->self->tid; + $tid_msg = " thread $tid" if $tid; + } + + my %i = Carp::caller_info($i); + $arg =~ s/\n/\/g; + $i{sub} =~ s/tm_die/die/g; + $mess .= "
\n"; + $mess .= "

$arg

\n"; + $mess .= "
\n"; + my ($url, $display_name) = url_and_display_name($i{file}); + $mess .= "\n"; + while (my %i = Carp::caller_info(++$i)) { + ($url, $display_name) = url_and_display_name($i{file}); + $mess .= "\n"; + } + $mess .= "
$i{sub} in $display_name at line $i{line}$tid_msg
$i{sub} in $display_name at line $i{line}$tid_msg
"; + return $mess; +} + +sub ineval { + (exists $ENV{MOD_PERL} ? 0 : $^S) || Carp::longmess() =~ /eval [\{\']/m +} + +sub htmlize { + my $l = shift; + $l =~ s/&/&/g; + $l =~ s//>/g; + return $l; +} + +sub tm_die { + my ($arg,@rest) = @_; + if (ineval()) { + realdie ($arg,@rest) if ineval(); + } + if (!ref($arg)) { + print TM_ERROR_FD longmess($arg,@rest); + } + exit($!); +} + +1; diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb index dcdf3328..b3197c69 100644 --- a/test/test_heuristics.rb +++ b/test/test_heuristics.rb @@ -47,8 +47,10 @@ class TestHeuristcs < Minitest::Test # Candidate languages = ["Perl", "Prolog"] def test_pl_prolog_perl_by_heuristics assert_heuristics({ - "Prolog" => "Prolog/turing.pl", - "Perl" => ["Perl/perl-test.t", "Perl/use5.pl"] + "Prolog" => all_fixtures("Prolog/*.pl"), + "Perl" => all_fixtures("Perl/*.pl"), + "Perl" => ["Perl/perl-test.t"], + "Perl6" => all_fixtures("Perl6/*.pl") }) end From 08945923e651ad36c8896939fdf2e7a506c87759 Mon Sep 17 00:00:00 2001 From: Rejean Loyer Date: Mon, 23 Feb 2015 10:01:13 -0500 Subject: [PATCH 43/66] Add designated color of eC language in lib/linguist/languages.yml for display in repository page's language bar. --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0848c24e..bf381d45 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3414,6 +3414,7 @@ desktop: eC: type: programming + color: "#4A4773" search_term: ec extensions: - .ec From c22a6563d953b04e3ae591ad027038aa486c045d Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Sun, 1 Mar 2015 22:13:26 -0600 Subject: [PATCH 44/66] Writing some (failing) tests for instrumentation --- test/test_instrumentation.rb | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/test_instrumentation.rb diff --git a/test/test_instrumentation.rb b/test/test_instrumentation.rb new file mode 100644 index 00000000..9078680c --- /dev/null +++ b/test/test_instrumentation.rb @@ -0,0 +1,43 @@ +require_relative "./helper" + +class TestInstrumentation < Minitest::Test + include Linguist + + class LocalInstrumenter + Event = Struct.new(:name, :args) + + attr_reader :events + + def initialize + @events = [] + end + + def instrument(name, *args) + @events << Event.new(name, args) + end + end + + def setup + Linguist.instrumenter = LocalInstrumenter.new + end + + def teardown + Linguist.instrumenter = nil + end + + def test_detection_instrumentation_with_binary_blob + binary_blob = fixture_blob("Binary/octocat.ai") + Language.detect(binary_blob) + + # Shouldn't instrument this (as it's binary) + assert_equal 0, Linguist.instrumenter.events.size + end + + def test_modeline_instrumentation + blob = fixture_blob("Data/Modelines/ruby") + Language.detect(blob) + + assert_equal 3, Linguist.instrumenter.events.size + assert_equal "linguist.detected", Linguist.instrumenter.events.last.name + end +end From 4efc3ff822139868c36afeefbbe3c1e92898d1de Mon Sep 17 00:00:00 2001 From: Simon Cooksey Date: Mon, 2 Mar 2015 17:04:18 +0000 Subject: [PATCH 45/66] Add colour for XMOS XC in linguist Adds a colour matching the XMOS colour scheme for .xc files. --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index bf381d45..70d52869 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3234,6 +3234,7 @@ WebIDL: XC: type: programming + color: "#99DA07" extensions: - .xc tm_scope: source.c From eaea6ac837203a4ef4fd79239d17a752d8cd2371 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Mon, 2 Mar 2015 18:09:09 +0100 Subject: [PATCH 46/66] QML as a programming language --- 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 0848c24e..c4c24539 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2487,7 +2487,7 @@ Python traceback: ace_mode: text QML: - type: markup + type: programming color: "#44a51c" extensions: - .qml From e5ce286c632ede86640da881bad93e9f7d490e07 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Mon, 2 Mar 2015 21:55:41 +0100 Subject: [PATCH 47/66] NL file format with .nl extension --- lib/linguist/languages.yml | 7 ++++ samples/NL/assign0.nl | 84 ++++++++++++++++++++++++++++++++++++++ samples/NewLisp/queens.nl | 49 ++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 samples/NL/assign0.nl create mode 100644 samples/NewLisp/queens.nl diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 70d52869..65f012c3 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1923,6 +1923,13 @@ Myghty: tm_scope: none ace_mode: text +NL: + type: data + extensions: + - .nl + tm_scope: none + ace_mode: text + NSIS: type: programming extensions: diff --git a/samples/NL/assign0.nl b/samples/NL/assign0.nl new file mode 100644 index 00000000..9f1c58cf --- /dev/null +++ b/samples/NL/assign0.nl @@ -0,0 +1,84 @@ +g3 0 1 0 # problem assign0 + 9 6 1 0 6 # vars, constraints, objectives, ranges, eqns + 0 0 # nonlinear constraints, objectives + 0 0 # network constraints: nonlinear, linear + 0 0 0 # nonlinear vars in constraints, objectives, both + 0 0 0 1 # linear network variables; functions; arith, flags + 9 0 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o) + 18 9 # nonzeros in Jacobian, gradients + 0 0 # max name lengths: constraints, variables + 0 0 0 0 0 # common exprs: b,c,o,c1,o1 +C0 +n0 +C1 +n0 +C2 +n0 +C3 +n0 +C4 +n0 +C5 +n0 +O0 0 +n0 +r +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +b +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +k8 +2 +4 +6 +8 +10 +12 +14 +16 +J0 3 +0 1 +1 1 +2 1 +J1 3 +3 1 +4 1 +5 1 +J2 3 +6 1 +7 1 +8 1 +J3 3 +0 1 +3 1 +6 1 +J4 3 +1 1 +4 1 +7 1 +J5 3 +2 1 +5 1 +8 1 +G0 9 +0 1 +1 3 +2 3 +3 2 +4 3 +5 3 +6 3 +7 3 +8 2 diff --git a/samples/NewLisp/queens.nl b/samples/NewLisp/queens.nl new file mode 100644 index 00000000..61c04992 --- /dev/null +++ b/samples/NewLisp/queens.nl @@ -0,0 +1,49 @@ +#!/usr/bin/env newlisp + +(constant 'NUM 8) + +(define (intersects? q1 q2) + (or + (= (q1 0) (q2 0)) + (= (q1 1) (q2 1)) + (= (abs (- (q1 0) (q2 0))) (abs (- (q1 1) (q2 1)))))) + +(define (variant? alist) + (set 'logic nil) + (cond + ((= (length alist) 1) true) + ((> (length alist) 1) + (while (> (length alist) 1) + (set 'q (pop alist -1)) + (dolist (el alist) + (push + (intersects? + (list q (inc (length alist))) + (list el (+ 1 $idx))) + logic -1))) + (not (apply or logic))))) + +(define (fork-by-line alist) + (let (res '()) + (dolist (i (sequence 1 NUM)) + (set 'tmp alist) + (push i tmp -1) + (setf res (push tmp res -1))) + res)) + +(define (find-variants num) + (let (res '()) + (cond + ((< num 1) + (begin (println "num < 1") (exit))) + ((= num 1) + (dolist (i (sequence 1 NUM)) (push (list i) res -1))) + ((> num 1) + (dolist (v (find-variants (dec num))) + (set 'passed (filter variant? (fork-by-line v))) + (if (not (empty? passed)) (extend res passed))))) + res)) + +(set 'solutions (find-variants NUM)) +(println (length solutions)) +;;(exit) \ No newline at end of file From cc0c71b2776d0ec7d962cffc6e6e3cebfb2cc295 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Mon, 2 Mar 2015 22:13:17 +0100 Subject: [PATCH 48/66] New sample for NL --- samples/NL/balassign0.nl | 2284 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 2284 insertions(+) create mode 100644 samples/NL/balassign0.nl diff --git a/samples/NL/balassign0.nl b/samples/NL/balassign0.nl new file mode 100644 index 00000000..59d5690b --- /dev/null +++ b/samples/NL/balassign0.nl @@ -0,0 +1,2284 @@ +g3 2 1 0 # problem balassign0 + 160 121 1 0 26 # vars, constraints, objectives, ranges, eqns + 0 0 # nonlinear constraints, objectives + 0 0 # network constraints: nonlinear, linear + 0 0 0 # nonlinear vars in constraints, objectives, both + 0 0 0 1 # linear network variables; functions; arith, flags + 130 30 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o) + 1435 30 # nonzeros in Jacobian, gradients + 0 0 # max name lengths: constraints, variables + 0 0 0 0 0 # common exprs: b,c,o,c1,o1 +C0 +n0 +C1 +n0 +C2 +n0 +C3 +n0 +C4 +n0 +C5 +n0 +C6 +n0 +C7 +n0 +C8 +n0 +C9 +n0 +C10 +n0 +C11 +n0 +C12 +n0 +C13 +n0 +C14 +n0 +C15 +n0 +C16 +n0 +C17 +n0 +C18 +n0 +C19 +n0 +C20 +n0 +C21 +n0 +C22 +n0 +C23 +n0 +C24 +n0 +C25 +n0 +C26 +n0 +C27 +n0 +C28 +n0 +C29 +n0 +C30 +n0 +C31 +n0 +C32 +n0 +C33 +n0 +C34 +n0 +C35 +n0 +C36 +n0 +C37 +n0 +C38 +n0 +C39 +n0 +C40 +n0 +C41 +n0 +C42 +n0 +C43 +n0 +C44 +n0 +C45 +n0 +C46 +n0 +C47 +n0 +C48 +n0 +C49 +n0 +C50 +n0 +C51 +n0 +C52 +n0 +C53 +n0 +C54 +n0 +C55 +n0 +C56 +n0 +C57 +n0 +C58 +n0 +C59 +n0 +C60 +n0 +C61 +n0 +C62 +n0 +C63 +n0 +C64 +n0 +C65 +n0 +C66 +n0 +C67 +n0 +C68 +n0 +C69 +n0 +C70 +n0 +C71 +n0 +C72 +n0 +C73 +n0 +C74 +n0 +C75 +n0 +C76 +n0 +C77 +n0 +C78 +n0 +C79 +n0 +C80 +n0 +C81 +n0 +C82 +n0 +C83 +n0 +C84 +n0 +C85 +n0 +C86 +n0 +C87 +n0 +C88 +n0 +C89 +n0 +C90 +n0 +C91 +n0 +C92 +n0 +C93 +n0 +C94 +n0 +C95 +n0 +C96 +n0 +C97 +n0 +C98 +n0 +C99 +n0 +C100 +n0 +C101 +n0 +C102 +n0 +C103 +n0 +C104 +n0 +C105 +n0 +C106 +n0 +C107 +n0 +C108 +n0 +C109 +n0 +C110 +n0 +C111 +n0 +C112 +n0 +C113 +n0 +C114 +n0 +C115 +n0 +C116 +n0 +C117 +n0 +C118 +n0 +C119 +n0 +C120 +n0 +O0 0 +n0 +r +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +4 1 +1 0 +1 0 +1 0 +1 0 +1 0 +2 0 +2 0 +2 0 +2 0 +2 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +1 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +2 0 +b +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +0 0 1 +1 5 +2 6 +1 4 +1 0 +1 0 +1 0 +1 1 +1 0 +1 2 +1 0 +1 0 +1 4 +1 0 +1 2 +1 2 +1 0 +2 4 +2 1 +2 1 +2 1 +2 2 +2 1 +2 3 +2 1 +2 1 +2 5 +2 1 +2 3 +2 3 +2 1 +k159 +11 +22 +33 +44 +55 +64 +73 +82 +91 +100 +111 +122 +133 +144 +155 +166 +177 +188 +199 +210 +220 +230 +240 +250 +260 +270 +280 +290 +300 +310 +321 +332 +343 +354 +365 +375 +385 +395 +405 +415 +425 +435 +445 +455 +465 +476 +487 +498 +509 +520 +531 +542 +553 +564 +575 +586 +597 +608 +619 +630 +641 +652 +663 +674 +685 +696 +707 +718 +729 +740 +749 +758 +767 +776 +785 +796 +807 +818 +829 +840 +850 +860 +870 +880 +890 +899 +908 +917 +926 +935 +945 +955 +965 +975 +985 +995 +1005 +1015 +1025 +1035 +1046 +1057 +1068 +1079 +1090 +1099 +1108 +1117 +1126 +1135 +1146 +1157 +1168 +1179 +1190 +1201 +1212 +1223 +1234 +1245 +1255 +1265 +1275 +1285 +1295 +1304 +1313 +1322 +1331 +1340 +1345 +1350 +1355 +1355 +1355 +1355 +1360 +1360 +1365 +1365 +1365 +1370 +1370 +1375 +1380 +1380 +1385 +1390 +1390 +1395 +1400 +1400 +1405 +1410 +1410 +1415 +1420 +1425 +1430 +J0 5 +0 1 +1 1 +2 1 +3 1 +4 1 +J1 5 +5 1 +6 1 +7 1 +8 1 +9 1 +J2 5 +10 1 +11 1 +12 1 +13 1 +14 1 +J3 5 +15 1 +16 1 +17 1 +18 1 +19 1 +J4 5 +20 1 +21 1 +22 1 +23 1 +24 1 +J5 5 +25 1 +26 1 +27 1 +28 1 +29 1 +J6 5 +30 1 +31 1 +32 1 +33 1 +34 1 +J7 5 +35 1 +36 1 +37 1 +38 1 +39 1 +J8 5 +40 1 +41 1 +42 1 +43 1 +44 1 +J9 5 +45 1 +46 1 +47 1 +48 1 +49 1 +J10 5 +50 1 +51 1 +52 1 +53 1 +54 1 +J11 5 +55 1 +56 1 +57 1 +58 1 +59 1 +J12 5 +60 1 +61 1 +62 1 +63 1 +64 1 +J13 5 +65 1 +66 1 +67 1 +68 1 +69 1 +J14 5 +70 1 +71 1 +72 1 +73 1 +74 1 +J15 5 +75 1 +76 1 +77 1 +78 1 +79 1 +J16 5 +80 1 +81 1 +82 1 +83 1 +84 1 +J17 5 +85 1 +86 1 +87 1 +88 1 +89 1 +J18 5 +90 1 +91 1 +92 1 +93 1 +94 1 +J19 5 +95 1 +96 1 +97 1 +98 1 +99 1 +J20 5 +100 1 +101 1 +102 1 +103 1 +104 1 +J21 5 +105 1 +106 1 +107 1 +108 1 +109 1 +J22 5 +110 1 +111 1 +112 1 +113 1 +114 1 +J23 5 +115 1 +116 1 +117 1 +118 1 +119 1 +J24 5 +120 1 +121 1 +122 1 +123 1 +124 1 +J25 5 +125 1 +126 1 +127 1 +128 1 +129 1 +J26 27 +0 -1 +5 -1 +10 -1 +15 -1 +20 -1 +25 -1 +30 -1 +35 -1 +40 -1 +45 -1 +50 -1 +55 -1 +60 -1 +65 -1 +70 -1 +75 -1 +80 -1 +85 -1 +90 -1 +95 -1 +100 -1 +105 -1 +110 -1 +115 -1 +120 -1 +125 -1 +130 1 +J27 27 +1 -1 +6 -1 +11 -1 +16 -1 +21 -1 +26 -1 +31 -1 +36 -1 +41 -1 +46 -1 +51 -1 +56 -1 +61 -1 +66 -1 +71 -1 +76 -1 +81 -1 +86 -1 +91 -1 +96 -1 +101 -1 +106 -1 +111 -1 +116 -1 +121 -1 +126 -1 +130 1 +J28 27 +2 -1 +7 -1 +12 -1 +17 -1 +22 -1 +27 -1 +32 -1 +37 -1 +42 -1 +47 -1 +52 -1 +57 -1 +62 -1 +67 -1 +72 -1 +77 -1 +82 -1 +87 -1 +92 -1 +97 -1 +102 -1 +107 -1 +112 -1 +117 -1 +122 -1 +127 -1 +130 1 +J29 27 +3 -1 +8 -1 +13 -1 +18 -1 +23 -1 +28 -1 +33 -1 +38 -1 +43 -1 +48 -1 +53 -1 +58 -1 +63 -1 +68 -1 +73 -1 +78 -1 +83 -1 +88 -1 +93 -1 +98 -1 +103 -1 +108 -1 +113 -1 +118 -1 +123 -1 +128 -1 +130 1 +J30 27 +4 -1 +9 -1 +14 -1 +19 -1 +24 -1 +29 -1 +34 -1 +39 -1 +44 -1 +49 -1 +54 -1 +59 -1 +64 -1 +69 -1 +74 -1 +79 -1 +84 -1 +89 -1 +94 -1 +99 -1 +104 -1 +109 -1 +114 -1 +119 -1 +124 -1 +129 -1 +130 1 +J31 27 +0 -1 +5 -1 +10 -1 +15 -1 +20 -1 +25 -1 +30 -1 +35 -1 +40 -1 +45 -1 +50 -1 +55 -1 +60 -1 +65 -1 +70 -1 +75 -1 +80 -1 +85 -1 +90 -1 +95 -1 +100 -1 +105 -1 +110 -1 +115 -1 +120 -1 +125 -1 +131 1 +J32 27 +1 -1 +6 -1 +11 -1 +16 -1 +21 -1 +26 -1 +31 -1 +36 -1 +41 -1 +46 -1 +51 -1 +56 -1 +61 -1 +66 -1 +71 -1 +76 -1 +81 -1 +86 -1 +91 -1 +96 -1 +101 -1 +106 -1 +111 -1 +116 -1 +121 -1 +126 -1 +131 1 +J33 27 +2 -1 +7 -1 +12 -1 +17 -1 +22 -1 +27 -1 +32 -1 +37 -1 +42 -1 +47 -1 +52 -1 +57 -1 +62 -1 +67 -1 +72 -1 +77 -1 +82 -1 +87 -1 +92 -1 +97 -1 +102 -1 +107 -1 +112 -1 +117 -1 +122 -1 +127 -1 +131 1 +J34 27 +3 -1 +8 -1 +13 -1 +18 -1 +23 -1 +28 -1 +33 -1 +38 -1 +43 -1 +48 -1 +53 -1 +58 -1 +63 -1 +68 -1 +73 -1 +78 -1 +83 -1 +88 -1 +93 -1 +98 -1 +103 -1 +108 -1 +113 -1 +118 -1 +123 -1 +128 -1 +131 1 +J35 27 +4 -1 +9 -1 +14 -1 +19 -1 +24 -1 +29 -1 +34 -1 +39 -1 +44 -1 +49 -1 +54 -1 +59 -1 +64 -1 +69 -1 +74 -1 +79 -1 +84 -1 +89 -1 +94 -1 +99 -1 +104 -1 +109 -1 +114 -1 +119 -1 +124 -1 +129 -1 +131 1 +J36 21 +0 -1 +5 -1 +10 -1 +15 -1 +20 -1 +25 -1 +30 -1 +35 -1 +45 -1 +50 -1 +55 -1 +60 -1 +65 -1 +75 -1 +100 -1 +105 -1 +110 -1 +115 -1 +120 -1 +125 -1 +132 1 +J37 9 +0 -1 +10 -1 +45 -1 +70 -1 +75 -1 +90 -1 +95 -1 +100 -1 +136 1 +J38 15 +15 -1 +20 -1 +25 -1 +30 -1 +35 -1 +40 -1 +50 -1 +55 -1 +60 -1 +65 -1 +80 -1 +110 -1 +115 -1 +120 -1 +138 1 +J39 25 +0 -1 +5 -1 +10 -1 +15 -1 +25 -1 +30 -1 +40 -1 +45 -1 +50 -1 +55 -1 +60 -1 +65 -1 +70 -1 +75 -1 +80 -1 +85 -1 +90 -1 +95 -1 +100 -1 +105 -1 +110 -1 +115 -1 +120 -1 +125 -1 +141 1 +J40 13 +0 -1 +10 -1 +20 -1 +30 -1 +35 -1 +40 -1 +45 -1 +70 -1 +75 -1 +85 -1 +100 -1 +125 -1 +143 1 +J41 12 +5 -1 +15 -1 +50 -1 +55 -1 +60 -1 +65 -1 +80 -1 +90 -1 +95 -1 +110 -1 +115 -1 +144 1 +J42 21 +1 -1 +6 -1 +11 -1 +16 -1 +21 -1 +26 -1 +31 -1 +36 -1 +46 -1 +51 -1 +56 -1 +61 -1 +66 -1 +76 -1 +101 -1 +106 -1 +111 -1 +116 -1 +121 -1 +126 -1 +132 1 +J43 9 +1 -1 +11 -1 +46 -1 +71 -1 +76 -1 +91 -1 +96 -1 +101 -1 +136 1 +J44 15 +16 -1 +21 -1 +26 -1 +31 -1 +36 -1 +41 -1 +51 -1 +56 -1 +61 -1 +66 -1 +81 -1 +111 -1 +116 -1 +121 -1 +138 1 +J45 25 +1 -1 +6 -1 +11 -1 +16 -1 +26 -1 +31 -1 +41 -1 +46 -1 +51 -1 +56 -1 +61 -1 +66 -1 +71 -1 +76 -1 +81 -1 +86 -1 +91 -1 +96 -1 +101 -1 +106 -1 +111 -1 +116 -1 +121 -1 +126 -1 +141 1 +J46 13 +1 -1 +11 -1 +21 -1 +31 -1 +36 -1 +41 -1 +46 -1 +71 -1 +76 -1 +86 -1 +101 -1 +126 -1 +143 1 +J47 12 +6 -1 +16 -1 +51 -1 +56 -1 +61 -1 +66 -1 +81 -1 +91 -1 +96 -1 +111 -1 +116 -1 +144 1 +J48 21 +2 -1 +7 -1 +12 -1 +17 -1 +22 -1 +27 -1 +32 -1 +37 -1 +47 -1 +52 -1 +57 -1 +62 -1 +67 -1 +77 -1 +102 -1 +107 -1 +112 -1 +117 -1 +122 -1 +127 -1 +132 1 +J49 9 +2 -1 +12 -1 +47 -1 +72 -1 +77 -1 +92 -1 +97 -1 +102 -1 +136 1 +J50 15 +17 -1 +22 -1 +27 -1 +32 -1 +37 -1 +42 -1 +52 -1 +57 -1 +62 -1 +67 -1 +82 -1 +112 -1 +117 -1 +122 -1 +138 1 +J51 25 +2 -1 +7 -1 +12 -1 +17 -1 +27 -1 +32 -1 +42 -1 +47 -1 +52 -1 +57 -1 +62 -1 +67 -1 +72 -1 +77 -1 +82 -1 +87 -1 +92 -1 +97 -1 +102 -1 +107 -1 +112 -1 +117 -1 +122 -1 +127 -1 +141 1 +J52 13 +2 -1 +12 -1 +22 -1 +32 -1 +37 -1 +42 -1 +47 -1 +72 -1 +77 -1 +87 -1 +102 -1 +127 -1 +143 1 +J53 12 +7 -1 +17 -1 +52 -1 +57 -1 +62 -1 +67 -1 +82 -1 +92 -1 +97 -1 +112 -1 +117 -1 +144 1 +J54 21 +3 -1 +8 -1 +13 -1 +18 -1 +23 -1 +28 -1 +33 -1 +38 -1 +48 -1 +53 -1 +58 -1 +63 -1 +68 -1 +78 -1 +103 -1 +108 -1 +113 -1 +118 -1 +123 -1 +128 -1 +132 1 +J55 9 +3 -1 +13 -1 +48 -1 +73 -1 +78 -1 +93 -1 +98 -1 +103 -1 +136 1 +J56 15 +18 -1 +23 -1 +28 -1 +33 -1 +38 -1 +43 -1 +53 -1 +58 -1 +63 -1 +68 -1 +83 -1 +113 -1 +118 -1 +123 -1 +138 1 +J57 25 +3 -1 +8 -1 +13 -1 +18 -1 +28 -1 +33 -1 +43 -1 +48 -1 +53 -1 +58 -1 +63 -1 +68 -1 +73 -1 +78 -1 +83 -1 +88 -1 +93 -1 +98 -1 +103 -1 +108 -1 +113 -1 +118 -1 +123 -1 +128 -1 +141 1 +J58 13 +3 -1 +13 -1 +23 -1 +33 -1 +38 -1 +43 -1 +48 -1 +73 -1 +78 -1 +88 -1 +103 -1 +128 -1 +143 1 +J59 12 +8 -1 +18 -1 +53 -1 +58 -1 +63 -1 +68 -1 +83 -1 +93 -1 +98 -1 +113 -1 +118 -1 +144 1 +J60 21 +4 -1 +9 -1 +14 -1 +19 -1 +24 -1 +29 -1 +34 -1 +39 -1 +49 -1 +54 -1 +59 -1 +64 -1 +69 -1 +79 -1 +104 -1 +109 -1 +114 -1 +119 -1 +124 -1 +129 -1 +132 1 +J61 9 +4 -1 +14 -1 +49 -1 +74 -1 +79 -1 +94 -1 +99 -1 +104 -1 +136 1 +J62 15 +19 -1 +24 -1 +29 -1 +34 -1 +39 -1 +44 -1 +54 -1 +59 -1 +64 -1 +69 -1 +84 -1 +114 -1 +119 -1 +124 -1 +138 1 +J63 25 +4 -1 +9 -1 +14 -1 +19 -1 +29 -1 +34 -1 +44 -1 +49 -1 +54 -1 +59 -1 +64 -1 +69 -1 +74 -1 +79 -1 +84 -1 +89 -1 +94 -1 +99 -1 +104 -1 +109 -1 +114 -1 +119 -1 +124 -1 +129 -1 +141 1 +J64 13 +4 -1 +14 -1 +24 -1 +34 -1 +39 -1 +44 -1 +49 -1 +74 -1 +79 -1 +89 -1 +104 -1 +129 -1 +143 1 +J65 12 +9 -1 +19 -1 +54 -1 +59 -1 +64 -1 +69 -1 +84 -1 +94 -1 +99 -1 +114 -1 +119 -1 +144 1 +J66 21 +0 -1 +5 -1 +10 -1 +15 -1 +20 -1 +25 -1 +30 -1 +35 -1 +45 -1 +50 -1 +55 -1 +60 -1 +65 -1 +75 -1 +100 -1 +105 -1 +110 -1 +115 -1 +120 -1 +125 -1 +146 1 +J67 4 +40 -1 +85 -1 +90 -1 +147 1 +J68 3 +80 -1 +95 -1 +149 1 +J69 9 +0 -1 +10 -1 +45 -1 +70 -1 +75 -1 +90 -1 +95 -1 +100 -1 +150 1 +J70 15 +15 -1 +20 -1 +25 -1 +30 -1 +35 -1 +40 -1 +50 -1 +55 -1 +60 -1 +65 -1 +80 -1 +110 -1 +115 -1 +120 -1 +152 1 +J71 3 +85 -1 +105 -1 +153 1 +J72 25 +0 -1 +5 -1 +10 -1 +15 -1 +25 -1 +30 -1 +40 -1 +45 -1 +50 -1 +55 -1 +60 -1 +65 -1 +70 -1 +75 -1 +80 -1 +85 -1 +90 -1 +95 -1 +100 -1 +105 -1 +110 -1 +115 -1 +120 -1 +125 -1 +155 1 +J73 3 +20 -1 +35 -1 +156 1 +J74 13 +0 -1 +10 -1 +20 -1 +30 -1 +35 -1 +40 -1 +45 -1 +70 -1 +75 -1 +85 -1 +100 -1 +125 -1 +157 1 +J75 12 +5 -1 +15 -1 +50 -1 +55 -1 +60 -1 +65 -1 +80 -1 +90 -1 +95 -1 +110 -1 +115 -1 +158 1 +J76 4 +25 -1 +105 -1 +120 -1 +159 1 +J77 21 +1 -1 +6 -1 +11 -1 +16 -1 +21 -1 +26 -1 +31 -1 +36 -1 +46 -1 +51 -1 +56 -1 +61 -1 +66 -1 +76 -1 +101 -1 +106 -1 +111 -1 +116 -1 +121 -1 +126 -1 +146 1 +J78 4 +41 -1 +86 -1 +91 -1 +147 1 +J79 3 +81 -1 +96 -1 +149 1 +J80 9 +1 -1 +11 -1 +46 -1 +71 -1 +76 -1 +91 -1 +96 -1 +101 -1 +150 1 +J81 15 +16 -1 +21 -1 +26 -1 +31 -1 +36 -1 +41 -1 +51 -1 +56 -1 +61 -1 +66 -1 +81 -1 +111 -1 +116 -1 +121 -1 +152 1 +J82 3 +86 -1 +106 -1 +153 1 +J83 25 +1 -1 +6 -1 +11 -1 +16 -1 +26 -1 +31 -1 +41 -1 +46 -1 +51 -1 +56 -1 +61 -1 +66 -1 +71 -1 +76 -1 +81 -1 +86 -1 +91 -1 +96 -1 +101 -1 +106 -1 +111 -1 +116 -1 +121 -1 +126 -1 +155 1 +J84 3 +21 -1 +36 -1 +156 1 +J85 13 +1 -1 +11 -1 +21 -1 +31 -1 +36 -1 +41 -1 +46 -1 +71 -1 +76 -1 +86 -1 +101 -1 +126 -1 +157 1 +J86 12 +6 -1 +16 -1 +51 -1 +56 -1 +61 -1 +66 -1 +81 -1 +91 -1 +96 -1 +111 -1 +116 -1 +158 1 +J87 4 +26 -1 +106 -1 +121 -1 +159 1 +J88 21 +2 -1 +7 -1 +12 -1 +17 -1 +22 -1 +27 -1 +32 -1 +37 -1 +47 -1 +52 -1 +57 -1 +62 -1 +67 -1 +77 -1 +102 -1 +107 -1 +112 -1 +117 -1 +122 -1 +127 -1 +146 1 +J89 4 +42 -1 +87 -1 +92 -1 +147 1 +J90 3 +82 -1 +97 -1 +149 1 +J91 9 +2 -1 +12 -1 +47 -1 +72 -1 +77 -1 +92 -1 +97 -1 +102 -1 +150 1 +J92 15 +17 -1 +22 -1 +27 -1 +32 -1 +37 -1 +42 -1 +52 -1 +57 -1 +62 -1 +67 -1 +82 -1 +112 -1 +117 -1 +122 -1 +152 1 +J93 3 +87 -1 +107 -1 +153 1 +J94 25 +2 -1 +7 -1 +12 -1 +17 -1 +27 -1 +32 -1 +42 -1 +47 -1 +52 -1 +57 -1 +62 -1 +67 -1 +72 -1 +77 -1 +82 -1 +87 -1 +92 -1 +97 -1 +102 -1 +107 -1 +112 -1 +117 -1 +122 -1 +127 -1 +155 1 +J95 3 +22 -1 +37 -1 +156 1 +J96 13 +2 -1 +12 -1 +22 -1 +32 -1 +37 -1 +42 -1 +47 -1 +72 -1 +77 -1 +87 -1 +102 -1 +127 -1 +157 1 +J97 12 +7 -1 +17 -1 +52 -1 +57 -1 +62 -1 +67 -1 +82 -1 +92 -1 +97 -1 +112 -1 +117 -1 +158 1 +J98 4 +27 -1 +107 -1 +122 -1 +159 1 +J99 21 +3 -1 +8 -1 +13 -1 +18 -1 +23 -1 +28 -1 +33 -1 +38 -1 +48 -1 +53 -1 +58 -1 +63 -1 +68 -1 +78 -1 +103 -1 +108 -1 +113 -1 +118 -1 +123 -1 +128 -1 +146 1 +J100 4 +43 -1 +88 -1 +93 -1 +147 1 +J101 3 +83 -1 +98 -1 +149 1 +J102 9 +3 -1 +13 -1 +48 -1 +73 -1 +78 -1 +93 -1 +98 -1 +103 -1 +150 1 +J103 15 +18 -1 +23 -1 +28 -1 +33 -1 +38 -1 +43 -1 +53 -1 +58 -1 +63 -1 +68 -1 +83 -1 +113 -1 +118 -1 +123 -1 +152 1 +J104 3 +88 -1 +108 -1 +153 1 +J105 25 +3 -1 +8 -1 +13 -1 +18 -1 +28 -1 +33 -1 +43 -1 +48 -1 +53 -1 +58 -1 +63 -1 +68 -1 +73 -1 +78 -1 +83 -1 +88 -1 +93 -1 +98 -1 +103 -1 +108 -1 +113 -1 +118 -1 +123 -1 +128 -1 +155 1 +J106 3 +23 -1 +38 -1 +156 1 +J107 13 +3 -1 +13 -1 +23 -1 +33 -1 +38 -1 +43 -1 +48 -1 +73 -1 +78 -1 +88 -1 +103 -1 +128 -1 +157 1 +J108 12 +8 -1 +18 -1 +53 -1 +58 -1 +63 -1 +68 -1 +83 -1 +93 -1 +98 -1 +113 -1 +118 -1 +158 1 +J109 4 +28 -1 +108 -1 +123 -1 +159 1 +J110 21 +4 -1 +9 -1 +14 -1 +19 -1 +24 -1 +29 -1 +34 -1 +39 -1 +49 -1 +54 -1 +59 -1 +64 -1 +69 -1 +79 -1 +104 -1 +109 -1 +114 -1 +119 -1 +124 -1 +129 -1 +146 1 +J111 4 +44 -1 +89 -1 +94 -1 +147 1 +J112 3 +84 -1 +99 -1 +149 1 +J113 9 +4 -1 +14 -1 +49 -1 +74 -1 +79 -1 +94 -1 +99 -1 +104 -1 +150 1 +J114 15 +19 -1 +24 -1 +29 -1 +34 -1 +39 -1 +44 -1 +54 -1 +59 -1 +64 -1 +69 -1 +84 -1 +114 -1 +119 -1 +124 -1 +152 1 +J115 3 +89 -1 +109 -1 +153 1 +J116 25 +4 -1 +9 -1 +14 -1 +19 -1 +29 -1 +34 -1 +44 -1 +49 -1 +54 -1 +59 -1 +64 -1 +69 -1 +74 -1 +79 -1 +84 -1 +89 -1 +94 -1 +99 -1 +104 -1 +109 -1 +114 -1 +119 -1 +124 -1 +129 -1 +155 1 +J117 3 +24 -1 +39 -1 +156 1 +J118 13 +4 -1 +14 -1 +24 -1 +34 -1 +39 -1 +44 -1 +49 -1 +74 -1 +79 -1 +89 -1 +104 -1 +129 -1 +157 1 +J119 12 +9 -1 +19 -1 +54 -1 +59 -1 +64 -1 +69 -1 +84 -1 +94 -1 +99 -1 +114 -1 +119 -1 +158 1 +J120 4 +29 -1 +109 -1 +124 -1 +159 1 +G0 30 +130 -1 +131 1 +132 -1 +133 -1 +134 -1 +135 -1 +136 -1 +137 -1 +138 -1 +139 -1 +140 -1 +141 -1 +142 -1 +143 -1 +144 -1 +145 -1 +146 1 +147 1 +148 1 +149 1 +150 1 +151 1 +152 1 +153 1 +154 1 +155 1 +156 1 +157 1 +158 1 +159 1 From 7f3f0327c2e497921d3fd5ad1cf5554ced932e89 Mon Sep 17 00:00:00 2001 From: Simon Cooksey Date: Tue, 3 Mar 2015 12:45:08 +0000 Subject: [PATCH 49/66] Added XC syntax --- .gitmodules | 3 +++ grammars.yml | 4 ++++ lib/linguist/languages.yml | 2 +- vendor/grammars/xc.tmbundle | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) create mode 160000 vendor/grammars/xc.tmbundle diff --git a/.gitmodules b/.gitmodules index 59844ad5..6990a425 100644 --- a/.gitmodules +++ b/.gitmodules @@ -642,3 +642,6 @@ [submodule "vendor/grammars/sublime-varnish"] path = vendor/grammars/sublime-varnish url = https://github.com/brandonwamboldt/sublime-varnish +[submodule "vendor/grammars/xc.tmbundle"] + path = vendor/grammars/xc.tmbundle + url = https://github.com/graymalkin/xc.tmbundle diff --git a/grammars.yml b/grammars.yml index 9edb205c..695dbd44 100644 --- a/grammars.yml +++ b/grammars.yml @@ -530,6 +530,10 @@ vendor/grammars/verilog.tmbundle: - source.verilog vendor/grammars/x86-assembly-textmate-bundle: - source.asm.x86 +vendor/grammars/xc.tmbundle/: +- source.c +- source.c.platform +- source.xc vendor/grammars/xml.tmbundle: - text.xml - text.xml.xsl diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 70d52869..6c6f0a65 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3237,7 +3237,7 @@ XC: color: "#99DA07" extensions: - .xc - tm_scope: source.c + tm_scope: source.xc ace_mode: c_cpp XML: diff --git a/vendor/grammars/xc.tmbundle b/vendor/grammars/xc.tmbundle new file mode 160000 index 00000000..83a61a26 --- /dev/null +++ b/vendor/grammars/xc.tmbundle @@ -0,0 +1 @@ +Subproject commit 83a61a26308208ee95354965fe023954c11b6e30 From 3a56d632e1456301424d6955842b8f5a22229f52 Mon Sep 17 00:00:00 2001 From: Simon Cooksey Date: Tue, 3 Mar 2015 13:02:58 +0000 Subject: [PATCH 50/66] Fixed build by removing duplicate C syntax definition --- grammars.yml | 2 -- vendor/grammars/xc.tmbundle | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/grammars.yml b/grammars.yml index 695dbd44..048f7da8 100644 --- a/grammars.yml +++ b/grammars.yml @@ -531,8 +531,6 @@ vendor/grammars/verilog.tmbundle: vendor/grammars/x86-assembly-textmate-bundle: - source.asm.x86 vendor/grammars/xc.tmbundle/: -- source.c -- source.c.platform - source.xc vendor/grammars/xml.tmbundle: - text.xml diff --git a/vendor/grammars/xc.tmbundle b/vendor/grammars/xc.tmbundle index 83a61a26..7239c92b 160000 --- a/vendor/grammars/xc.tmbundle +++ b/vendor/grammars/xc.tmbundle @@ -1 +1 @@ -Subproject commit 83a61a26308208ee95354965fe023954c11b6e30 +Subproject commit 7239c92bd612b01fc5bfea36056d530db78d6c64 From c7b4cf636f821955354a4958e943c018cdf7b816 Mon Sep 17 00:00:00 2001 From: Lars Brinkhoff Date: Wed, 4 Mar 2015 21:25:12 +0100 Subject: [PATCH 51/66] GLSL should not be in the C group. --- lib/linguist/languages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 52bbaa36..9f2a742a 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -994,7 +994,6 @@ GDScript: ace_mode: text GLSL: - group: C type: programming extensions: - .glsl From 2d5476f6c844fcae21858c39c8a120e2d3fdf632 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Thu, 5 Mar 2015 10:01:28 -0800 Subject: [PATCH 52/66] Yield the block in LocalInstrumenter --- test/test_instrumentation.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_instrumentation.rb b/test/test_instrumentation.rb index 9078680c..b9e5c3e9 100644 --- a/test/test_instrumentation.rb +++ b/test/test_instrumentation.rb @@ -14,6 +14,7 @@ class TestInstrumentation < Minitest::Test def instrument(name, *args) @events << Event.new(name, args) + yield end end From e8326529b5121f80c80b58216c554f5de4982cd6 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Thu, 5 Mar 2015 10:03:01 -0800 Subject: [PATCH 53/66] Pass blob to instrumentation --- lib/linguist/language.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index bf0dfc33..e0e35602 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -105,7 +105,7 @@ module Linguist # Bail early if the blob is binary or empty. return nil if blob.likely_binary? || blob.binary? || blob.empty? - Linguist.instrument("linguist.detection") do + Linguist.instrument("linguist.detection", :blob => blob) do # Call each strategy until one candidate is returned. languages = [] strategy = nil From 3dcdc11c1b6cf28c2b78d2dba83de4cfce58d132 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Thu, 5 Mar 2015 10:03:51 -0800 Subject: [PATCH 54/66] Avoid passing block to detected instrumenter --- lib/linguist/language.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index e0e35602..6c551bf7 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -125,9 +125,9 @@ module Linguist end end - Linguist.instrument("linguist.detected", :blob => blob, :strategy => strategy, :language => languages.first) do - languages.first - end + Linguist.instrument("linguist.detected", :blob => blob, :strategy => strategy, :language => languages.first) + + languages.first end end From 7fdead01009570298d4d6777192880b2d1422a90 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Thu, 5 Mar 2015 10:11:08 -0800 Subject: [PATCH 55/66] Only yield if block given --- test/test_instrumentation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_instrumentation.rb b/test/test_instrumentation.rb index b9e5c3e9..9fd5dc66 100644 --- a/test/test_instrumentation.rb +++ b/test/test_instrumentation.rb @@ -14,7 +14,7 @@ class TestInstrumentation < Minitest::Test def instrument(name, *args) @events << Event.new(name, args) - yield + yield if block_given? end end From 1bc1803628e5b74d813d2db46ffd0756d6c582f3 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 5 Mar 2015 12:50:12 -0600 Subject: [PATCH 56/66] Check for block here too --- lib/linguist.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist.rb b/lib/linguist.rb index 4419ff5b..3929efb9 100644 --- a/lib/linguist.rb +++ b/lib/linguist.rb @@ -14,7 +14,7 @@ class << Linguist if instrumenter instrumenter.instrument(*args, &bk) else - yield + yield if block_given? end end end From a1010b8cf810f09a066937011928d2d4ebc00415 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 5 Mar 2015 13:21:07 -0600 Subject: [PATCH 57/66] Actually return the strategy --- lib/linguist/language.rb | 5 +++-- test/test_instrumentation.rb | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 6c551bf7..a1ff3318 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -108,9 +108,10 @@ module Linguist Linguist.instrument("linguist.detection", :blob => blob) do # Call each strategy until one candidate is returned. languages = [] - strategy = nil + returning_strategy = nil STRATEGIES.each do |strategy| + returning_strategy = strategy candidates = Linguist.instrument("linguist.strategy", :blob => blob, :strategy => strategy, :candidates => languages) do strategy.call(blob, languages) end @@ -125,7 +126,7 @@ module Linguist end end - Linguist.instrument("linguist.detected", :blob => blob, :strategy => strategy, :language => languages.first) + Linguist.instrument("linguist.detected", :blob => blob, :strategy => returning_strategy, :language => languages.first) languages.first end diff --git a/test/test_instrumentation.rb b/test/test_instrumentation.rb index 9fd5dc66..ab0615e5 100644 --- a/test/test_instrumentation.rb +++ b/test/test_instrumentation.rb @@ -38,7 +38,13 @@ class TestInstrumentation < Minitest::Test blob = fixture_blob("Data/Modelines/ruby") Language.detect(blob) + detect_event = Linguist.instrumenter.events.last + detect_event_payload = detect_event[:args].first + assert_equal 3, Linguist.instrumenter.events.size - assert_equal "linguist.detected", Linguist.instrumenter.events.last.name + assert_equal "linguist.detected", detect_event.name + assert_equal Language['Ruby'], detect_event_payload[:language] + assert_equal blob, detect_event_payload[:blob] + assert_equal Linguist::Strategy::Modeline, detect_event_payload[:strategy] end end From 44f505e687f06981fe02a660aafddf476ba3180e Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 5 Mar 2015 15:08:05 -0600 Subject: [PATCH 58/66] Grammars update --- vendor/grammars/NimLime | 2 +- vendor/grammars/PHP-Twig.tmbundle | 2 +- vendor/grammars/SublimePapyrus | 2 +- vendor/grammars/dart-sublime-bundle | 2 +- vendor/grammars/elixir-tmbundle | 2 +- vendor/grammars/factor | 2 +- vendor/grammars/fsharpbinding | 2 +- vendor/grammars/grace-tmbundle | 2 +- vendor/grammars/haxe-sublime-bundle | 2 +- vendor/grammars/language-gfm | 2 +- vendor/grammars/mercury-tmlanguage | 2 +- vendor/grammars/restructuredtext.tmbundle | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vendor/grammars/NimLime b/vendor/grammars/NimLime index fac6b182..ae0b75d9 160000 --- a/vendor/grammars/NimLime +++ b/vendor/grammars/NimLime @@ -1 +1 @@ -Subproject commit fac6b182e8a92a65c9e144c578948d7b51048f26 +Subproject commit ae0b75d99a60f555e1b5cbab53eaed2ca9ca9101 diff --git a/vendor/grammars/PHP-Twig.tmbundle b/vendor/grammars/PHP-Twig.tmbundle index ad0f5147..f4f7529a 160000 --- a/vendor/grammars/PHP-Twig.tmbundle +++ b/vendor/grammars/PHP-Twig.tmbundle @@ -1 +1 @@ -Subproject commit ad0f5147e6d7ae70469084659cffcfd22575869e +Subproject commit f4f7529ac2a07527caa7c9154b87c96d17e18aa1 diff --git a/vendor/grammars/SublimePapyrus b/vendor/grammars/SublimePapyrus index e1b78aac..6f4e954f 160000 --- a/vendor/grammars/SublimePapyrus +++ b/vendor/grammars/SublimePapyrus @@ -1 +1 @@ -Subproject commit e1b78aacb6b0ab8b4c26ea897b128335f8ed939c +Subproject commit 6f4e954f35976f72f2a620af68aa0ba73e48478b diff --git a/vendor/grammars/dart-sublime-bundle b/vendor/grammars/dart-sublime-bundle index 21096f24..65c9cd9a 160000 --- a/vendor/grammars/dart-sublime-bundle +++ b/vendor/grammars/dart-sublime-bundle @@ -1 +1 @@ -Subproject commit 21096f24d8a34668d54ad31b8902ab5c709c1c07 +Subproject commit 65c9cd9a6540f6e47e5770314e13de7df05b2d2b diff --git a/vendor/grammars/elixir-tmbundle b/vendor/grammars/elixir-tmbundle index 9c63ff09..99910870 160000 --- a/vendor/grammars/elixir-tmbundle +++ b/vendor/grammars/elixir-tmbundle @@ -1 +1 @@ -Subproject commit 9c63ff09bd411d3e5c5a737145fc33d288804c9c +Subproject commit 99910870bb1cd095fc0af9010f018f1ae9e95b4e diff --git a/vendor/grammars/factor b/vendor/grammars/factor index fe2c2d23..e237b49f 160000 --- a/vendor/grammars/factor +++ b/vendor/grammars/factor @@ -1 +1 @@ -Subproject commit fe2c2d23de9e300d7cd1b04e139dfbdd2069d00a +Subproject commit e237b49f83c12aff3070c570404ef6bb19d1cc95 diff --git a/vendor/grammars/fsharpbinding b/vendor/grammars/fsharpbinding index a008fe9c..513db1c4 160000 --- a/vendor/grammars/fsharpbinding +++ b/vendor/grammars/fsharpbinding @@ -1 +1 @@ -Subproject commit a008fe9c64d454132941eb72334c52e4ad93266e +Subproject commit 513db1c44390c4967afe4dd220b9ec4f6a52cc3e diff --git a/vendor/grammars/grace-tmbundle b/vendor/grammars/grace-tmbundle index 6bea212a..2fba162c 160000 --- a/vendor/grammars/grace-tmbundle +++ b/vendor/grammars/grace-tmbundle @@ -1 +1 @@ -Subproject commit 6bea212a5843e152cd605ec6075eb7352cbeaf0d +Subproject commit 2fba162ce7cfb37421acb097be6aa31aaf414155 diff --git a/vendor/grammars/haxe-sublime-bundle b/vendor/grammars/haxe-sublime-bundle index 50c5aa0e..84a4fab1 160000 --- a/vendor/grammars/haxe-sublime-bundle +++ b/vendor/grammars/haxe-sublime-bundle @@ -1 +1 @@ -Subproject commit 50c5aa0e10f277f83dfe3d0e269a1043271be4df +Subproject commit 84a4fab144c185f4430f68cf10de35a7dfc79cb7 diff --git a/vendor/grammars/language-gfm b/vendor/grammars/language-gfm index 5f5df306..6ca2ea2a 160000 --- a/vendor/grammars/language-gfm +++ b/vendor/grammars/language-gfm @@ -1 +1 @@ -Subproject commit 5f5df3064c9dccbfd8dac8d260b0d4a843ac88a5 +Subproject commit 6ca2ea2ac50fe02cde1bcec114c66101129daab6 diff --git a/vendor/grammars/mercury-tmlanguage b/vendor/grammars/mercury-tmlanguage index 1cb8e949..cb57d42d 160000 --- a/vendor/grammars/mercury-tmlanguage +++ b/vendor/grammars/mercury-tmlanguage @@ -1 +1 @@ -Subproject commit 1cb8e94922803658040bc29aa732c1671e2afe5b +Subproject commit cb57d42dbe343d3809c3dd7946f28f6354a2687e diff --git a/vendor/grammars/restructuredtext.tmbundle b/vendor/grammars/restructuredtext.tmbundle index 43fc7b1f..608d8bcd 160000 --- a/vendor/grammars/restructuredtext.tmbundle +++ b/vendor/grammars/restructuredtext.tmbundle @@ -1 +1 @@ -Subproject commit 43fc7b1ff351d6733f7ce136aafe3091e77b4347 +Subproject commit 608d8bcdea179d4bf3def6244e0d9cf7705f2fea From bdb2a221a5ca81b8a75028a0aa5efbb33d26e2a8 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 5 Mar 2015 15:13:54 -0600 Subject: [PATCH 59/66] Bumping version to 4.4.3 --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 86dd6961..9a84798b 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.4.2" + VERSION = "4.4.3" end From 0d848b342fac474e754b3d969cbef821f9157510 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 6 Mar 2015 07:07:41 +0100 Subject: [PATCH 60/66] .jbuilder as a Ruby extension --- lib/linguist/languages.yml | 1 + samples/Ruby/index.json.jbuilder | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 samples/Ruby/index.json.jbuilder diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 9f2a742a..1cc8f347 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2666,6 +2666,7 @@ Ruby: - .gemspec - .god - .irbrc + - .jbuilder - .mspec - .pluginspec - .podspec diff --git a/samples/Ruby/index.json.jbuilder b/samples/Ruby/index.json.jbuilder new file mode 100644 index 00000000..26c7bc67 --- /dev/null +++ b/samples/Ruby/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@courts) do |court| + json.extract! court, :id, :name_r, :region, :region_r, :email, :website + json.url court_url(court, format: :json) +end From 2d03eae413a27c478a8f5686be01d1640b464cd2 Mon Sep 17 00:00:00 2001 From: aquileia Date: Fri, 6 Mar 2015 13:34:19 +0100 Subject: [PATCH 61/66] Exclude gettext catalogues from statistics Gettext catalogues are used for translations and are thus essentially prose, but were classified as "programming" in 507d191d7d. In large projects like e.g. wesnoth/wesnoth, gettext can dominate the language statistics with about 95% although the actual code is C++. --- 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 9f2a742a..2dfb611e 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1047,7 +1047,7 @@ Gentoo Eclass: ace_mode: sh Gettext Catalog: - type: programming + type: prose search_term: pot searchable: false aliases: From 866466852479fc11fe6bacc3b7460f51eb6ce271 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 6 Mar 2015 14:26:09 -0500 Subject: [PATCH 62/66] Update popular languages I took all non-fork repositories on github.com, grouped them by their primary language, and took the 25 most popular. --- lib/linguist/popular.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/linguist/popular.yml b/lib/linguist/popular.yml index 1a5cb750..afb68021 100644 --- a/lib/linguist/popular.yml +++ b/lib/linguist/popular.yml @@ -9,21 +9,21 @@ - CSS - Clojure - CoffeeScript -- Common Lisp -- Diff -- Emacs Lisp -- Erlang +- Go - HTML - Haskell - Java - JavaScript - Lua +- Matlab - Objective-C - PHP - Perl - Python +- R - Ruby -- SQL - Scala -- Scheme - Shell +- Swift +- TeX +- VimL From 8da458e1a85ba72dcb1a36a4d51d0b7a05693328 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sun, 8 Mar 2015 16:22:41 -0700 Subject: [PATCH 63/66] apt-get update before downloading deps --- .travis.yml | 1 - script/travis/before_install | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4d0c2351..52540b57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: false before_install: script/travis/before_install rvm: - 1.9.3 diff --git a/script/travis/before_install b/script/travis/before_install index 442f6718..93ef383c 100755 --- a/script/travis/before_install +++ b/script/travis/before_install @@ -5,6 +5,8 @@ set -ex # Fetch all commits/refs needed to run our tests. git fetch origin master:master v2.0.0:v2.0.0 test/attributes:test/attributes test/master:test/master +sudo apt-get update + script/vendor-deb libicu48 libicu-dev if ruby -e 'exit RUBY_VERSION >= "2.0" && RUBY_VERSION < "2.1"'; then # Workaround for https://bugs.ruby-lang.org/issues/8074. We can't use this From 5ef944e8b81f39c21de755f66947602620604689 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 10 Mar 2015 11:16:17 +0200 Subject: [PATCH 64/66] Detect *.sma files as SourcePawn --- lib/linguist/languages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 62dfe0f3..ada5149f 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2936,6 +2936,7 @@ SourcePawn: - sourcemod extensions: - .sp + - .sma tm_scope: source.sp ace_mode: text From 8b9ad131d1a3f9b9a3d9634fc2326b327088e1ed Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 10 Mar 2015 16:20:59 +0200 Subject: [PATCH 65/66] Create foo.sma --- samples/SourcePawn/foo.sma | 272 +++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 samples/SourcePawn/foo.sma diff --git a/samples/SourcePawn/foo.sma b/samples/SourcePawn/foo.sma new file mode 100644 index 00000000..e03b77a2 --- /dev/null +++ b/samples/SourcePawn/foo.sma @@ -0,0 +1,272 @@ +// vim: set ts=4 sw=4 tw=99 noet: +// +// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). +// Copyright (C) The AMX Mod X Development Team. +// +// This software is licensed under the GNU General Public License, version 3 or higher. +// Additional exceptions apply. For full license details, see LICENSE.txt or visit: +// https://alliedmods.net/amxmodx-license + +// +// TimeLeft Plugin +// + +#include + +const TASK_TIMEREMAIN_SHORT = 8648458 // 0.8s repeat task +const TASK_TIMEREMAIN_LARGE = 34543 // 1.0s repeat task + +// time display flags +const TD_BOTTOM_WHITE_TEXT = 1 // a - display white text on bottom +const TD_USE_VOICE = 2 // b - use voice +const TD_NO_REMAINING_VOICE = 4 // c - don't add "remaining" (only in voice) +const TD_NO_HOURS_MINS_SECS_VOICE = 8 // d - don't add "hours/minutes/seconds" (only in voice) +const TD_SHOW_SPEAK_VALUES_BELOW = 16 // e - show/speak if current time is less than this set in parameter + +new g_TimeSet[32][2] +new g_LastTime +new g_CountDown +new g_Switch + +// pcvars +new g_amx_time_voice, g_amx_timeleft +new g_mp_timelimit + +public plugin_init() +{ + register_plugin("TimeLeft", AMXX_VERSION_STR, "AMXX Dev Team") + register_dictionary("timeleft.txt") + g_amx_time_voice = register_cvar("amx_time_voice", "1") + register_srvcmd("amx_time_display", "setDisplaying") + g_amx_timeleft = register_cvar("amx_timeleft", "00:00", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_UNLOGGED|FCVAR_SPONLY) + register_clcmd("say timeleft", "sayTimeLeft", 0, "- displays timeleft") + register_clcmd("say thetime", "sayTheTime", 0, "- displays current time") + + set_task(0.8, "timeRemain", TASK_TIMEREMAIN_SHORT, "", 0, "b") + + g_mp_timelimit = get_cvar_pointer("mp_timelimit") +} + +public sayTheTime(id) +{ + if (get_pcvar_num(g_amx_time_voice)) + { + new mhours[6], mmins[6], whours[32], wmins[32], wpm[6] + + get_time("%H", mhours, charsmax(mhours)) + get_time("%M", mmins, charsmax(mmins)) + + new mins = str_to_num(mmins) + new hrs = str_to_num(mhours) + + if (mins) + num_to_word(mins, wmins, charsmax(wmins)) + else + wmins[0] = EOS + + if (hrs < 12) + wpm = "am " + else + { + if (hrs > 12) hrs -= 12 + wpm = "pm " + } + + if (hrs) + num_to_word(hrs, whours, charsmax(whours)) + else + whours = "twelve " + + client_cmd(id, "spk ^"fvox/time_is_now %s_period %s%s^"", whours, wmins, wpm) + } + + new ctime[64] + + get_time("%m/%d/%Y - %H:%M:%S", ctime, charsmax(ctime)) + client_print(0, print_chat, "%L: %s", LANG_PLAYER, "THE_TIME", ctime) + + return PLUGIN_CONTINUE +} + +public sayTimeLeft(id) +{ + if (get_pcvar_float(g_mp_timelimit)) + { + new a = get_timeleft() + + if (get_pcvar_num(g_amx_time_voice)) + { + new svoice[128] + setTimeVoice(svoice, charsmax(svoice), 0, a) + client_cmd(id, "%s", svoice) + } + client_print(0, print_chat, "%L: %d:%02d", LANG_PLAYER, "TIME_LEFT", (a / 60), (a % 60)) + } + else + client_print(0, print_chat, "%L", LANG_PLAYER, "NO_T_LIMIT") + + return PLUGIN_CONTINUE +} + +setTimeText(text[], len, tmlf, id) +{ + new secs = tmlf % 60 + new mins = tmlf / 60 + + if (secs == 0) + formatex(text, len, "%d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE") + else if (mins == 0) + formatex(text, len, "%d %L", secs, id, (secs > 1) ? "SECONDS" : "SECOND") + else + formatex(text, len, "%d %L %d %L", mins, id, (mins > 1) ? "MINUTES" : "MINUTE", secs, id, (secs > 1) ? "SECONDS" : "SECOND") +} + +setTimeVoice(text[], len, flags, tmlf) +{ + new temp[7][32] + new secs = tmlf % 60 + new mins = tmlf / 60 + + // for (new a = 0;a < 7;++a) // we just created it, already null + // temp[a][0] = 0 + + if (secs > 0) + { + num_to_word(secs, temp[4], charsmax(temp[])) + + if ( ~flags & TD_NO_HOURS_MINS_SECS_VOICE ) + temp[5] = "seconds " /* there is no "second" in default hl */ + } + + if (mins > 59) + { + new hours = mins / 60 + + num_to_word(hours, temp[0], charsmax(temp[])) + + if ( ~flags & TD_NO_HOURS_MINS_SECS_VOICE ) + temp[1] = "hours " + + mins = mins % 60 + } + + if (mins > 0) + { + num_to_word(mins, temp[2], charsmax(temp[])) + + if ( ~flags & TD_NO_HOURS_MINS_SECS_VOICE ) + temp[3] = "minutes " + } + + if ( ~flags & TD_NO_REMAINING_VOICE ) + temp[6] = "remaining " + + return formatex(text, len, "spk ^"vox/%s%s%s%s%s%s%s^"", temp[0], temp[1], temp[2], temp[3], temp[4], temp[5], temp[6]) +} + +findDispFormat(_time) +{ + // it is important to check i _time) + { + if (!g_Switch) + { + g_CountDown = g_Switch = _time + remove_task(TASK_TIMEREMAIN_SHORT) + set_task(1.0, "timeRemain", TASK_TIMEREMAIN_LARGE, "", 0, "b") + } + + return i + } + } + else if (g_TimeSet[i][0] == _time) + { + return i + } + } + + return -1 +} + +public setDisplaying() +{ + new arg[32], flags[32], num[32] + new argc = read_argc() - 1 + new i = 0 + + while (i < argc && i < sizeof(g_TimeSet)) + { + read_argv(i + 1, arg, charsmax(arg)) + parse(arg, flags, charsmax(flags), num, charsmax(num)) + + g_TimeSet[i][0] = str_to_num(num) + g_TimeSet[i][1] = read_flags(flags) + + i++ + } + + if( i < sizeof(g_TimeSet) ) + g_TimeSet[i][0] = 0 // has to be zeroed in case command is sent twice + + return PLUGIN_HANDLED +} + +public timeRemain(param[]) +{ + new gmtm = get_timeleft() + new tmlf = g_Switch ? --g_CountDown : gmtm + new stimel[12] + + formatex(stimel, charsmax(stimel), "%02d:%02d", gmtm / 60, gmtm % 60) + set_pcvar_string(g_amx_timeleft, stimel) + + if (g_Switch && gmtm > g_Switch) + { + remove_task(TASK_TIMEREMAIN_LARGE) + g_Switch = 0 + set_task(0.8, "timeRemain", TASK_TIMEREMAIN_SHORT, "", 0, "b") + + return + } + + if (tmlf > 0 && g_LastTime != tmlf) + { + g_LastTime = tmlf + new tm_set = findDispFormat(tmlf) + + if (tm_set != -1) + { + new flags = g_TimeSet[tm_set][1] + new arg[128] + + if (flags & TD_BOTTOM_WHITE_TEXT) + { + new players[MAX_PLAYERS], pnum, plr + + get_players(players, pnum, "c") + + if (flags & TD_SHOW_SPEAK_VALUES_BELOW) // yes this is correct flag, just because message should be shorter if it is shown every seconds + set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 1.1, 0.1, 0.5, -1) + else + set_hudmessage(255, 255, 255, -1.0, 0.85, 0, 0.0, 3.0, 0.0, 0.5, -1) + + for (new i = 0; i < pnum; i++) + { + plr = players[i] + setTimeText(arg, charsmax(arg), tmlf, plr) + show_hudmessage(plr, "%s", arg) + } + } + + if (flags & TD_USE_VOICE) + { + setTimeVoice(arg, charsmax(arg), flags, tmlf) + client_cmd(0, "%s", arg) + } + } + } +} From 464d6e9ec484de537e42730eb2b8c119707462a0 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 12 Mar 2015 10:41:34 -0700 Subject: [PATCH 66/66] Simplifying requires --- bin/linguist | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/linguist b/bin/linguist index 6ac8f0a7..d1d9c306 100755 --- a/bin/linguist +++ b/bin/linguist @@ -2,10 +2,8 @@ # linguist — detect language type for a file, or, given a directory, determine language breakdown # usage: linguist [<--breakdown>] - -require 'linguist/file_blob' -require 'linguist/language' -require 'linguist/repository' +# +require 'linguist' require 'rugged' path = ARGV[0] || Dir.pwd