Skip to content

Commit

Permalink
Merge branch 'master' into associate-heuristic-with-extension
Browse files Browse the repository at this point in the history
Conflicts:
	lib/linguist/heuristics.rb
  • Loading branch information
pchaigno committed Jun 18, 2015
2 parents be122ca + 4757da7 commit 8bf1def
Show file tree
Hide file tree
Showing 42 changed files with 1,960 additions and 39 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
[submodule "vendor/grammars/fancy-tmbundle"]
path = vendor/grammars/fancy-tmbundle
url = https://github.com/fancy-lang/fancy-tmbundle
[submodule "vendor/grammars/fsharpbinding"]
path = vendor/grammars/fsharpbinding
url = https://github.com/fsharp/fsharpbinding
[submodule "vendor/grammars/monkey.tmbundle"]
path = vendor/grammars/monkey.tmbundle
url = https://github.com/gingerbeardman/monkey.tmbundle
Expand Down Expand Up @@ -644,3 +641,9 @@
[submodule "vendor/grammars/smali-sublime"]
path = vendor/grammars/smali-sublime
url = https://github.com/ShaneWilton/sublime-smali
[submodule "vendor/grammars/language-jsoniq"]
path = vendor/grammars/language-jsoniq
url = http://github.com/wcandillon/language-jsoniq
[submodule "vendor/grammars/atom-fsharp"]
path = vendor/grammars/atom-fsharp
url = https://github.com/fsprojects/atom-fsharp
8 changes: 6 additions & 2 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ vendor/grammars/asp.tmbundle:
vendor/grammars/assembly.tmbundle:
- objdump.x86asm
- source.x86asm
vendor/grammars/atom-fsharp/:
- source.fsharp
vendor/grammars/atom-salt:
- source.python.salt
- source.yaml.salt
Expand Down Expand Up @@ -215,6 +217,7 @@ vendor/grammars/d.tmbundle:
vendor/grammars/dart-sublime-bundle:
- source.dart
- source.pubspec
- text.dart-analysis-output
- text.dart-doccomments
vendor/grammars/desktop.tmbundle:
- source.desktop
Expand Down Expand Up @@ -247,8 +250,6 @@ vendor/grammars/fish-tmbundle:
vendor/grammars/fortran.tmbundle:
- source.fortran
- source.fortran.modern
vendor/grammars/fsharpbinding:
- source.fsharp
vendor/grammars/gap-tmbundle/:
- source.gap
vendor/grammars/gettext.tmbundle:
Expand Down Expand Up @@ -320,6 +321,9 @@ vendor/grammars/language-hy:
vendor/grammars/language-javascript:
- source.js
- source.js.regexp
vendor/grammars/language-jsoniq/:
- source.jq
- source.xq
vendor/grammars/language-python:
- source.python
- source.regexp.python
Expand Down
22 changes: 20 additions & 2 deletions lib/linguist/heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,30 @@ def call(data)
end

