fixing block comments at the top of function blocks, and in other locations ... Issue #379

This commit is contained in:
Jeremy Ashkenas 2010-06-01 23:56:10 -04:00
parent 61d9bd7e5e
commit b3d1c238eb
4 changed files with 10 additions and 3 deletions

View File

@ -212,6 +212,7 @@
herecomment: true
});
this.token('HERECOMMENT', comment.split(MULTILINER));
this.token('TERMINATOR', '\n');
} else {
lines = compact(match[1].replace(COMMENT_CLEANER, '').split(MULTILINER));
i = this.tokens.length - 1;

View File

@ -1,5 +1,5 @@
(function(){
var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, helpers, include, pair;
var BALANCED_PAIRS, COMMENTS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, Rewriter, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, helpers, include, pair;
var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
return function() {
return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
@ -65,7 +65,7 @@
Rewriter.prototype.adjust_comments = function() {
return this.scan_tokens(__bind(function(prev, token, post, i) {
var _c, after, before;
if (!(token[0] === 'COMMENT')) {
if (!(include(COMMENTS, token[0]))) {
return 1;
}
_c = [this.tokens[i - 2], this.tokens[i + 2]];
@ -392,4 +392,6 @@
// The grammar can't disambiguate them, so we insert the implicit indentation.
SINGLE_LINERS = ['ELSE', "->", "=>", 'TRY', 'FINALLY', 'THEN'];
SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN'];
// Comment flavors.
COMMENTS = ['COMMENT', 'HERECOMMENT'];
})();

View File

@ -141,6 +141,7 @@ exports.Lexer: class Lexer
if match[3]
comment: @sanitize_heredoc match[3], {herecomment: true}
@token 'HERECOMMENT', comment.split MULTILINER
@token 'TERMINATOR', '\n'
else
lines: compact match[1].replace(COMMENT_CLEANER, '').split MULTILINER
i: @tokens.length - 1

View File

@ -53,7 +53,7 @@ exports.Rewriter: class Rewriter
# correctly indented, or appear on a line of their own.
adjust_comments: ->
@scan_tokens (prev, token, post, i) =>
return 1 unless token[0] is 'COMMENT'
return 1 unless include COMMENTS, token[0]
[before, after]: [@tokens[i - 2], @tokens[i + 2]]
if after and after[0] is 'INDENT'
@tokens.splice i + 2, 1
@ -292,3 +292,6 @@ IMPLICIT_END: ['IF', 'UNLESS', 'FOR', 'WHILE', 'UNTIL', 'TERMINATOR', 'INDENT'
# The grammar can't disambiguate them, so we insert the implicit indentation.
SINGLE_LINERS: ['ELSE', "->", "=>", 'TRY', 'FINALLY', 'THEN']
SINGLE_CLOSERS: ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN']
# Comment flavors.
COMMENTS: ['COMMENT', 'HERECOMMENT']