# class Sass::Repl

Runs a SassScript read-eval-print loop. It presents a prompt on the terminal, reads in SassScript expressions, evaluates them, and prints the result.

### Public Class Methods

new(options = {}) click to toggle source

@param options [{Symbol => Object}] An options hash.

    # File lib/sass/repl.rb, line 11
    def initialize(options = {})
      @options = options
    end

### Public Instance Methods

run() click to toggle source

Starts the read-eval-print loop.

    # File lib/sass/repl.rb, line 16
    def run
      environment = Environment.new
      @line = 0
      loop do
        @line += 1
        unless (text = Readline.readline('>> '))
          puts
          return
        end

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

### Private Instance Methods

parse_input(environment, text) click to toggle source

    # File lib/sass/repl.rb, line 33
    def parse_input(environment, text)
      case text
      when Script::MATCH
        name = $1
        guarded = !!$3
        val = Script::Parser.parse($2, @line, text.size - ($3 || '').size - $2.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 |line|
          puts "\tfrom #{line}"
        end
      end
    end