adding a block test and using PARAM_SPLAT to remove the last shift/reduce conflict

This commit is contained in:
Jeremy Ashkenas 2010-01-03 10:46:37 -05:00
parent 21a0cc83ae
commit ba3c5298f7
3 changed files with 9 additions and 7 deletions

View File

@ -5,7 +5,7 @@ token IF ELSE UNLESS
token NUMBER STRING REGEX
token TRUE FALSE YES NO ON OFF
token IDENTIFIER PROPERTY_ACCESS
token CODE PARAM NEW RETURN
token CODE PARAM PARAM_SPLAT NEW RETURN
token TRY CATCH FINALLY THROW
token BREAK CONTINUE
token FOR IN BY WHILE
@ -17,12 +17,9 @@ token COMMENT
token JS
token INDENT OUTDENT
# We expect one shift-reduce conflict. Because of the lexer, it will never occur.
expect 1
# Declare order of operations.
prechigh
nonassoc UMINUS SPLAT NOT '!' '!!' '~' '++' '--' '?'
nonassoc UMINUS PARAM_SPLAT SPLAT NOT '!' '!!' '~' '++' '--' '?'
left '*' '/' '%'
left '+' '-'
left '<<' '>>' '>>>'
@ -203,7 +200,7 @@ rule
Param:
PARAM
| '*' PARAM = SPLAT { result = ParamSplatNode.new(val[1]) }
| PARAM_SPLAT PARAM { result = ParamSplatNode.new(val[1]) }
;
Splat:

View File

@ -219,7 +219,8 @@ module CoffeeScript
i -= 1
tok = @tokens[i]
return if !tok
next if ['*', ','].include?(tok[0])
next if tok[0] == ','
next tok[0] = :PARAM_SPLAT if tok[0] == '*'
return if tok[0] != :IDENTIFIER
tok[0] = :PARAM
end

View File

@ -0,0 +1,4 @@
results: [1, 2, 3].map() x =>
x * x
print(results.join(' ') is '1 4 9')