Module: HH::Syntax

Defined in:
lib/ext/highlighter/common.rb,
lib/ext/highlighter/lang/ruby.rb

Defined Under Namespace

Classes: Default, Ruby, Token, Tokenizer

Constant Summary collapse

SYNTAX =

A hash for registering syntax implementations.

Hash.new( Default )

Class Method Summary collapse

Class Method Details

.allObject

Return an array of the names of supported syntaxes.



190
191
192
193
# File 'lib/ext/highlighter/common.rb', line 190

def all
  lang_dir = File.join(File.dirname(__FILE__), "syntax", "lang")
  Dir["#{lang_dir}/*.rb"].map { |path| File.basename(path, ".rb") }
end

.load(syntax) ⇒ Object

Load the implementation of the requested syntax. If the syntax cannot be found, or if it cannot be loaded for whatever reason, the Default syntax handler will be returned.



180
181
182
183
184
185
186
# File 'lib/ext/highlighter/common.rb', line 180

def load( syntax )
  begin
    require_relative "lang/#{syntax}"
  rescue LoadError
  end
  SYNTAX[ syntax ].new
end