mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Merge branch 'pr/804' into postscript_support
Conflicts: lib/linguist/generated.rb
This commit is contained in:
@@ -58,6 +58,7 @@ module Linguist
|
||||
generated_parser? ||
|
||||
generated_net_docfile? ||
|
||||
generated_net_designer_file? ||
|
||||
generated_postscript? ||
|
||||
generated_protocol_buffer? ||
|
||||
generated_jni_header? ||
|
||||
composer_lock? ||
|
||||
@@ -176,6 +177,29 @@ module Linguist
|
||||
false
|
||||
end
|
||||
|
||||
# Internal: Is the blob of PostScript generated?
|
||||
#
|
||||
# PostScript files are often generated by other programs. If they tell us so,
|
||||
# we can detect them.
|
||||
#
|
||||
# Returns true or false.
|
||||
def generated_postscript?
|
||||
return false unless ['.ps', '.eps'].include? extname
|
||||
|
||||
# We analyze the "%%Creator:" comment, which contains the author/generator
|
||||
# of the file. If there is one, it should be in one of the first few lines.
|
||||
creator = lines[0..9].find {|line| line =~ /^%%Creator: /}
|
||||
return false if creator.nil?
|
||||
|
||||
# Most generators write their version number, while human authors' or companies'
|
||||
# names don't contain numbers. So look if the line contains digits. Also
|
||||
# look for some special cases without version numbers.
|
||||
return creator =~ /[0-9]/ ||
|
||||
creator.include?("mpage") ||
|
||||
creator.include?("draw") ||
|
||||
creator.include?("ImageMagick")
|
||||
end
|
||||
|
||||
# Internal: Is the blob a C++, Java or Python source file generated by the
|
||||
# Protocol Buffer compiler?
|
||||
#
|
||||
|
||||
@@ -1255,6 +1255,12 @@ PogoScript:
|
||||
lexer: Text only
|
||||
primary_extension: .pogo
|
||||
|
||||
PostScript:
|
||||
type: markup
|
||||
primary_extension: .ps
|
||||
extensions:
|
||||
- .eps
|
||||
|
||||
PowerShell:
|
||||
type: programming
|
||||
ace_mode: powershell
|
||||
|
||||
41
samples/PostScript/sierpinski.ps
Normal file
41
samples/PostScript/sierpinski.ps
Normal file
@@ -0,0 +1,41 @@
|
||||
%!PS-Adobe-3.0
|
||||
%%Creator: Aaron Puchert
|
||||
%%Title: The Sierpinski triangle
|
||||
%%Pages: 1
|
||||
%%PageOrder: Ascend
|
||||
|
||||
%%BeginProlog
|
||||
% PAGE SETTINGS
|
||||
/pageset {
|
||||
28.3464566 28.3464566 scale % set cm = 1
|
||||
0.5 0.5 translate
|
||||
0 setlinewidth
|
||||
} def
|
||||
|
||||
% sierpinski(n) draws a sierpinski triangle of order n
|
||||
/sierpinski {
|
||||
dup 0 gt {
|
||||
[0.5 0 0 0.5 0 0] concat dup 1 sub sierpinski
|
||||
[1 0 0 1 1 0] concat dup 1 sub sierpinski
|
||||
[1 0 0 1 -1 1] concat dup 1 sub sierpinski
|
||||
[2 0 0 2 0 -1] concat
|
||||
} {
|
||||
newpath
|
||||
0 0 moveto
|
||||
1 0 lineto
|
||||
0 1 lineto
|
||||
closepath
|
||||
fill
|
||||
} ifelse pop} def
|
||||
%%EndProlog
|
||||
|
||||
%%BeginSetup
|
||||
<< /PageSize [596 843] >> setpagedevice % A4
|
||||
%%EndSetup
|
||||
|
||||
%%Page: Test 1
|
||||
pageset
|
||||
[20 0 10 300 sqrt 0 0] concat
|
||||
9 sierpinski
|
||||
showpage
|
||||
%%EOF
|
||||
@@ -185,6 +185,9 @@ class TestBlob < Test::Unit::TestCase
|
||||
# PEG.js-generated parsers
|
||||
assert blob("JavaScript/parser.js").generated?
|
||||
|
||||
# Generated PostScript
|
||||
assert !blob("PostScript/sierpinski.ps").generated?
|
||||
|
||||
# These examples are too basic to tell
|
||||
assert !blob("JavaScript/empty.js").generated?
|
||||
assert !blob("JavaScript/hello.js").generated?
|
||||
|
||||
Reference in New Issue
Block a user