Skip to content

Commit 5aee41a

Browse files
committed
rubyish - added 1.9 '->' lambda syntax
1 parent a8d0acb commit 5aee41a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

examples/rubyish/rubyish.nqp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ grammar Rubyish::Grammar is HLL::Grammar {
224224
# Operators - mostly stolen from NQP
225225
token infix:sym<**> { <sym> <O('%exponentiation, :op<pow_n>')> }
226226

227-
token prefix:sym<-> { <sym> <O('%unary, :op<neg_n>')> }
227+
token prefix:sym<-> { <sym><![>]> <O('%unary, :op<neg_n>')> }
228228
token prefix:sym<!> { <sym> <O('%unary, :op<not_i>')> }
229229

230230
token infix:sym<*> { <sym> <O('%multiplicative, :op<mul_n>')> }
@@ -324,6 +324,7 @@ grammar Rubyish::Grammar is HLL::Grammar {
324324

325325
token term:sym<lambda> {
326326
'lambda' :s ['{' ['|' ~ '|' <signature>]? ] ~ '}' <stmtlist>
327+
| '->' :s ['(' ~ ')' <signature> :s]? '{' ~ '}' <stmtlist>
327328
}
328329

329330
method builtin-init() {

examples/rubyish/t/lamba.t

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
puts "1..5"
1+
puts "1..7"
22
def make_iterator(n)
33
lambda { |incr,desc| n += incr; puts "ok #{n} - #{desc}"}
44
end
@@ -12,3 +12,9 @@ it2.call(0,"iterator 2")
1212
it2.call(1,"iterator 2")
1313
it1.call(3,"iterator 1")
1414

15+
# Ruby 1.9+ style lambda syntax
16+
17+
m = 5
18+
test = ->(desc) {puts "ok #{m+=1} - #{desc}"}
19+
test.call("new lamba syntax");
20+
test.call("new lamba syntax");

0 commit comments

Comments
 (0)