Module: Inform::Grammar
- Defined in:
- lib/runtime/grammar_parser.rb
Overview
Grammar
Defined Under Namespace
Constant Summary collapse
- Verbs =
Inform::Grammar::Index.new
- VALID_EXTENSIONS =
['h.inf.rb', '.inf.rb', '.rb', ''].freeze
- SUPPORT_DIR_PATH =
File.(__dir__)
Class Method Summary collapse
- .absolute_basename(file_path) ⇒ Object
- .get_path_for_best_match(str) ⇒ Object
- .load_by_name(module_name) ⇒ Object
- .load_by_path(module_path, module_name = nil) ⇒ Object
- .partitions ⇒ Object
- .selections ⇒ Object
Class Method Details
.absolute_basename(file_path) ⇒ Object
361 362 363 |
# File 'lib/runtime/grammar_parser.rb', line 361 def self.absolute_basename(file_path) File.basename(file_path, File.extname(file_path)).split(/\./).first end |
.get_path_for_best_match(str) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/runtime/grammar_parser.rb', line 366 def self.get_path_for_best_match(str) VALID_EXTENSIONS.each do |ext| grammar_guess = str + ext guess = File.( File.join( Inform::Library.inform_gem_lib_path, Inform::Runtime.inform_dir_path, grammar_guess)) return guess if File.exist?(guess) end nil end |
.load_by_name(module_name) ⇒ Object
379 380 381 382 |
# File 'lib/runtime/grammar_parser.rb', line 379 def self.load_by_name(module_name) module_path = get_path_for_best_match(module_name) load_by_path(module_path, module_name) end |
.load_by_path(module_path, module_name = nil) ⇒ Object
384 385 386 387 388 389 390 391 |
# File 'lib/runtime/grammar_parser.rb', line 384 def self.load_by_path(module_path, module_name = nil) raise ArgumentError, 'Parameter may not be nil: module_path' if module_path.nil? raise LoadError, 'No such file: ' + module_path unless File.exist?(module_path) module_name ||= absolute_basename(module_path) log.debug "Loading grammar file: #{module_path}" Inform::Grammar::Parser.new.parse_grammar( module_name.to_sym, File.foreach(module_path), origin_path: module_path) end |