Class: ShellOpts::Grammar::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/shellopts/compiler.rb

Overview

Service object for compiling an option definition string. Returns a Grammar::Program object

Compiler implements a recursive descend algorithm to compile the option string. The algorithm uses state variables and is embedded in a Grammar::Compiler service object

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(program_name, source) ⇒ Compiler

Initialize a Compiler object. source is the option definition string



29
30
31
32
33
34
35
36
37
# File 'lib/shellopts/compiler.rb', line 29

def initialize(program_name, source)
  @program_name, @tokens = program_name, source.split(/\s+/).reject(&:empty?)

  # @commands_by_path is an hash from command-path to Command or Program
  # object. The top level Program object has nil as its path.
  # @commands_by_path is used to check for uniqueness of commands and to
  # link sub-commands to their parents
  @commands_by_path = {}
end

Instance Method Details

#callObject



39
40
41
# File 'lib/shellopts/compiler.rb', line 39

def call
  compile_program
end