mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Add location data to tokens generated by the rewriter.
This commit is contained in:
parent
bb94e02fad
commit
12625cc00c
2 changed files with 47 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
||||||
this.tagPostfixConditionals();
|
this.tagPostfixConditionals();
|
||||||
this.addImplicitBraces();
|
this.addImplicitBraces();
|
||||||
this.addImplicitParentheses();
|
this.addImplicitParentheses();
|
||||||
|
this.addLocationDataToGeneratedTokens();
|
||||||
return this.tokens;
|
return this.tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -221,6 +222,31 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Rewriter.prototype.addLocationDataToGeneratedTokens = function() {
|
||||||
|
return this.scanTokens(function(token, i, tokens) {
|
||||||
|
var prevToken;
|
||||||
|
if (token.generated && !token.locationData) {
|
||||||
|
if (i > 0) {
|
||||||
|
prevToken = tokens[i - 1];
|
||||||
|
token.locationData = {
|
||||||
|
first_line: prevToken.locationData.last_line,
|
||||||
|
first_column: prevToken.locationData.last_column,
|
||||||
|
last_line: prevToken.locationData.last_line,
|
||||||
|
last_column: prevToken.locationData.last_column
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
token.locationData = {
|
||||||
|
first_line: 0,
|
||||||
|
first_column: 0,
|
||||||
|
last_line: 0,
|
||||||
|
last_column: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Rewriter.prototype.addImplicitIndentation = function() {
|
Rewriter.prototype.addImplicitIndentation = function() {
|
||||||
var action, condition, indent, outdent, starter;
|
var action, condition, indent, outdent, starter;
|
||||||
starter = indent = outdent = null;
|
starter = indent = outdent = null;
|
||||||
|
|
|
@ -26,6 +26,7 @@ class exports.Rewriter
|
||||||
@tagPostfixConditionals()
|
@tagPostfixConditionals()
|
||||||
@addImplicitBraces()
|
@addImplicitBraces()
|
||||||
@addImplicitParentheses()
|
@addImplicitParentheses()
|
||||||
|
@addLocationDataToGeneratedTokens()
|
||||||
@tokens
|
@tokens
|
||||||
|
|
||||||
# Rewrite the token stream, looking one token ahead and behind.
|
# Rewrite the token stream, looking one token ahead and behind.
|
||||||
|
@ -190,6 +191,25 @@ class exports.Rewriter
|
||||||
prev[0] = 'FUNC_EXIST' if prev[0] is '?'
|
prev[0] = 'FUNC_EXIST' if prev[0] is '?'
|
||||||
2
|
2
|
||||||
|
|
||||||
|
# Add location data to all tokens generated by the rewriter.
|
||||||
|
addLocationDataToGeneratedTokens: ->
|
||||||
|
@scanTokens (token, i, tokens) ->
|
||||||
|
if token.generated and not token.locationData
|
||||||
|
if i > 0
|
||||||
|
prevToken = tokens[i-1]
|
||||||
|
token.locationData =
|
||||||
|
first_line: prevToken.locationData.last_line
|
||||||
|
first_column: prevToken.locationData.last_column
|
||||||
|
last_line: prevToken.locationData.last_line
|
||||||
|
last_column: prevToken.locationData.last_column
|
||||||
|
else
|
||||||
|
token.locationData =
|
||||||
|
first_line: 0
|
||||||
|
first_column: 0
|
||||||
|
last_line: 0
|
||||||
|
last_column: 0
|
||||||
|
return 1
|
||||||
|
|
||||||
# Because our grammar is LALR(1), it can't handle some single-line
|
# Because our grammar is LALR(1), it can't handle some single-line
|
||||||
# expressions that lack ending delimiters. The **Rewriter** adds the implicit
|
# expressions that lack ending delimiters. The **Rewriter** adds the implicit
|
||||||
# blocks, so it doesn't need to. ')' can close a single-line block,
|
# blocks, so it doesn't need to. ')' can close a single-line block,
|
||||||
|
|
Loading…
Add table
Reference in a new issue