Sha256: ab19ced543e8e05c699e155928bc323723a3839b4c7baf9af8c700fbf27a0fe6

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# Run a script.
# Shortcut for telling a script to run.
#

module GlooLang
  module Verbs
    class Run < GlooLang::Core::Verb

      KEYWORD = 'run'.freeze
      KEYWORD_SHORT = 'r'.freeze
      EVALUATE_RUN = '~>'.freeze
      MISSING_EXPR_ERR = 'Missing Expression!'.freeze

      #
      # Run the verb.
      #
      def run
        if @tokens.token_count < 2
          $engine.err MISSING_EXPR_ERR
          return
        end

        if @tokens.second == EVALUATE_RUN
          run_expression
        else
          run_script
        end
      end

      #
      # Get the Verb's keyword.
      #
      def self.keyword
        return KEYWORD
      end

      #
      # Get the Verb's keyword shortcut.
      #
      def self.keyword_shortcut
        return KEYWORD_SHORT
      end

      # ---------------------------------------------------------------------
      #    Private functions
      # ---------------------------------------------------------------------

      private

      #
      # Run a script specified by pathname
      #
      def run_script
        GlooLang::Exec::Runner.run @tokens.second
      end

      #
      # Evaluate an expression and run that.
      #
      def run_expression
        unless @tokens.token_count > 2
          $engine.err MISSING_EXPR_ERR
          return
        end

        expr = GlooLang::Expr::Expression.new( @tokens.params[ 1..-1 ] )
        $engine.parser.run expr.evaluate
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gloo-lang-0.9.8 lib/gloo_lang/verbs/run.rb
gloo-lang-0.9.7 lib/gloo_lang/verbs/run.rb
gloo-lang-0.9.6 lib/gloo_lang/verbs/run.rb
gloo-lang-0.9.5 lib/gloo_lang/verbs/run.rb
gloo-lang-0.9.4 lib/gloo_lang/verbs/run.rb
gloo-lang-0.9.3 lib/gloo_lang/verbs/run.rb