diff --git a/.gitignore b/.gitignore
index 08e2205d..90d94706 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-Gemfile.lock
+/Gemfile.lock
.bundle/
benchmark/
lib/linguist/samples.json
diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb
index 9c1d9948..13f0173f 100644
--- a/lib/linguist/heuristics.rb
+++ b/lib/linguist/heuristics.rb
@@ -36,6 +36,9 @@ module Linguist
if languages.all? { |l| ["AsciiDoc", "AGS Script"].include?(l) }
result = disambiguate_asc(data)
end
+ if languages.all? { |l| ["FORTRAN", "Forth"].include?(l) }
+ result = disambiguate_f(data)
+ end
return result
end
end
@@ -138,6 +141,16 @@ module Linguist
matches
end
+ def self.disambiguate_f(data)
+ matches = []
+ if /^: /.match(data)
+ matches << Language["Forth"]
+ elsif /^([c*][^a-z]| subroutine\s)/i.match(data)
+ matches << Language["FORTRAN"]
+ end
+ matches
+ end
+
def self.active?
!!ACTIVE
end
diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb
index 083e8a3c..f4c7a62e 100644
--- a/lib/linguist/language.rb
+++ b/lib/linguist/language.rb
@@ -431,11 +431,6 @@ module Linguist
# Returns the extensions Array
attr_reader :filenames
- # Public: Return all possible extensions for language
- def all_extensions
- (extensions + [primary_extension]).uniq
- end
-
# Deprecated: Get primary extension
#
# Defaults to the first extension but can be overridden
@@ -593,9 +588,9 @@ module Linguist
:ace_mode => options['ace_mode'],
:wrap => options['wrap'],
:group_name => options['group'],
- :searchable => options.key?('searchable') ? options['searchable'] : true,
+ :searchable => options.fetch('searchable', true),
:search_term => options['search_term'],
- :extensions => [options['extensions'].first] + options['extensions'][1..-1].sort,
+ :extensions => Array(options['extensions']),
:interpreters => options['interpreters'].sort,
:filenames => options['filenames'],
:popular => popular.include?(name)
diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml
index 022918e6..4d36d8d0 100644
--- a/lib/linguist/languages.yml
+++ b/lib/linguist/languages.yml
@@ -33,15 +33,6 @@ AGS Script:
- .ash
tm_scope: source.c++
-Ant Build System:
- type: data
- tm_scope: text.xml.ant
- extensions:
- - .ant.xml
- filenames:
- - build.xml
- - ant.xml
-
ANTLR:
type: programming
color: "#9DC3FF"
@@ -117,6 +108,13 @@ Alloy:
extensions:
- .als
+Ant Build System:
+ type: data
+ tm_scope: text.xml.ant
+ filenames:
+ - ant.xml
+ - build.xml
+
ApacheConf:
type: markup
aliases:
@@ -649,13 +647,6 @@ E:
extensions:
- .E
-Ecere Projects:
- type: data
- group: JavaScript
- extensions:
- - .epj
- tm_scope: source.json
-
ECL:
type: programming
color: "#8a1267"
@@ -671,6 +662,13 @@ Eagle:
- .brd
tm_scope: text.xml
+Ecere Projects:
+ type: data
+ group: JavaScript
+ extensions:
+ - .epj
+ tm_scope: source.json
+
Eiffel:
type: programming
color: "#946d57"
@@ -767,8 +765,8 @@ Factor:
extensions:
- .factor
filenames:
- - .factor-rc
- .factor-boot-rc
+ - .factor-rc
Fancy:
type: programming
@@ -792,6 +790,9 @@ Forth:
extensions:
- .fth
- .4th
+ - .F
+ - .f
+ - .for
- .forth
- .frt
@@ -809,13 +810,6 @@ G-code:
- .gco
- .gcode
-Game Maker Language:
- type: programming
- color: "#8ad353"
- extensions:
- - .gml
- tm_scope: source.js
-
GAMS:
type: programming
extensions:
@@ -860,6 +854,13 @@ GLSL:
- .vrx
- .vshader
+Game Maker Language:
+ type: programming
+ color: "#8ad353"
+ extensions:
+ - .gml
+ tm_scope: source.js
+
Genshi:
extensions:
- .kid
@@ -1119,9 +1120,14 @@ INI:
aliases:
- dosini
-Inno Setup:
+IRC log:
+ search_term: irc
+ aliases:
+ - irc
+ - irc logs
extensions:
- - .iss
+ - .irclog
+ - .weechatlog
Idris:
type: programming
@@ -1144,15 +1150,6 @@ Inno Setup:
extensions:
- .iss
-IRC log:
- search_term: irc
- aliases:
- - irc
- - irc logs
- extensions:
- - .irclog
- - .weechatlog
-
Io:
type: programming
color: "#a9188d"
@@ -1471,9 +1468,9 @@ Makefile:
- .mak
- .mk
filenames:
- - makefile
- - Makefile
- GNUmakefile
+ - Makefile
+ - makefile
interpreters:
- make
@@ -1526,8 +1523,6 @@ Matlab:
Maven POM:
type: data
tm_scope: text.xml.pom
- extensions:
- - .pom.xml
filenames:
- pom.xml
@@ -1829,6 +1824,14 @@ Parrot:
extensions:
- .parrot # Dummy extension
+Parrot Assembly:
+ group: Parrot
+ type: programming
+ aliases:
+ - pasm
+ extensions:
+ - .pasm
+
Parrot Internal Representation:
group: Parrot
tm_scope: source.parrot.pir
@@ -1838,14 +1841,6 @@ Parrot Internal Representation:
extensions:
- .pir
-Parrot Assembly:
- group: Parrot
- type: programming
- aliases:
- - pasm
- extensions:
- - .pasm
-
Pascal:
type: programming
color: "#b0ce4e"
@@ -2002,10 +1997,10 @@ Python:
- .wsgi
- .xpy
filenames:
- - wscript
- - SConstruct
- - SConscript
- BUILD
+ - SConscript
+ - SConstruct
+ - wscript
interpreters:
- python
@@ -2585,8 +2580,8 @@ VimL:
filenames:
- .vimrc
- _vimrc
- - vimrc
- gvimrc
+ - vimrc
Visual Basic:
type: programming
@@ -2688,12 +2683,12 @@ XML:
filenames:
- .classpath
- .project
+ - Web.Debug.config
+ - Web.Release.config
+ - Web.config
- build.xml.dist
- packages.config
- phpunit.xml.dist
- - Web.config
- - Web.Debug.config
- - Web.Release.config
XProc:
type: programming
diff --git a/samples/Ant Build System/filenames/ant.xml b/samples/Ant Build System/filenames/ant.xml
new file mode 100644
index 00000000..54e96ddc
--- /dev/null
+++ b/samples/Ant Build System/filenames/ant.xml
@@ -0,0 +1,110 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/Ant Build System/filenames/build.xml b/samples/Ant Build System/filenames/build.xml
new file mode 120000
index 00000000..6c7d5cd4
--- /dev/null
+++ b/samples/Ant Build System/filenames/build.xml
@@ -0,0 +1 @@
+ant.xml
\ No newline at end of file
diff --git a/samples/FORTRAN/sample1.F b/samples/FORTRAN/sample1.F
new file mode 100644
index 00000000..39ba97cb
--- /dev/null
+++ b/samples/FORTRAN/sample1.F
@@ -0,0 +1,25 @@
+c comment
+* comment
+
+ program main
+
+ end
+
+ subroutine foo( i, x, b )
+ INTEGER i
+ REAL x
+ LOGICAL b
+
+ if( i.ne.0 ) then
+ call bar( -i )
+ end if
+
+ return
+ end
+
+ double complex function baz()
+
+ baz = (0.0d0,0.0d0)
+
+ return
+ end
diff --git a/samples/FORTRAN/sample1.f b/samples/FORTRAN/sample1.f
new file mode 100644
index 00000000..39ba97cb
--- /dev/null
+++ b/samples/FORTRAN/sample1.f
@@ -0,0 +1,25 @@
+c comment
+* comment
+
+ program main
+
+ end
+
+ subroutine foo( i, x, b )
+ INTEGER i
+ REAL x
+ LOGICAL b
+
+ if( i.ne.0 ) then
+ call bar( -i )
+ end if
+
+ return
+ end
+
+ double complex function baz()
+
+ baz = (0.0d0,0.0d0)
+
+ return
+ end
diff --git a/samples/FORTRAN/sample1.for b/samples/FORTRAN/sample1.for
new file mode 100644
index 00000000..39ba97cb
--- /dev/null
+++ b/samples/FORTRAN/sample1.for
@@ -0,0 +1,25 @@
+c comment
+* comment
+
+ program main
+
+ end
+
+ subroutine foo( i, x, b )
+ INTEGER i
+ REAL x
+ LOGICAL b
+
+ if( i.ne.0 ) then
+ call bar( -i )
+ end if
+
+ return
+ end
+
+ double complex function baz()
+
+ baz = (0.0d0,0.0d0)
+
+ return
+ end
diff --git a/samples/FORTRAN/sample2.f b/samples/FORTRAN/sample2.f
new file mode 100644
index 00000000..19538ac7
--- /dev/null
+++ b/samples/FORTRAN/sample2.f
@@ -0,0 +1,25 @@
+ PROGRAM MAIN
+
+ END
+
+C comment
+* comment
+
+ SUBROUTINE foo( i, x, b )
+ INTEGER i
+ REAL x
+ LOGICAL b
+
+ IF( i.NE.0 ) THEN
+ CALL bar( -i )
+ END IF
+
+ RETURN
+ END
+
+ DOUBLE COMPLEX FUNCTION baz()
+
+ baz = (0.0d0,0.0d0)
+
+ RETURN
+ END
diff --git a/samples/Forth/core.F b/samples/Forth/core.F
new file mode 100644
index 00000000..4a13e217
--- /dev/null
+++ b/samples/Forth/core.F
@@ -0,0 +1,252 @@
+: immediate lastxt @ dup c@ negate swap c! ;
+
+: \ source nip >in ! ; immediate \ Copyright 2004, 2012 Lars Brinkhoff
+
+: char \ ( "word" -- char )
+ bl-word here 1+ c@ ;
+
+: ahead here 0 , ;
+
+: resolve here swap ! ;
+
+: ' bl-word here find 0branch [ ahead ] exit [ resolve ] 0 ;
+
+: postpone-nonimmediate [ ' literal , ' compile, ] literal , ;
+
+: create dovariable_code header, reveal ;
+
+create postponers
+ ' postpone-nonimmediate ,
+ ' abort ,
+ ' , ,
+
+: word \ ( char "string" -- caddr )
+ drop bl-word here ;
+
+: postpone \ ( C: "word" -- )
+ bl word find 1+ cells postponers + @ execute ; immediate
+
+: unresolved \ ( C: "word" -- orig )
+ postpone postpone postpone ahead ; immediate
+
+: chars \ ( n1 -- n2 )
+ ;
+
+: else \ ( -- ) ( C: orig1 -- orig2 )
+ unresolved branch swap resolve ; immediate
+
+: if \ ( flag -- ) ( C: -- orig )
+ unresolved 0branch ; immediate
+
+: then \ ( -- ) ( C: orig -- )
+ resolve ; immediate
+
+: [char] \ ( "word" -- )
+ char postpone literal ; immediate
+
+: (does>) lastxt @ dodoes_code over >code ! r> swap >does ! ;
+
+: does> postpone (does>) ; immediate
+
+: begin \ ( -- ) ( C: -- dest )
+ here ; immediate
+
+: while \ ( x -- ) ( C: dest -- orig dest )
+ unresolved 0branch swap ; immediate
+
+: repeat \ ( -- ) ( C: orig dest -- )
+ postpone branch , resolve ; immediate
+
+: until \ ( x -- ) ( C: dest -- )
+ postpone 0branch , ; immediate
+
+: recurse lastxt @ compile, ; immediate
+
+: pad \ ( -- addr )
+ here 1024 + ;
+
+: parse \ ( char "string" -- addr n )
+ pad >r begin
+ source? if else 0 0 then
+ while
+ r@ c! r> 1+ >r
+ repeat 2drop pad r> over - ;
+
+: ( \ ( "string" -- )
+ [ char ) ] literal parse 2drop ; immediate
+ \ TODO: If necessary, refill and keep parsing.
+
+: string, ( addr n -- )
+ here over allot align swap cmove ;
+
+: (s") ( -- addr n ) ( R: ret1 -- ret2 )
+ r> dup @ swap cell+ 2dup + aligned >r swap ;
+
+create squote 128 allot
+
+: s" ( "string" -- addr n )
+ state @ if
+ postpone (s") [char] " parse dup , string,
+ else
+ [char] " parse >r squote r@ cmove squote r>
+ then ; immediate
+
+: (abort") ( ... addr n -- ) ( R: ... -- )
+ cr type cr abort ;
+
+: abort" ( ... x "string" -- ) ( R: ... -- )
+ postpone if postpone s" postpone (abort") postpone then ; immediate
+
+\ ----------------------------------------------------------------------
+
+( Core words. )
+
+\ TODO: #
+\ TODO: #>
+\ TODO: #s
+
+: and ( x y -- x&y ) nand invert ;
+
+: * 1 2>r 0 swap begin r@ while
+ r> r> swap 2dup dup + 2>r and if swap over + swap then dup +
+ repeat r> r> 2drop drop ;
+
+\ TODO: */mod
+
+: +loop ( -- ) ( C: nest-sys -- )
+ postpone (+loop) postpone 0branch , postpone unloop ; immediate
+
+: space bl emit ;
+
+: ?.- dup 0 < if [char] - emit negate then ;
+
+: digit [char] 0 + emit ;
+
+: (.) base @ /mod ?dup if recurse then digit ;
+
+: ." ( "string" -- ) postpone s" postpone type ; immediate
+
+: . ( x -- ) ?.- (.) space ;
+
+: postpone-number ( caddr -- )
+ 0 0 rot count >number dup 0= if
+ 2drop nip
+ postpone (literal) postpone (literal) postpone ,
+ postpone literal postpone ,
+ else
+ ." Undefined: " type cr abort
+ then ;
+
+' postpone-number postponers cell+ !
+
+: / ( x y -- x/y ) /mod nip ;
+
+: 0< ( n -- flag ) 0 < ;
+
+: 1- ( n -- n-1 ) -1 + ;
+
+: 2! ( x1 x2 addr -- ) swap over ! cell+ ! ;
+
+: 2* ( n -- 2n ) dup + ;
+
+\ Kernel: 2/
+
+: 2@ ( addr -- x1 x2 ) dup cell+ @ swap @ ;
+
+\ Kernel: 2drop
+\ Kernel: 2dup
+
+\ TODO: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
+\ 3 pick 3 pick ;
+
+\ TODO: 2swap
+
+\ TODO: <#
+
+: abs ( n -- |n| )
+ dup 0< if negate then ;
+
+\ TODO: accept
+
+: c, ( n -- )
+ here c! 1 chars allot ;
+
+: char+ ( n1 -- n2 )
+ 1+ ;
+
+: constant create , does> @ ;
+
+: decimal ( -- )
+ 10 base ! ;
+
+: depth ( -- n )
+ data_stack 100 cells + 'SP @ - /cell / 2 - ;
+
+: do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
+ postpone 2>r here ; immediate
+
+\ TODO: environment?
+\ TODO: evaluate
+\ TODO: fill
+\ TODO: fm/mod )
+\ TODO: hold
+
+: j ( -- x1 ) ( R: x1 x2 x3 -- x1 x2 x3 )
+ 'RP @ 3 cells + @ ;
+
+\ TODO: leave
+
+: loop ( -- ) ( C: nest-sys -- )
+ postpone 1 postpone (+loop)
+ postpone 0branch ,
+ postpone unloop ; immediate
+
+: lshift begin ?dup while 1- swap dup + swap repeat ;
+
+: rshift 1 begin over while dup + swap 1- swap repeat nip
+ 2>r 0 1 begin r@ while
+ r> r> 2dup swap dup + 2>r and if swap over + swap then dup +
+ repeat r> r> 2drop drop ;
+
+: max ( x y -- max[x,y] )
+ 2dup > if drop else nip then ;
+
+\ Kernel: min
+\ TODO: mod
+\ TODO: move
+
+: (quit) ( R: ... -- )
+ return_stack 100 cells + 'RP !
+ 0 'source-id ! tib ''source ! #tib ''#source !
+ postpone [
+ begin
+ refill
+ while
+ interpret state @ 0= if ." ok" cr then
+ repeat
+ bye ;
+
+' (quit) ' quit >body cell+ !
+
+\ TODO: s>d
+\ TODO: sign
+\ TODO: sm/rem
+
+: spaces ( n -- )
+ 0 do space loop ;
+
+\ TODO: u.
+
+: signbit ( -- n ) -1 1 rshift invert ;
+
+: xor ( x y -- x^y ) 2dup nand >r r@ nand swap r> nand nand ;
+
+: u< ( x y -- flag ) signbit xor swap signbit xor > ;
+
+\ TODO: um/mod
+
+: variable ( "word" -- )
+ create /cell allot ;
+
+: ['] \ ( C: "word" -- )
+ ' postpone literal ; immediate
diff --git a/samples/Forth/core.f b/samples/Forth/core.f
new file mode 100644
index 00000000..4a13e217
--- /dev/null
+++ b/samples/Forth/core.f
@@ -0,0 +1,252 @@
+: immediate lastxt @ dup c@ negate swap c! ;
+
+: \ source nip >in ! ; immediate \ Copyright 2004, 2012 Lars Brinkhoff
+
+: char \ ( "word" -- char )
+ bl-word here 1+ c@ ;
+
+: ahead here 0 , ;
+
+: resolve here swap ! ;
+
+: ' bl-word here find 0branch [ ahead ] exit [ resolve ] 0 ;
+
+: postpone-nonimmediate [ ' literal , ' compile, ] literal , ;
+
+: create dovariable_code header, reveal ;
+
+create postponers
+ ' postpone-nonimmediate ,
+ ' abort ,
+ ' , ,
+
+: word \ ( char "string" -- caddr )
+ drop bl-word here ;
+
+: postpone \ ( C: "word" -- )
+ bl word find 1+ cells postponers + @ execute ; immediate
+
+: unresolved \ ( C: "word" -- orig )
+ postpone postpone postpone ahead ; immediate
+
+: chars \ ( n1 -- n2 )
+ ;
+
+: else \ ( -- ) ( C: orig1 -- orig2 )
+ unresolved branch swap resolve ; immediate
+
+: if \ ( flag -- ) ( C: -- orig )
+ unresolved 0branch ; immediate
+
+: then \ ( -- ) ( C: orig -- )
+ resolve ; immediate
+
+: [char] \ ( "word" -- )
+ char postpone literal ; immediate
+
+: (does>) lastxt @ dodoes_code over >code ! r> swap >does ! ;
+
+: does> postpone (does>) ; immediate
+
+: begin \ ( -- ) ( C: -- dest )
+ here ; immediate
+
+: while \ ( x -- ) ( C: dest -- orig dest )
+ unresolved 0branch swap ; immediate
+
+: repeat \ ( -- ) ( C: orig dest -- )
+ postpone branch , resolve ; immediate
+
+: until \ ( x -- ) ( C: dest -- )
+ postpone 0branch , ; immediate
+
+: recurse lastxt @ compile, ; immediate
+
+: pad \ ( -- addr )
+ here 1024 + ;
+
+: parse \ ( char "string" -- addr n )
+ pad >r begin
+ source? if else 0 0 then
+ while
+ r@ c! r> 1+ >r
+ repeat 2drop pad r> over - ;
+
+: ( \ ( "string" -- )
+ [ char ) ] literal parse 2drop ; immediate
+ \ TODO: If necessary, refill and keep parsing.
+
+: string, ( addr n -- )
+ here over allot align swap cmove ;
+
+: (s") ( -- addr n ) ( R: ret1 -- ret2 )
+ r> dup @ swap cell+ 2dup + aligned >r swap ;
+
+create squote 128 allot
+
+: s" ( "string" -- addr n )
+ state @ if
+ postpone (s") [char] " parse dup , string,
+ else
+ [char] " parse >r squote r@ cmove squote r>
+ then ; immediate
+
+: (abort") ( ... addr n -- ) ( R: ... -- )
+ cr type cr abort ;
+
+: abort" ( ... x "string" -- ) ( R: ... -- )
+ postpone if postpone s" postpone (abort") postpone then ; immediate
+
+\ ----------------------------------------------------------------------
+
+( Core words. )
+
+\ TODO: #
+\ TODO: #>
+\ TODO: #s
+
+: and ( x y -- x&y ) nand invert ;
+
+: * 1 2>r 0 swap begin r@ while
+ r> r> swap 2dup dup + 2>r and if swap over + swap then dup +
+ repeat r> r> 2drop drop ;
+
+\ TODO: */mod
+
+: +loop ( -- ) ( C: nest-sys -- )
+ postpone (+loop) postpone 0branch , postpone unloop ; immediate
+
+: space bl emit ;
+
+: ?.- dup 0 < if [char] - emit negate then ;
+
+: digit [char] 0 + emit ;
+
+: (.) base @ /mod ?dup if recurse then digit ;
+
+: ." ( "string" -- ) postpone s" postpone type ; immediate
+
+: . ( x -- ) ?.- (.) space ;
+
+: postpone-number ( caddr -- )
+ 0 0 rot count >number dup 0= if
+ 2drop nip
+ postpone (literal) postpone (literal) postpone ,
+ postpone literal postpone ,
+ else
+ ." Undefined: " type cr abort
+ then ;
+
+' postpone-number postponers cell+ !
+
+: / ( x y -- x/y ) /mod nip ;
+
+: 0< ( n -- flag ) 0 < ;
+
+: 1- ( n -- n-1 ) -1 + ;
+
+: 2! ( x1 x2 addr -- ) swap over ! cell+ ! ;
+
+: 2* ( n -- 2n ) dup + ;
+
+\ Kernel: 2/
+
+: 2@ ( addr -- x1 x2 ) dup cell+ @ swap @ ;
+
+\ Kernel: 2drop
+\ Kernel: 2dup
+
+\ TODO: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
+\ 3 pick 3 pick ;
+
+\ TODO: 2swap
+
+\ TODO: <#
+
+: abs ( n -- |n| )
+ dup 0< if negate then ;
+
+\ TODO: accept
+
+: c, ( n -- )
+ here c! 1 chars allot ;
+
+: char+ ( n1 -- n2 )
+ 1+ ;
+
+: constant create , does> @ ;
+
+: decimal ( -- )
+ 10 base ! ;
+
+: depth ( -- n )
+ data_stack 100 cells + 'SP @ - /cell / 2 - ;
+
+: do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
+ postpone 2>r here ; immediate
+
+\ TODO: environment?
+\ TODO: evaluate
+\ TODO: fill
+\ TODO: fm/mod )
+\ TODO: hold
+
+: j ( -- x1 ) ( R: x1 x2 x3 -- x1 x2 x3 )
+ 'RP @ 3 cells + @ ;
+
+\ TODO: leave
+
+: loop ( -- ) ( C: nest-sys -- )
+ postpone 1 postpone (+loop)
+ postpone 0branch ,
+ postpone unloop ; immediate
+
+: lshift begin ?dup while 1- swap dup + swap repeat ;
+
+: rshift 1 begin over while dup + swap 1- swap repeat nip
+ 2>r 0 1 begin r@ while
+ r> r> 2dup swap dup + 2>r and if swap over + swap then dup +
+ repeat r> r> 2drop drop ;
+
+: max ( x y -- max[x,y] )
+ 2dup > if drop else nip then ;
+
+\ Kernel: min
+\ TODO: mod
+\ TODO: move
+
+: (quit) ( R: ... -- )
+ return_stack 100 cells + 'RP !
+ 0 'source-id ! tib ''source ! #tib ''#source !
+ postpone [
+ begin
+ refill
+ while
+ interpret state @ 0= if ." ok" cr then
+ repeat
+ bye ;
+
+' (quit) ' quit >body cell+ !
+
+\ TODO: s>d
+\ TODO: sign
+\ TODO: sm/rem
+
+: spaces ( n -- )
+ 0 do space loop ;
+
+\ TODO: u.
+
+: signbit ( -- n ) -1 1 rshift invert ;
+
+: xor ( x y -- x^y ) 2dup nand >r r@ nand swap r> nand nand ;
+
+: u< ( x y -- flag ) signbit xor swap signbit xor > ;
+
+\ TODO: um/mod
+
+: variable ( "word" -- )
+ create /cell allot ;
+
+: ['] \ ( C: "word" -- )
+ ' postpone literal ; immediate
diff --git a/samples/Forth/core.for b/samples/Forth/core.for
new file mode 100644
index 00000000..4a13e217
--- /dev/null
+++ b/samples/Forth/core.for
@@ -0,0 +1,252 @@
+: immediate lastxt @ dup c@ negate swap c! ;
+
+: \ source nip >in ! ; immediate \ Copyright 2004, 2012 Lars Brinkhoff
+
+: char \ ( "word" -- char )
+ bl-word here 1+ c@ ;
+
+: ahead here 0 , ;
+
+: resolve here swap ! ;
+
+: ' bl-word here find 0branch [ ahead ] exit [ resolve ] 0 ;
+
+: postpone-nonimmediate [ ' literal , ' compile, ] literal , ;
+
+: create dovariable_code header, reveal ;
+
+create postponers
+ ' postpone-nonimmediate ,
+ ' abort ,
+ ' , ,
+
+: word \ ( char "string" -- caddr )
+ drop bl-word here ;
+
+: postpone \ ( C: "word" -- )
+ bl word find 1+ cells postponers + @ execute ; immediate
+
+: unresolved \ ( C: "word" -- orig )
+ postpone postpone postpone ahead ; immediate
+
+: chars \ ( n1 -- n2 )
+ ;
+
+: else \ ( -- ) ( C: orig1 -- orig2 )
+ unresolved branch swap resolve ; immediate
+
+: if \ ( flag -- ) ( C: -- orig )
+ unresolved 0branch ; immediate
+
+: then \ ( -- ) ( C: orig -- )
+ resolve ; immediate
+
+: [char] \ ( "word" -- )
+ char postpone literal ; immediate
+
+: (does>) lastxt @ dodoes_code over >code ! r> swap >does ! ;
+
+: does> postpone (does>) ; immediate
+
+: begin \ ( -- ) ( C: -- dest )
+ here ; immediate
+
+: while \ ( x -- ) ( C: dest -- orig dest )
+ unresolved 0branch swap ; immediate
+
+: repeat \ ( -- ) ( C: orig dest -- )
+ postpone branch , resolve ; immediate
+
+: until \ ( x -- ) ( C: dest -- )
+ postpone 0branch , ; immediate
+
+: recurse lastxt @ compile, ; immediate
+
+: pad \ ( -- addr )
+ here 1024 + ;
+
+: parse \ ( char "string" -- addr n )
+ pad >r begin
+ source? if else 0 0 then
+ while
+ r@ c! r> 1+ >r
+ repeat 2drop pad r> over - ;
+
+: ( \ ( "string" -- )
+ [ char ) ] literal parse 2drop ; immediate
+ \ TODO: If necessary, refill and keep parsing.
+
+: string, ( addr n -- )
+ here over allot align swap cmove ;
+
+: (s") ( -- addr n ) ( R: ret1 -- ret2 )
+ r> dup @ swap cell+ 2dup + aligned >r swap ;
+
+create squote 128 allot
+
+: s" ( "string" -- addr n )
+ state @ if
+ postpone (s") [char] " parse dup , string,
+ else
+ [char] " parse >r squote r@ cmove squote r>
+ then ; immediate
+
+: (abort") ( ... addr n -- ) ( R: ... -- )
+ cr type cr abort ;
+
+: abort" ( ... x "string" -- ) ( R: ... -- )
+ postpone if postpone s" postpone (abort") postpone then ; immediate
+
+\ ----------------------------------------------------------------------
+
+( Core words. )
+
+\ TODO: #
+\ TODO: #>
+\ TODO: #s
+
+: and ( x y -- x&y ) nand invert ;
+
+: * 1 2>r 0 swap begin r@ while
+ r> r> swap 2dup dup + 2>r and if swap over + swap then dup +
+ repeat r> r> 2drop drop ;
+
+\ TODO: */mod
+
+: +loop ( -- ) ( C: nest-sys -- )
+ postpone (+loop) postpone 0branch , postpone unloop ; immediate
+
+: space bl emit ;
+
+: ?.- dup 0 < if [char] - emit negate then ;
+
+: digit [char] 0 + emit ;
+
+: (.) base @ /mod ?dup if recurse then digit ;
+
+: ." ( "string" -- ) postpone s" postpone type ; immediate
+
+: . ( x -- ) ?.- (.) space ;
+
+: postpone-number ( caddr -- )
+ 0 0 rot count >number dup 0= if
+ 2drop nip
+ postpone (literal) postpone (literal) postpone ,
+ postpone literal postpone ,
+ else
+ ." Undefined: " type cr abort
+ then ;
+
+' postpone-number postponers cell+ !
+
+: / ( x y -- x/y ) /mod nip ;
+
+: 0< ( n -- flag ) 0 < ;
+
+: 1- ( n -- n-1 ) -1 + ;
+
+: 2! ( x1 x2 addr -- ) swap over ! cell+ ! ;
+
+: 2* ( n -- 2n ) dup + ;
+
+\ Kernel: 2/
+
+: 2@ ( addr -- x1 x2 ) dup cell+ @ swap @ ;
+
+\ Kernel: 2drop
+\ Kernel: 2dup
+
+\ TODO: 2over ( x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2 )
+\ 3 pick 3 pick ;
+
+\ TODO: 2swap
+
+\ TODO: <#
+
+: abs ( n -- |n| )
+ dup 0< if negate then ;
+
+\ TODO: accept
+
+: c, ( n -- )
+ here c! 1 chars allot ;
+
+: char+ ( n1 -- n2 )
+ 1+ ;
+
+: constant create , does> @ ;
+
+: decimal ( -- )
+ 10 base ! ;
+
+: depth ( -- n )
+ data_stack 100 cells + 'SP @ - /cell / 2 - ;
+
+: do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
+ postpone 2>r here ; immediate
+
+\ TODO: environment?
+\ TODO: evaluate
+\ TODO: fill
+\ TODO: fm/mod )
+\ TODO: hold
+
+: j ( -- x1 ) ( R: x1 x2 x3 -- x1 x2 x3 )
+ 'RP @ 3 cells + @ ;
+
+\ TODO: leave
+
+: loop ( -- ) ( C: nest-sys -- )
+ postpone 1 postpone (+loop)
+ postpone 0branch ,
+ postpone unloop ; immediate
+
+: lshift begin ?dup while 1- swap dup + swap repeat ;
+
+: rshift 1 begin over while dup + swap 1- swap repeat nip
+ 2>r 0 1 begin r@ while
+ r> r> 2dup swap dup + 2>r and if swap over + swap then dup +
+ repeat r> r> 2drop drop ;
+
+: max ( x y -- max[x,y] )
+ 2dup > if drop else nip then ;
+
+\ Kernel: min
+\ TODO: mod
+\ TODO: move
+
+: (quit) ( R: ... -- )
+ return_stack 100 cells + 'RP !
+ 0 'source-id ! tib ''source ! #tib ''#source !
+ postpone [
+ begin
+ refill
+ while
+ interpret state @ 0= if ." ok" cr then
+ repeat
+ bye ;
+
+' (quit) ' quit >body cell+ !
+
+\ TODO: s>d
+\ TODO: sign
+\ TODO: sm/rem
+
+: spaces ( n -- )
+ 0 do space loop ;
+
+\ TODO: u.
+
+: signbit ( -- n ) -1 1 rshift invert ;
+
+: xor ( x y -- x^y ) 2dup nand >r r@ nand swap r> nand nand ;
+
+: u< ( x y -- flag ) signbit xor swap signbit xor > ;
+
+\ TODO: um/mod
+
+: variable ( "word" -- )
+ create /cell allot ;
+
+: ['] \ ( C: "word" -- )
+ ' postpone literal ; immediate
diff --git a/samples/Maven POM/filenames/pom.xml b/samples/Maven POM/filenames/pom.xml
new file mode 100644
index 00000000..6e329fd9
--- /dev/null
+++ b/samples/Maven POM/filenames/pom.xml
@@ -0,0 +1,207 @@
+
+
+ 4.0.0
+ renpengben
+ spring4mvc-jpa
+ war
+ 0.0.1-SNAPSHOT
+ spring4mvc-jpa Maven Webapp
+
+ https://renpengben.github.io
+
+ spring4mvc-jpa
+
+
+ UTF-8
+ 1.7
+ 4.11
+ 1.7.7
+ 1.2.17
+
+ 4.0.5.RELEASE
+ 1.6.0.RELEASE
+ 2.1_3
+
+ 5.1.31
+ 4.3.5.Final
+ 5.1.1.Final
+ 1.0.6
+
+
+
+
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+ org.slf4j
+ slf4j-log4j12
+ ${slf4j.version}
+
+
+ log4j
+ log4j
+ ${log4j.version}
+
+
+
+
+
+ org.springframework
+ spring-core
+ ${spring.version}
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+
+ org.springframework
+ spring-beans
+ ${spring.version}
+
+
+ org.springframework
+ spring-context
+ ${spring.version}
+
+
+
+ org.springframework
+ spring-aop
+ ${spring.version}
+
+
+
+ org.springframework
+ spring-expression
+ ${spring.version}
+
+
+ org.springframework
+ spring-tx
+ ${spring.version}
+
+
+
+
+ org.springframework
+ spring-aspects
+ ${spring.version}
+
+
+ org.springframework
+ spring-context-support
+ ${spring.version}
+
+
+ org.springframework
+ spring-jdbc
+ ${spring.version}
+
+
+ org.springframework
+ spring-orm
+ ${spring.version}
+
+
+
+ org.springframework
+ spring-web
+ ${spring.version}
+
+
+ org.springframework
+ spring-webmvc
+ ${spring.version}
+
+
+ org.springframework
+ spring-test
+ ${spring.version}
+ test
+
+
+
+ org.springframework.data
+ spring-data-jpa
+ ${spring.data.jpa.version}
+
+
+ junit-dep
+ junit
+
+
+
+
+ cglib
+ cglib-nodep
+ ${cglib.version}
+
+
+
+
+
+
+
+ org.hibernate
+ hibernate-core
+ ${hibernate.version}
+
+
+ org.hibernate
+ hibernate-entitymanager
+ ${hibernate.version}
+
+
+ org.hibernate
+ hibernate-validator
+ ${hibernate-validator.version}
+ compile
+
+
+
+
+
+ mysql
+ mysql-connector-java
+ ${mysql.version}
+ runtime
+
+
+ com.alibaba
+ druid
+ ${druid-version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+ 1.7
+ 1.7
+
+
+
+
+
diff --git a/samples/Ruby/filenames/Gemfile.lock b/samples/Ruby/filenames/Gemfile.lock
new file mode 100644
index 00000000..22208028
--- /dev/null
+++ b/samples/Ruby/filenames/Gemfile.lock
@@ -0,0 +1,42 @@
+PATH
+ remote: .
+ specs:
+ github-linguist (4.0.1)
+ charlock_holmes (~> 0.7.3)
+ escape_utils (~> 1.0.1)
+ mime-types (>= 1.19)
+ rugged (~> 0.22.0b1)
+ github-linguist-grammars (4.0.1)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ charlock_holmes (0.7.3)
+ coderay (1.1.0)
+ escape_utils (1.0.1)
+ metaclass (0.0.4)
+ method_source (0.8.2)
+ mime-types (2.4.3)
+ mocha (1.1.0)
+ metaclass (~> 0.0.1)
+ plist (3.1.0)
+ pry (0.10.1)
+ coderay (~> 1.1.0)
+ method_source (~> 0.8.1)
+ slop (~> 3.4)
+ rake (10.3.2)
+ rugged (0.22.0b1)
+ slop (3.6.0)
+ yajl-ruby (1.2.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ github-linguist!
+ github-linguist-grammars!
+ mocha
+ plist (~> 3.1)
+ pry
+ rake
+ yajl-ruby
diff --git a/test/test_heuristics.rb b/test/test_heuristics.rb
index 306cab28..40713ca7 100644
--- a/test/test_heuristics.rb
+++ b/test/test_heuristics.rb
@@ -100,6 +100,16 @@ class TestHeuristcs < Test::Unit::TestCase
end
end
+ def test_f_by_heuristics
+ languages = ["FORTRAN", "Forth"]
+ languages.each do |language|
+ all_fixtures(language).each do |fixture|
+ results = Heuristics.disambiguate_f(fixture("#{language}/#{File.basename(fixture)}"))
+ assert_equal Language[language], results.first
+ end
+ end
+ end
+
# Candidate languages = ["Hack", "PHP"]
def test_hack_by_heuristics
results = Heuristics.disambiguate_hack(fixture("Hack/funs.php"))
diff --git a/test/test_language.rb b/test/test_language.rb
index 2b96c8d2..f81ebbaf 100644
--- a/test/test_language.rb
+++ b/test/test_language.rb
@@ -348,12 +348,6 @@ class TestLanguage < Test::Unit::TestCase
assert_equal '.coffee', Language['CoffeeScript'].primary_extension
assert_equal '.t', Language['Turing'].primary_extension
assert_equal '.ts', Language['TypeScript'].primary_extension
-
- # This is a nasty requirement, but there's some code in GitHub that
- # expects this. Really want to drop this.
- Language.all.each do |language|
- assert language.primary_extension, "#{language} has no primary extension"
- end
end
def test_eql
diff --git a/test/test_pedantic.rb b/test/test_pedantic.rb
index 668803ad..be8ce063 100644
--- a/test/test_pedantic.rb
+++ b/test/test_pedantic.rb
@@ -1,57 +1,29 @@
require_relative "./helper"
class TestPedantic < Test::Unit::TestCase
- Lib = File.expand_path("../../lib/linguist", __FILE__)
-
- def file(name)
- File.read(File.join(Lib, name))
- end
+ filename = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
+ LANGUAGES = YAML.load(File.read(filename))
def test_language_names_are_sorted
- languages = []
- file("languages.yml").lines.each do |line|
- if line =~ /^(\w+):$/
- languages << $1
- end
- end
- assert_sorted languages
+ assert_sorted LANGUAGES.keys
end
def test_extensions_are_sorted
- extensions = nil
- file("languages.yml").lines.each do |line|
- if line =~ /^ extensions:$/
- extensions = []
- elsif extensions && line =~ /^ - \.([\w\-\.]+)( *#.*)?$/
- extensions << $1
- else
- assert_sorted extensions[1..-1] if extensions
- extensions = nil
- end
+ LANGUAGES.each do |name, language|
+ extensions = language['extensions']
+ assert_sorted extensions[1..-1] if extensions && extensions.size > 1
end
end
def test_filenames_are_sorted
- filenames = nil
- file("languages.yml").lines.each do |line|
- if line =~ /^ filenames:$/
- filenames = []
- elsif filenames && line =~ /^ - \.(\w+)$/
- filenames << $1
- else
- assert_sorted filenames if filenames
- filenames = nil
- end
+ LANGUAGES.each do |name, language|
+ assert_sorted language['filenames'] if language['filenames']
end
end
def assert_sorted(list)
- previous = nil
- list.each do |item|
- if previous && previous > item
- flunk "#{previous} should come after #{item}"
- end
- previous = item
+ list.each_cons(2) do |previous, item|
+ flunk "#{previous} should come after #{item}" if previous > item
end
end
end
diff --git a/test/test_samples.rb b/test/test_samples.rb
index f335ed36..114ed315 100644
--- a/test/test_samples.rb
+++ b/test/test_samples.rb
@@ -52,20 +52,28 @@ class TestSamples < Test::Unit::TestCase
end
# If a language extension isn't globally unique then make sure there are samples
- def test_presence
- Linguist::Language.all.each do |language|
- language.all_extensions.each do |extension|
- language_matches = Language.find_by_filename("foo#{extension}")
+ Linguist::Language.all.each do |language|
+ define_method "test_#{language.name}_has_samples" do
+ language.extensions.each do |extension|
+ language_matches = Language.find_by_extension(extension)
- # If there is more than one language match for a given extension
- # then check that there are examples for that language with the extension
+ # Check for samples if more than one language matches the given extension.
if language_matches.length > 1
- language_matches.each do |language|
- assert File.directory?("samples/#{language.name}"), "#{language.name} is missing a samples directory"
- assert Dir.glob("samples/#{language.name}/*#{extension}").any?, "#{language.name} is missing samples for extension #{extension}"
+ 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"
end
end
end
+
+ language.filenames.each do |filename|
+ # Check for samples if more than one language matches the given filename
+ if Language.find_by_filename(filename).size > 1
+ sample = "samples/#{language.name}/filenames/#{filename}"
+ assert File.exists?(sample),
+ "Missing sample in #{sample.inspect}. See https://github.com/github/linguist/blob/master/CONTRIBUTING.md"
+ end
+ end
end
end
end
diff --git a/vendor/cache/mime-types-1.25.1.gem b/vendor/cache/mime-types-1.25.1.gem
deleted file mode 100644
index 877d8a97..00000000
Binary files a/vendor/cache/mime-types-1.25.1.gem and /dev/null differ
diff --git a/vendor/cache/yajl-ruby-1.1.0.gem b/vendor/cache/yajl-ruby-1.1.0.gem
deleted file mode 100644
index 3fcb580e..00000000
Binary files a/vendor/cache/yajl-ruby-1.1.0.gem and /dev/null differ