diff --git a/ruby/Rakefile b/ruby/Rakefile index bf533d4..ca9dddc 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -7,7 +7,12 @@ namespace :test do desc "Run tests on source changes" task :watch do loop do - sh "fd .*.rb | entr -d rake test:isolated" + sh <<~SH + while true + do + fd .*.rb | entr -d rake test:isolated + done + SH end end end diff --git a/ruby/lib/lox/resolver.rb b/ruby/lib/lox/resolver.rb new file mode 100644 index 0000000..1321adf --- /dev/null +++ b/ruby/lib/lox/resolver.rb @@ -0,0 +1,33 @@ +module Lox + class Resolver + + def initialize(interpreter) + @interpreter = interpreter + + @scopes = [] + end + + def resolve(values) + values.each do + value.accept(self) + end + end + + def visit_block(stmt) + with_scope do + resolve(stmt.stmts) + end + nil + end + + private + + def with_block + @scopes.push({}) + yield + @scopes.pop + end + + + end +end