mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add Lexer class
This commit is contained in:
39
lib/linguist/lexer.rb
Normal file
39
lib/linguist/lexer.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
require 'yaml'
|
||||
|
||||
module Linguist
|
||||
class Lexer < Struct.new(:name, :aliases, :filenames, :mimetypes)
|
||||
@name_index = {}
|
||||
@alias_index = {}
|
||||
|
||||
def self.find_by_name(name)
|
||||
@name_index[name.downcase]
|
||||
end
|
||||
|
||||
def self.find_by_alias(name)
|
||||
@alias_index[name.downcase]
|
||||
end
|
||||
|
||||
def self.[](name)
|
||||
find_by_name(name) || find_by_alias(name)
|
||||
end
|
||||
|
||||
def to_s
|
||||
aliases.first
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
eql?(other)
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
equal?(other)
|
||||
end
|
||||
|
||||
YAML.load_file(File.expand_path("../lexers.yml", __FILE__)).each do |lexer|
|
||||
@name_index[lexer.name.downcase] = lexer
|
||||
lexer.aliases.each do |name|
|
||||
@alias_index[name.downcase] = lexer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user