Guess .h language

This commit is contained in:
Joshua Peek
2011-05-27 14:57:11 -05:00
parent c73d45f9f9
commit 61bdd3deaf
12 changed files with 118 additions and 6 deletions

View File

@@ -269,8 +269,12 @@ module Linguist
# Returns a Language object
def language
if text?
# First see if there is a Language for the extension
if Language.find_by_extension(extname)
# If its a header file (.h) try to guess the language
if language = header_language
language
# See if there is a Language for the extension
elsif Language.find_by_extension(extname)
pathname.language
# Try to detect Language from shebang line
@@ -293,6 +297,21 @@ module Linguist
language.lexer
end
# Internal: Guess language of header files (.h).
#
# Returns a Language.
def header_language
return unless extname == '.h'
if lines.grep(/^@(interface|property|private|public|end)/).any?
Language['Objective-C']
elsif lines.grep(/^class |^\s+(public|protected|private):/).any?
Language['C++']
else
Language['C']
end
end
# Internal: Extract the script name from the shebang line
#
# Requires Blob#data