Class: Mayl::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/mayl/parser.rb

Overview

Public: The parser interprets commands and executes them.

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Parser

Public: initializes a new Parser with an environment.

env - the global state.



7
8
9
# File 'lib/mayl/parser.rb', line 7

def initialize(env)
  @env = env
end

Instance Method Details

#parse(input) ⇒ Object

Public: Parses a given input and creates a command representation for it.

Returns a Command.



14
15
16
17
18
# File 'lib/mayl/parser.rb', line 14

def parse(input)
  operator, *operands = input.split
  klass = Commands.const_get(operator.capitalize)
  klass.new(@env, *Array(operands))
end