Marking indentation tokens generated with helper.

This commit is contained in:
clutchski
2011-12-17 18:40:50 -05:00
parent f6dbaa7c31
commit cdd3c13ce9
2 changed files with 20 additions and 11 deletions

View File

@@ -203,7 +203,7 @@
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
};
return this.scanTokens(function(token, i, tokens) {
var tag, _ref, _ref2;
var implicit, tag, _ref, _ref2;
tag = token[0];
if (tag === 'TERMINATOR' && this.tag(i + 1) === 'THEN') {
tokens.splice(i, 1);
@@ -219,10 +219,8 @@
}
if (__indexOf.call(SINGLE_LINERS, tag) >= 0 && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
starter = tag;
_ref2 = this.indentation(token), indent = _ref2[0], outdent = _ref2[1];
_ref2 = this.indentation(token, implicit = true), indent = _ref2[0], outdent = _ref2[1];
if (starter === 'THEN') indent.fromThen = true;
this.generated(indent);
this.generated(outdent);
tokens.splice(i + 1, 0, indent);
this.detectEnd(i + 2, condition, action);
if (tag === 'THEN') tokens.splice(i, 1);
@@ -250,8 +248,20 @@
});
};
Rewriter.prototype.indentation = function(token) {
return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]];
Rewriter.prototype.indentation = function(token, implicit) {
var t, tokens, _i, _len, _results;
if (implicit == null) implicit = false;
tokens = [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]];
if (implicit) {
_results = [];
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
t = tokens[_i];
_results.push(this.generated(t));
}
return _results;
} else {
return tokens;
}
};
Rewriter.prototype.tag = function(i) {

View File

@@ -213,10 +213,8 @@ class exports.Rewriter
if tag in SINGLE_LINERS and @tag(i + 1) isnt 'INDENT' and
not (tag is 'ELSE' and @tag(i + 1) is 'IF')
starter = tag
[indent, outdent] = @indentation token
[indent, outdent] = @indentation token, implicit=true
indent.fromThen = true if starter is 'THEN'
@generated(indent)
@generated(outdent)
tokens.splice i + 1, 0, indent
@detectEnd i + 2, condition, action
tokens.splice i, 1 if tag is 'THEN'
@@ -242,8 +240,9 @@ class exports.Rewriter
1
# Generate the indentation tokens, based on another token on the same line.
indentation: (token) ->
[['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]]
indentation: (token, implicit=false) ->
tokens = [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]]
if implicit then (@generated(t) for t in tokens) else tokens
# Look up a tag by token index.
tag: (i) -> @tokens[i]?[0]