fixing Issue #328, parse error with indents and comments (StanAngeloff)

This commit is contained in:
Jeremy Ashkenas 2010-04-21 22:26:45 -04:00
parent bf2a5386f9
commit 01b4393fa7
3 changed files with 11 additions and 5 deletions

View File

@ -62,14 +62,16 @@
// correctly indented, or appear on a line of their own.
Rewriter.prototype.adjust_comments = function adjust_comments() {
return this.scan_tokens(__bind(function(prev, token, post, i) {
var after;
var _a, after, before;
if (!(token[0] === 'COMMENT')) {
return 1;
}
after = this.tokens[i + 2];
_a = [this.tokens[i - 2], this.tokens[i + 2]];
before = _a[0];
after = _a[1];
if (after && after[0] === 'INDENT') {
this.tokens.splice(i + 2, 1);
this.tokens.splice(i, 0, after);
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]]);

View File

@ -54,10 +54,13 @@ exports.Rewriter: class Rewriter
adjust_comments: ->
@scan_tokens (prev, token, post, i) =>
return 1 unless token[0] is 'COMMENT'
after: @tokens[i + 2]
[before, after]: [@tokens[i - 2], @tokens[i + 2]]
if after and after[0] is 'INDENT'
@tokens.splice i + 2, 1
@tokens.splice i, 0, after
if before and before[0] is 'OUTDENT' and post and prev[0] is post[0] is 'TERMINATOR'
@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]]

View File

@ -4,6 +4,7 @@ func: ->
false
false # comment
false
# comment
true