mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Recognise that PEG.js-generated parsers are in fact generated
This commit is contained in:
@@ -255,17 +255,16 @@ module Linguist
|
|||||||
# Includes:
|
# Includes:
|
||||||
# - XCode project XML files
|
# - XCode project XML files
|
||||||
# - Minified JavaScript
|
# - Minified JavaScript
|
||||||
|
# - Compiled CoffeeScript
|
||||||
|
# - PEG.js-generated parsers
|
||||||
#
|
#
|
||||||
# Please add additional test coverage to
|
# Please add additional test coverage to
|
||||||
# `test/test_blob.rb#test_generated` if you make any changes.
|
# `test/test_blob.rb#test_generated` if you make any changes.
|
||||||
#
|
#
|
||||||
# Return true or false
|
# Return true or false
|
||||||
def generated?
|
def generated?
|
||||||
if xcode_project_file? || generated_net_docfile?
|
if name == 'Gemfile.lock' || minified_javascript? || compiled_coffeescript? ||
|
||||||
true
|
xcode_project_file? || generated_net_docfile? || generated_parser?
|
||||||
elsif generated_coffeescript? || minified_javascript?
|
|
||||||
true
|
|
||||||
elsif name == 'Gemfile.lock'
|
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
@@ -293,17 +292,36 @@ module Linguist
|
|||||||
average_line_length > 100
|
average_line_length > 100
|
||||||
end
|
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
|
# Requires Blob#data
|
||||||
#
|
#
|
||||||
# CoffeScript is meant to output JS that would be difficult to
|
# CoffeScript is meant to output JS that would be difficult to
|
||||||
# tell if it was generated or not. Look for a number of patterns
|
# 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
|
# Return true or false
|
||||||
def generated_coffeescript?
|
def compiled_coffeescript?
|
||||||
return unless extname == '.js'
|
return false unless extname == '.js'
|
||||||
|
|
||||||
# CoffeeScript generated by > 1.2 include a comment on the first line
|
# CoffeeScript generated by > 1.2 include a comment on the first line
|
||||||
if lines[0] =~ /^\/\/ Generated by /
|
if lines[0] =~ /^\/\/ Generated by /
|
||||||
|
|||||||
2963
test/fixtures/javascript/parser.js
vendored
Normal file
2963
test/fixtures/javascript/parser.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -183,9 +183,13 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert blob("javascript/jquery-1.6.1.min.js").generated?
|
assert blob("javascript/jquery-1.6.1.min.js").generated?
|
||||||
assert blob("javascript/jquery-1.4.2.min.js").generated?
|
assert blob("javascript/jquery-1.4.2.min.js").generated?
|
||||||
|
|
||||||
# CoffeScript JS
|
# CoffeeScript-generated JS
|
||||||
|
# TODO
|
||||||
|
|
||||||
# These examples are to basic to tell
|
# PEG.js-generated parsers
|
||||||
|
assert blob("javascript/parser.js").generated?
|
||||||
|
|
||||||
|
# These examples are too basic to tell
|
||||||
assert !blob("javascript/empty.js").generated?
|
assert !blob("javascript/empty.js").generated?
|
||||||
assert !blob("javascript/hello.js").generated?
|
assert !blob("javascript/hello.js").generated?
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user