Sha256: e6a11ce3769ffc33931edc9bf92e1621d697434e2954216344eb5b9843bfb7dc

Contents?: true

Size: 1.09 KB

Versions: 31

Compression:

Stored size: 1.09 KB

Contents

require 'readline'

module Sass
  class Repl
    def initialize(options = {})
      @options = options
    end

    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

31 entries across 31 versions & 6 rubygems

Version Path
gohanlonllc-haml-2.1.0.20080513000000 lib/sass/repl.rb
gohanlonllc-haml-2.1.0 lib/sass/repl.rb
honkster-haml-2.1.0 lib/sass/repl.rb
honkster-haml-2.1.1 lib/sass/repl.rb
jwhitmire-haml-2.1.0.1 lib/sass/repl.rb
jwhitmire-haml-2.1.0.2 lib/sass/repl.rb
jwhitmire-haml-2.1.0.3 lib/sass/repl.rb
wireframe-haml-2.1.0 lib/sass/repl.rb
wireframe-haml-2.1.1 lib/sass/repl.rb
haml-edge-2.1.10 lib/sass/repl.rb
haml-edge-2.1.11 lib/sass/repl.rb
haml-edge-2.1.1 lib/sass/repl.rb
haml-edge-2.1.12 lib/sass/repl.rb
haml-edge-2.1.21 lib/sass/repl.rb
haml-edge-2.1.17 lib/sass/repl.rb
haml-edge-2.1.13 lib/sass/repl.rb
haml-edge-2.1.15 lib/sass/repl.rb
haml-edge-2.1.16 lib/sass/repl.rb
haml-edge-2.1.18 lib/sass/repl.rb
haml-edge-2.1.19 lib/sass/repl.rb