Sha256: 5a569b5f45dc0129a7ba53ca7830191dbb787c02cb162eabb3e09c437c842b0e

Contents?: true

Size: 519 Bytes

Versions: 4

Compression:

Stored size: 519 Bytes

Contents

module Mayl
  # Public: The parser interprets commands and executes them.
  class Parser
    # Public: initializes a new Parser with an environment.
    #
    # env - the global state.
    def initialize(env)
      @env = env
    end

    # Public: Parses a given input and creates a command representation for it.
    #
    # Returns a Command.
    def parse(input)
      operator, *operands = input.split
      klass = Commands.const_get(operator.capitalize)
      klass.new(@env, *Array(operands))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mayl-0.2.1 lib/mayl/parser.rb
mayl-0.2.0 lib/mayl/parser.rb
mayl-0.1.0 lib/mayl/parser.rb
mayl-0.0.1 lib/mayl/parser.rb