mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
44 lines
1,004 B
Ruby
44 lines
1,004 B
Ruby
require 'readline'
|
|
|
|
module Sass
|
|
module Repl
|
|
class << self
|
|
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)
|
|
|
|
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}"
|
|
end
|
|
end
|
|
end
|
|
end
|