diff --git a/parser/parser.go b/parser/parser.go index faca900..af5bc03 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -207,6 +207,7 @@ func (p *parser) init(fset *gotoken.FileSet, filename string, src []byte, mode M p.registerInfix(token.INT, p.parseCallArgument) p.registerInfix(token.STRING, p.parseCallArgument) p.registerInfix(token.SYMBEG, p.parseCallArgument) + p.registerInfix(token.CAPTURE, p.parseCallArgument) p.registerInfix(token.SELF, p.parseCallArgument) p.registerInfix(token.LBRACE, p.parseCallBlock) p.registerInfix(token.DO, p.parseCallBlock) diff --git a/parser/parser_test.go b/parser/parser_test.go index 43ee0b0..3f7dd48 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -98,6 +98,31 @@ func TestBlockCapture(t *testing.T) { }, }, }, + { + desc: "block capture as arg on call in func body", + input: ` + def foo + each &block + end`, + result: &ast.FunctionLiteral{ + Name: &ast.Identifier{Value: "foo"}, + Parameters: []*ast.FunctionParameter{}, + Body: &ast.BlockStatement{ + Statements: []ast.Statement{ + &ast.ExpressionStatement{ + Expression: &ast.ContextCallExpression{ + Function: &ast.Identifier{Value: "each"}, + Arguments: []ast.Expression{ + &ast.BlockCapture{ + Name: &ast.Identifier{Value: "block"}, + }, + }, + }, + }, + }, + }, + }, + }, } for _, tt := range tests {