Skip to content
Permalink
Browse files

Started implementing block local variables.

  • Loading branch information
alex committed Jul 8, 2013
1 parent 0861fc0 commit ebaf04c62ded5a5fa7bf4843c2a0faeea4cc7b01
Showing with 20 additions and 13 deletions.
  1. +12 −0 tests/test_interpreter.py
  2. +5 −0 tests/test_parser.py
  3. +1 −1 topaz.mspec
  4. +2 −12 topaz/parser.py
@@ -1729,6 +1729,18 @@ def test_destructuring_arg_block(self, space):
None, None, None, None, None
]

def test_block_local_var(self, space):
w_res = space.execute("""
def f
yield
end
x = 3
f { |;x| x = 5 }
return x
""")
assert space.int_w(w_res) == 3


class TestExceptions(BaseTopazTest):
def test_simple(self, space):
@@ -1513,6 +1513,11 @@ def test_block(self, space):
]),
), 1))
]))
assert space.parse("f { |;x, y| }") == ast.Main(ast.Block([
ast.Statement(ast.Send(ast.Self(1), "f", [], ast.SendBlock(
[], None, None, ast.Nil(),
), 1))
]))

def test_lambda(self, space):
assert space.parse("->{}") == ast.Main(ast.Block([
@@ -32,7 +32,7 @@ class MSpecScript

language = [
"#{Rubyspec}/language",
# Block local variables: ``[].each {|a; b| }``
# Required block arg after *args: ``f {|*a, b| }``
"^#{Rubyspec}/language/block_spec.rb",
# Posix character class: ``/[[:alnum:]]/``
"^#{Rubyspec}/language/regexp/character_classes_spec.rb",
@@ -2009,12 +2009,7 @@ def opt_block_param(self, p):

@pg.production("block_param_def : PIPE opt_bv_decl PIPE")
def block_param_def_pipe_opt_bv_decl_pipe(self, p):
"""
tPIPE opt_bv_decl tPIPE {
$$ = support.new_args($1.getPosition(), null, null, null, null, null);
}
"""
raise NotImplementedError(p)
return self.new_args()

@pg.production("block_param_def : OROP")
def block_param_def_orop(self, p):
@@ -2042,12 +2037,7 @@ def bv_decls(self, p):

@pg.production("bvar : IDENTIFIER")
def bvar_identifier(self, p):
"""
tIDENTIFIER {
support.new_bv($1);
}
"""
raise NotImplementedError(p)
self.lexer.symtable.declare_local(p[0].getstr())

@pg.production("bvar : f_bad_arg")
def bvar_f_bad_arg(self, p):

0 comments on commit ebaf04c

Please sign in to comment.
You can’t perform that action at this time.