Module: Inform::Grammar

Defined in:
lib/story_teller/grammar_parser.rb

Overview

Grammar

Defined Under Namespace

Classes: Index, Parser

Constant Summary collapse

Verbs =
Inform::Grammar::Index.new
VALID_EXTENSIONS =
['h.inf.rb', '.inf.rb', '.rb', ''].freeze
SUPPORT_DIR_PATH =
File.expand_path(__dir__)

Class Method Summary collapse

Class Method Details

.absolute_basename(file_path) ⇒ Object



390
391
392
# File 'lib/story_teller/grammar_parser.rb', line 390

def self.absolute_basename(file_path)
  File.basename(file_path, File.extname(file_path)).split(/\./).first
end

.get_path_for_best_match(str) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/story_teller/grammar_parser.rb', line 395

def self.get_path_for_best_match(str)
  VALID_EXTENSIONS.each do |ext|
    grammar_guess = str + ext
    guess = File.expand_path(
      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



408
409
410
411
# File 'lib/story_teller/grammar_parser.rb', line 408

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

Raises:

  • (ArgumentError)


413
414
415
416
417
418
419
420
# File 'lib/story_teller/grammar_parser.rb', line 413

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

.partitionsObject



380
381
382
# File 'lib/story_teller/grammar_parser.rb', line 380

def self.partitions
  @partitions ||= defined?(Java) ? java.util.concurrent.ConcurrentHashMap.new : {}
end

.selectionsObject



384
385
386
# File 'lib/story_teller/grammar_parser.rb', line 384

def self.selections
  @selections ||= defined?(Java) ? java.util.concurrent.ConcurrentHashMap.new : {}
end