1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/sass/repl.rb

52 lines
1.1 KiB
Ruby
Raw Normal View History

2008-10-16 16:23:45 -07:00
require 'readline'
module Sass
2009-02-25 22:11:49 -08:00
class Repl
def initialize(options = {})
@options = options
end
2008-10-16 16:23:45 -07:00
2009-02-25 22:11:49 -08:00
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
2008-10-16 16:23:45 -07:00
end
2009-02-25 22:11:49 -08:00
Readline::HISTORY << text
parse_input(environment, text)
2008-10-16 16:23:45 -07:00
end
2009-02-25 22:11:49 -08:00
end
2008-10-16 16:23:45 -07:00
2009-02-25 22:11:49 -08:00
private
2008-10-16 16:23:45 -07:00
2009-02-25 22:11:49 -08:00
def parse_input(environment, text)
case text
when Script::MATCH
name = $1
guarded = $2 == '||='
val = Script::Parser.parse($3, @line, text.size - $3.size)
2008-10-16 16:23:45 -07:00
2009-02-25 22:11:49 -08:00
unless guarded && environment.var(name)
environment.set_var(name, val.perform(environment))
end
2008-10-16 16:23:45 -07:00
2009-02-25 22:11:49 -08:00
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}"
2008-10-16 16:23:45 -07:00
end
end
end
end
end