Recognise that PEG.js-generated parsers are in fact generated

This commit is contained in:
Michael Ficarra
2012-06-19 11:18:51 -05:00
parent 8a9d8a15af
commit 11166911dc
3 changed files with 2996 additions and 11 deletions

View File

@@ -255,17 +255,16 @@ module Linguist
# Includes:
# - XCode project XML files
# - Minified JavaScript
# - Compiled CoffeeScript
# - PEG.js-generated parsers
#
# Please add additional test coverage to
# `test/test_blob.rb#test_generated` if you make any changes.
#
# Return true or false
def generated?
if xcode_project_file? || generated_net_docfile?
true
elsif generated_coffeescript? || minified_javascript?
true
elsif name == 'Gemfile.lock'
if name == 'Gemfile.lock' || minified_javascript? || compiled_coffeescript? ||
xcode_project_file? || generated_net_docfile? || generated_parser?
true
else
false
@@ -293,17 +292,36 @@ module Linguist
average_line_length > 100
end
# Internal: Is the blob JS generated by CoffeeScript?
# Internal: Is the blob of JS a parser generated by PEG.js?
#
# Requires Blob#data
#
# PEG.js-generated parsers are not meant to be consumed by humans.
#
# Return true or false
def generated_parser?
return false unless extname == '.js'
# PEG.js-generated parsers include a comment near the top of the file
# that marks them as such.
if lines[0..4].join('') =~ /^(?:[^\/]|\/[^\*])*\/\*(?:[^\*]|\*[^\/])*Generated by PEG.js/
return true
end
false
end
# Internal: Is the blob of JS generated by CoffeeScript?
#
# Requires Blob#data
#
# CoffeScript is meant to output JS that would be difficult to
# tell if it was generated or not. Look for a number of patterns
# outputed by the CS compiler.
# output by the CS compiler.
#
# Return true or false
def generated_coffeescript?
return unless extname == '.js'
def compiled_coffeescript?
return false unless extname == '.js'
# CoffeeScript generated by > 1.2 include a comment on the first line
if lines[0] =~ /^\/\/ Generated by /