Adding kamatsu's proposed block literal syntax

This commit is contained in:
Jeremy Ashkenas
2010-01-03 10:19:39 -05:00
parent 7eff8786bc
commit 21a0cc83ae
2 changed files with 15 additions and 2 deletions

View File

@@ -17,6 +17,9 @@ token COMMENT
token JS token JS
token INDENT OUTDENT token INDENT OUTDENT
# We expect one shift-reduce conflict. Because of the lexer, it will never occur.
expect 1
# Declare order of operations. # Declare order of operations.
prechigh prechigh
nonassoc UMINUS SPLAT NOT '!' '!!' '~' '++' '--' '?' nonassoc UMINUS SPLAT NOT '!' '!!' '~' '++' '--' '?'
@@ -260,8 +263,14 @@ rule
# A generic function invocation. # A generic function invocation.
Invocation: Invocation:
Value "(" ArgList ")" { result = CallNode.new(val[0], val[2]) } Value Arguments { result = CallNode.new(val[0], val[1]) }
| Invocation "(" ArgList ")" { result = CallNode.new(val[0], val[2]) } | Invocation Arguments { result = CallNode.new(val[0], val[1]) }
# | Invocation Code { result = val[0] << val[1] }
;
Arguments:
"(" ArgList ")" { result = val[1] }
| "(" ArgList ")" Code { result = val[1] << val[3] }
; ;
# Calling super. # Calling super.

View File

@@ -220,6 +220,10 @@ module CoffeeScript
@arguments.any? {|a| a.is_a?(ArgSplatNode) } @arguments.any? {|a| a.is_a?(ArgSplatNode) }
end end
def <<(argument)
@arguments << argument
end
def compile(o={}) def compile(o={})
o = super(o) o = super(o)
return write(compile_splat(o)) if splat? return write(compile_splat(o)) if splat?