removing special rule from rewriter for naked functions in arrays

This commit is contained in:
Jeremy Ashkenas 2010-03-02 00:43:01 -05:00
parent cd6dd5abfd
commit c219adffd5
6 changed files with 10 additions and 6 deletions

View File

@ -85,7 +85,7 @@
// The remainder of the source code.
this.i = 0;
// Current character position we're parsing.
this.line = 1;
this.line = 0;
// The current line.
this.indent = 0;
// The current indent level.

View File

@ -252,7 +252,7 @@
idx += 1;
tok = this.tokens[idx];
pre = this.tokens[idx - 1];
if ((!tok || (SINGLE_CLOSERS.indexOf(tok[0]) >= 0 && tok[1] !== ';') || (pre[0] === ',' && tok[0] === 'PARAM_START') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) {
if ((!tok || (SINGLE_CLOSERS.indexOf(tok[0]) >= 0 && tok[1] !== ';') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) {
insertion = pre[0] === "," ? idx - 1 : idx;
this.tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]]);
break;

View File

@ -115,7 +115,7 @@ exports.Lexer: class Lexer
tokenize: (code) ->
@code : code # The remainder of the source code.
@i : 0 # Current character position we're parsing.
@line : 1 # The current line.
@line : 0 # The current line.
@indent : 0 # The current indent level.
@indents : [] # The stack of all indent levels we are currently within.
@tokens : [] # Collection of all parsed tokens in the form ['TOKEN_TYPE', value, line]

View File

@ -180,7 +180,6 @@ exports.Rewriter: class Rewriter
pre: @tokens[idx - 1]
if (not tok or
(SINGLE_CLOSERS.indexOf(tok[0]) >= 0 and tok[1] isnt ';') or
(pre[0] is ',' and tok[0] is 'PARAM_START') or
(tok[0] is ')' && parens is 0)) and
not (starter is 'ELSE' and tok[0] is 'ELSE')
insertion: if pre[0] is "," then idx - 1 else idx

View File

@ -14,6 +14,11 @@ ok y.x.name is 'x'
() ->
# Multiple nested function declarations mixed with implicit calls should not
# cause a syntax error.
(one) -> (two) -> three four, (five) -> six seven, eight, (nine) ->
obj: {
name: "Fred"
@ -70,7 +75,7 @@ ok result is 10
# And even with strange things like this:
funcs: [(x) -> x, (x) -> x * x]
funcs: [((x) -> x), ((x) -> x * x)]
result: funcs[1] 5
ok result is 25

View File

@ -1,4 +1,4 @@
a: [(x) -> x, (x) -> x * x]
a: [((x) -> x), ((x) -> x * x)]
ok a.length is 2