Sha256: 8e8c8d6d5adca5f11a5db4c3803b8c9d6a21a72190a8c5b9f341311e1a4d6953

Contents?: true

Size: 1.35 KB

Versions: 48

Compression:

Stored size: 1.35 KB

Contents

require 'readline'

module Sass
  # Runs a SassScript read-eval-print loop.
  # It presents a prompt on the terminal,
  # reads in SassScript expressions,
  # evaluates them,
  # and prints the result.
  class Repl
    # @param options [{Symbol => Object}] An options hash.
    def initialize(options = {})
      @options = options
    end

    # Starts the read-eval-print loop.
    def run
      environment = Environment.new
      environment.set_var('important', Script::String.new('!important'))
      @line = 0
      loop do
        @line += 1
        unless text = Readline.readline('>> ')
          puts
          return
        end

        Readline::HISTORY << text
        parse_input(environment, text)
      end
    end

    private

    def parse_input(environment, text)
      case text
      when Script::MATCH
        name = $1
        guarded = $2 == '||='
        val = Script::Parser.parse($3, @line, text.size - $3.size)

        unless guarded && environment.var(name)
          environment.set_var(name, val.perform(environment))
        end

        p environment.var(name)
      else
        p Script::Parser.parse(text, @line, 0).perform(environment)
      end
    rescue Sass::SyntaxError => e
      puts "SyntaxError: #{e.message}"
      if @options[:trace]
        e.backtrace.each do |e|
          puts "\tfrom #{e}"
        end
      end
    end
  end
end

Version data entries

48 entries across 47 versions & 6 rubygems

Version Path
radiantcms-couchrest_model-0.1.4 vendor/plugins/haml/lib/sass/repl.rb
radiant-0.9.1 vendor/plugins/haml/lib/sass/repl.rb
haml-2.2.24 lib/sass/repl.rb
radiant-0.9.0.rc2 vendor/plugins/haml/lib/sass/repl.rb
haml-2.2.23 lib/sass/repl.rb
haml-edge-2.3.179 lib/sass/repl.rb
haml-edge-2.3.178 lib/sass/repl.rb
haml-edge-2.3.177 lib/sass/repl.rb
haml-edge-2.3.176 lib/sass/repl.rb
haml-edge-2.3.175 lib/sass/repl.rb
haml-2.2.22 lib/sass/repl.rb
haml-edge-2.3.174 lib/sass/repl.rb
haml-edge-2.3.173 lib/sass/repl.rb
haml-edge-2.3.172 lib/sass/repl.rb
haml-edge-2.3.171 lib/sass/repl.rb
haml-edge-2.3.170 lib/sass/repl.rb
haml-2.2.21 lib/sass/repl.rb
haml-edge-2.3.169 lib/sass/repl.rb
haml-edge-2.3.168 lib/sass/repl.rb
haml-edge-2.3.167 lib/sass/repl.rb