Class: Rattler::Runner

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

Overview

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<String>)

    the command-line arguments



35
36
37
38
39
40
41
42
43
44
# File 'lib/rattler/runner.rb', line 35

def initialize(args)
  @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<String>)

    the command-line arguments



28
29
30
# File 'lib/rattler/runner.rb', line 28

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

Instance Method Details

#runObject

Run the command-line parser.



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

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