Class: Rattler::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rattler/runner.rb

Overview

Rattler::Runner defines the command-line parser generator.

Constant Summary collapse

ERRNO_USAGE =

Invalid command line arguments

1
ERRNO_READ_ERROR =

Error reading grammar file

2
ERRNO_WRITE_ERROR =

Error writing parser file

3
ERRNO_PARSE_ERROR =

Error parsing grammar

4
ERRNO_GEN_ERROR =

Error generaing ruby code

5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Create a new command-line parser.

Parameters:

  • args (Array)

    the command-line arguments



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rattler/runner.rb', line 32

def initialize(args)
  @standalone = false
  @optimize = true
  options.parse!(args)
  if args.size == 1
    @srcfname = Pathname.new(args.shift)
  else
    puts options
    exit ERRNO_USAGE
  end
end

Class Method Details

.run(args) ⇒ Object

Run the command-line parser

Parameters:

  • args (Array)

    the command-line arguments



25
26
27
# File 'lib/rattler/runner.rb', line 25

def self.run(args)
  self.new(args).run
end

Instance Method Details

#runObject

Run the command-line parser.



45
46
47
48
49
50
51
52
# File 'lib/rattler/runner.rb', line 45

def run
  if result = analyze
    synthesize(result)
  else
    puts parser.failure
    exit ERRNO_PARSE_ERROR
  end
end