mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add detection of GrammarKit-generated files
GrammarKit is a plugin by JetBrains for creating custom language plugins for JetBrains IDEs (such as IntelliJ, RubyMine, CLion and more). It defines a BNF parser language which can be used to generate a parser in Java, and it also integrates JFLex for generating a lexer in Java. Both of these generated Java files can be recognised by a comment on the first line of the file, and so classifying them as generated is trivial.
This commit is contained in:
@@ -72,7 +72,9 @@ module Linguist
|
||||
vcr_cassette? ||
|
||||
generated_module? ||
|
||||
generated_unity3d_meta? ||
|
||||
generated_racc?
|
||||
generated_racc? ||
|
||||
generated_jflex? ||
|
||||
generated_grammarkit?
|
||||
end
|
||||
|
||||
# Internal: Is the blob an Xcode file?
|
||||
@@ -373,5 +375,32 @@ module Linguist
|
||||
return false unless lines.count > 2
|
||||
return lines[2].start_with?("# This file is automatically generated by Racc")
|
||||
end
|
||||
|
||||
# Internal: Is this a JFlex-generated file?
|
||||
#
|
||||
# A JFlex-generated file contains:
|
||||
# /* The following code was generated by JFlex x.y.z on d/at/e ti:me */
|
||||
# on the first line.
|
||||
#
|
||||
# Return true or false
|
||||
def generated_jflex?
|
||||
return false unless extname == '.java'
|
||||
return false unless lines.count > 1
|
||||
return lines[0].start_with?("/* The following code was generated by JFlex ")
|
||||
end
|
||||
|
||||
# Internal: Is this a GrammarKit-generated file?
|
||||
#
|
||||
# A GrammarKit-generated file typically contain:
|
||||
# // This is a generated file. Not intended for manual editing.
|
||||
# on the first line. This is not always the case, as it's possible to
|
||||
# customize the class header.
|
||||
#
|
||||
# Return true or false
|
||||
def generated_grammarkit?
|
||||
return false unless extname == '.java'
|
||||
return false unless lines.count > 1
|
||||
return lines[0].start_with?("// This is a generated file. Not intended for manual editing.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user