disambiguate ".l" do |data|
if data.include?("(def(un|macro)\s")
if /\(def(un|macro)\s/.match(data)
Language["Common Lisp"]
elsif /^(%[%{}]xs|<.*>)/.match(data)
Language["Lex"]
elsif /^\.[a-z][a-z](\s|$)/.match(data)
elsif /^\.[a-z][a-z](\s|$)/i.match(data)
Language["Groff"]
elsif /^\((de|class|rel|code|data|must)\s/.match(data)
Language["PicoLisp"]
end
end

disambiguate "Groff", "Nemerle" do |data|
if /^[.']/.match(data)
Language["Groff"]
elsif /^(module|namespace|using)\s/.match(data)
Language["Nemerle"]
end
end

disambiguate "GAS", "Groff" do |data|
if /^[.'][a-z][a-z](\s|$)/i.match(data)
Language["Groff"]
elsif /((^|\s)move?[. ])|\.(include|globa?l)\s/.match(data)
Language["GAS"]
end
end
end
Expand Down
28 changes: 27 additions & 1 deletion lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ GAS:
group: Assembly
extensions:
- .s
- .ms
tm_scope: source.asm.x86
ace_mode: assembly_x86

Expand Down Expand Up @@ -1209,13 +1210,26 @@ Groff:
extensions:
- .man
- '.1'
- .1in
- .1m
- .1x
- '.2'
- '.3'
- .3in
- .3m
- .3qt
- .3x
- '.4'
- '.5'
- '.6'
- '.7'
- '.8'
- '.9'
- .l
- .ms
- .n
- .rno
- .roff
tm_scope: text.groff
aliases:
- nroff
Expand Down Expand Up @@ -1508,11 +1522,12 @@ JSONLD:
tm_scope: source.js

JSONiq:
color: "#40d47e"
type: programming
ace_mode: jsoniq
extensions:
- .jq
tm_scope: source.xquery
tm_scope: source.jq

Jade:
group: HTML
Expand Down Expand Up @@ -2475,6 +2490,16 @@ Perl6:
tm_scope: source.perl.6
ace_mode: perl

PicoLisp:
type: programming
extensions:
- .l
interpreters:
- picolisp
- pil
tm_scope: source.lisp
ace_mode: lisp

PigLatin:
type: programming
color: "#fcd7de"
Expand Down Expand Up @@ -3554,6 +3579,7 @@ XQuery:
- .xqm
- .xqy
ace_mode: xquery
tm_scope: source.xq

XS:
type: programming
Expand Down
2 changes: 1 addition & 1 deletion lib/linguist/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Linguist
VERSION = "4.5.5"
VERSION = "4.5.6"
end
164 changes: 164 additions & 0 deletions samples/Common Lisp/array.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
;;; -*- Mode: Lisp; Package: LISP -*-
;;;
;;; This file is part of xyzzy.
;;;

(provide "array")

(in-package "lisp")

(export '(make-vector make-array vector array-dimensions array-in-bounds-p
upgraded-array-element-type adjust-array))

(defun upgraded-array-element-type (type)
(cond ((or (eq type 't)
(null type))
't)
((member type '(character base-character standard-char
extended-character) :test #'eq)
'character)
(t
(setq type (car (si:canonicalize-type type)))
(cond ((or (eq type 't)
(null type))
't)
((member type '(character base-character standard-char
extended-character) :test #'eq)
'character)
(t 't)))))

(defun check-array-initialize-option (ies-p ics-p displaced-to)
(let ((x 0))
(and ies-p (incf x))
(and ics-p (incf x))
(and displaced-to (incf x))
(when (> x 1)
(error ":initial-element, :initial-contents, :displaced-to"))))

(defun make-vector (length &key
(element-type t)
(initial-element nil ies-p)
(initial-contents nil ics-p)
fill-pointer
adjustable
displaced-to
(displaced-index-offset 0))
(setq element-type (upgraded-array-element-type element-type))
(check-array-initialize-option ies-p ics-p displaced-to)
(let ((vector (si:*make-vector length element-type initial-element adjustable
fill-pointer displaced-to displaced-index-offset)))
(when ics-p
(si:*copy-into-seq vector initial-contents))
vector))

(defun make-array (dimensions &rest rest
&key
(element-type t)
(initial-element nil ies-p)
(initial-contents nil ics-p)
fill-pointer
adjustable
displaced-to
(displaced-index-offset 0))
(cond ((integerp dimensions)
(apply #'make-vector dimensions rest))
((= (length dimensions) 1)
(apply #'make-vector (car dimensions) rest))
(t
(setq element-type (upgraded-array-element-type element-type))
(check-array-initialize-option ies-p ics-p displaced-to)
(when fill-pointer
(error ":fill-pointer"))
(let ((array (si:*make-array dimensions element-type
initial-element adjustable
displaced-to displaced-index-offset)))
(when ics-p
(let ((dims (make-list (array-rank array)
:initial-element 0))
(stack (list initial-contents))
(rank (1- (array-rank array))))
(dolist (x dims)
(push (elt (car stack) 0) stack))
(dotimes (i (array-total-size array))
(setf (row-major-aref array i) (car stack))
(do ((x dims (cdr x))
(j rank (1- j)))
((null x))
(pop stack)
(incf (car x))
(when (< (car x) (array-dimension array j))
(do ((r (- rank j) (1- r)))
((< r 0))
(push (elt (car stack) (nth r dims)) stack))
(return))
(setf (car x) 0)))))
array))))

(defun vector (&rest list)
(make-vector (length list) :element-type t :initial-contents list))

(defun array-dimensions (array)
(do ((i (1- (array-rank array)) (1- i))
(dims '()))
((minusp i) dims)
(push (array-dimension array i) dims)))

(defun array-in-bounds-p (array &rest subscripts)
(let ((r (array-rank array)))
(when (/= r (length subscripts))
(error "subscripts: ~S" subscripts))
(do ((i 0 (1+ i))
(s subscripts (cdr s)))
((= i r) t)
(unless (<= 0 (car s) (1- (array-dimension array i)))
(return nil)))))

(defun adjust-array (old-array
dimensions
&rest rest
&key
(element-type nil ets-p)
initial-element
(initial-contents nil ics-p)
(fill-pointer nil fps-p)
displaced-to
displaced-index-offset)
(when (/= (length dimensions) (array-rank old-array))
(error "?"))
(unless ets-p
(push (array-element-type old-array) rest)
(push :element-type rest))
(when (adjustable-array-p old-array)
(push t rest)
(push :adjustable rest))
(cond (fps-p
(unless (array-has-fill-pointer-p old-array)
(error "?")))
(t
(when (array-has-fill-pointer-p old-array)
(push (fill-pointer old-array) rest)
(push :fill-pointer rest))))
(when (eq old-array displaced-to)
(error "?"))
(let ((new-array (apply #'make-array dimensions rest)))
(or ics-p displaced-to
(copy-array-partially old-array new-array))
(cond ((adjustable-array-p old-array)
(si:*replace-array old-array new-array)
old-array)
(t
new-array))))

(defun copy-array-partially (src dst)
(let* ((dims (mapcar #'min (array-dimensions src) (array-dimensions dst)))
(r (array-rank src))
(s (make-list r :initial-element 0)))
(setq r (1- r))
(dotimes (x (apply #'* dims))
(setf (apply #'aref dst s) (apply #'aref src s))
(do ((i r (1- i)))
((minusp i))
(incf (nth i s))
(when (< (nth i s) (nth i dims))
(return))
(setf (nth i s) 0)))))
Loading

0 comments on commit 8bf1def

Please sign in to comment.