Class: Mayl::Parser
- Inherits:
-
Object
- Object
- Mayl::Parser
- Defined in:
- lib/mayl/parser.rb
Overview
Public: The parser interprets commands and executes them.
Instance Method Summary collapse
-
#initialize(env) ⇒ Parser
constructor
Public: initializes a new Parser with an environment.
-
#parse(input) ⇒ Object
Public: Parses a given input and creates a command representation for it.
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 |