Unsatisfactory patch that fixes Issue #394 ... comments that prefix spaced out if/else clauses.

This commit is contained in:
Jeremy Ashkenas
2010-06-12 17:41:46 -04:00
parent 969740a263
commit d9071a80a0
3 changed files with 25 additions and 7 deletions

View File

@@ -71,13 +71,13 @@
if (after && after[0] === 'INDENT') {
this.tokens.splice(i + 2, 1);
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after);
return 1;
} else if (prev && prev[0] !== 'TERMINATOR' && prev[0] !== 'INDENT' && prev[0] !== 'OUTDENT') {
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
return 2;
} else {
return 1;
} else if (before && before[0] === 'OUTDENT' && prev && prev[0] === 'TERMINATOR' && post && post[0] === 'TERMINATOR' && after && after[0] === 'ELSE') {
this.tokens.splice(i + 1, 0, this.tokens.splice(i - 2, 1)[0]);
}
return 1;
};
return (function() {
return __func.apply(__this, arguments);

View File

@@ -61,12 +61,15 @@ exports.Rewriter: class Rewriter
@tokens.splice i - 2, 1
else
@tokens.splice i, 0, after
return 1
else if prev and prev[0] isnt 'TERMINATOR' and prev[0] isnt 'INDENT' and prev[0] isnt 'OUTDENT'
@tokens.splice i, 0, ['TERMINATOR', "\n", prev[2]]
return 2
else
return 1
else if before and before[0] is 'OUTDENT' and
prev and prev[0] is 'TERMINATOR' and
post and post[0] is 'TERMINATOR' and
after and after[0] is 'ELSE'
@tokens.splice i + 1, 0, @tokens.splice(i - 2, 1)[0]
return 1
# Leading newlines would introduce an ambiguity in the grammar, so we
# dispatch them here.

View File

@@ -64,4 +64,19 @@ func: ->
###
Another block comment.
###
code
code
# Spaced comments in if / elses.
result: if false
1
# comment
else if false
2
# comment
else
3
ok result is 3