Module: Inform::Grammar
- Defined in:
- lib/story_teller/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
343 344 345 |
# File 'lib/story_teller/grammar_parser.rb', line 343 def self.absolute_basename(file_path) File.basename(file_path, File.extname(file_path)).split(/\./).first end |
.get_path_for_best_match(str) ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/story_teller/grammar_parser.rb', line 348 def self.get_path_for_best_match(str) VALID_EXTENSIONS.each do |ext| grammar_guess = str + ext guess = File.( File.join( StoryTeller::Library.inform_gem_lib_path, StoryTeller::Engine.inform_code_prefix, grammar_guess)) return guess if File.exist?(guess) end nil end |
.load_by_name(module_name) ⇒ Object
361 362 363 364 |
# File 'lib/story_teller/grammar_parser.rb', line 361 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
366 367 368 369 370 371 372 373 |
# File 'lib/story_teller/grammar_parser.rb', line 366 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 |