Skip to content
Browse files

add iter support

  • Loading branch information...
1 parent 11481e6 commit 208c5ba0a56f3ec39e1b24f6f1d3162c2d3e5c6d @rkh committed Aug 30, 2011
View
1 lib/reak/bootstrap/ast.rb
@@ -4,6 +4,7 @@ module AST
require 'reak/bootstrap/ast/string'
require 'reak/bootstrap/ast/constant_access'
require 'reak/bootstrap/ast/scoped_constant'
+ require 'reak/bootstrap/ast/iter'
require 'reak/bootstrap/ast/keyword_send'
require 'reak/bootstrap/ast/block'
View
15 lib/reak/bootstrap/ast/iter.rb
@@ -0,0 +1,15 @@
+module Reak
+ module AST
+ class Iter < Rubinius::AST::Iter
+ include Reak::AST::Node
+
+ def self.bootstrap_grammar(g)
+ g.seq("[", g.t(:block), "]")
+ end
+
+ def self.action(body)
+ new 1, nil, body
+ end
+ end
+ end
+end
View
10 lib/reak/bootstrap/ast/keyword_send.rb
@@ -11,19 +11,21 @@ def self.method_and_args(*pairs)
def self.bootstrap_grammar(g)
g.key_value_pair = g.seq(g.t(:identifier), ":", :sp, g.t(:primary), :sp) { |k,v| [k, v] }
g.keyword_send_args = g.many(:key_value_pair) { |*p| method_and_args(*p) }
- g.seq(receiver_rule, :sp, :keyword_send_args)
+ g.seq(receiver_rule, :sp, :keyword_send_args, g.maybe(:iter))
end
- def self.action(receiver, _, method_and_args)
- new(1, receiver, *method_and_args)
+ def self.action(receiver, _, method_and_args, iter)
+ method, args = method_and_args
+ new(1, receiver, method, args, *iter)
end
def self.receiver_rule
:primary
end
- def initialize(line, receiver, name, arguments)
+ def initialize(line, receiver, name, arguments, block = nil)
super line, receiver, Reak.smalltalk_prefix(name), nil, true
+ @block = block
@arguments.array.concat arguments
end
View
29 test/bootstrap/ast/iter_test.rb
@@ -0,0 +1,29 @@
+require File.expand_path('../../test_helper', __FILE__)
+MiniTest::Unit.autorun if $0 == __FILE__
+
+class ASTIterTest < MiniTest::Unit::TestCase
+ include LiteralTest
+ literal Reak::AST::Iter
+
+ module Something
+ @value = nil
+
+ def self.value
+ @value
+ end
+
+ def self.set_value(value)
+ @value = value
+ yield
+ end
+
+ Reak.smalltalk_expose singleton_class, 'set_value', 'setValue:'
+ end
+
+ parses "'foo' bar: 'baz' [ 'blah' ]"
+
+ evaluates("ASTIterTest.Something setValue: 'foo' [ 'ok' ]") do |return_value|
+ assert_equal "ok", return_value
+ assert_equal "foo", Something.value
+ end
+end

0 comments on commit 208c5ba

Please sign in to comment.
Something went wrong with that request. Please try again.