lexer: fixed broken logics (due to f051d088
) and a snakecased variable
This commit is contained in:
parent
3fd7f9efdd
commit
9a3b736174
20
lib/lexer.js
20
lib/lexer.js
|
@ -35,29 +35,31 @@
|
|||
return this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
||||
};
|
||||
Lexer.prototype.identifierToken = function() {
|
||||
var close_index, forcedIdentifier, id, tag;
|
||||
var closeIndex, forcedIdentifier, id, tag;
|
||||
if (!(id = this.match(IDENTIFIER))) {
|
||||
return false;
|
||||
}
|
||||
this.i += id.length;
|
||||
if (id === 'all' && this.tag() === 'FOR') {
|
||||
this.token('ALL', id);
|
||||
return true;
|
||||
}
|
||||
forcedIdentifier = this.tagAccessor() || this.match(ASSIGNED, 1);
|
||||
tag = 'IDENTIFIER';
|
||||
if (include(JS_KEYWORDS, id) || !forcedIdentifier && include(COFFEE_KEYWORDS, id)) {
|
||||
tag = id.toUpperCase();
|
||||
if (tag === 'WHEN' && include(LINE_BREAK, this.tag())) {
|
||||
tag = 'LEADING_WHEN';
|
||||
}
|
||||
} else if (id === 'all' && this.tag() === 'FOR') {
|
||||
tag = 'ALL';
|
||||
}
|
||||
if (include(UNARY, tag)) {
|
||||
} else if (include(UNARY, tag)) {
|
||||
tag = 'UNARY';
|
||||
} else if (include(JS_FORBIDDEN, id)) {
|
||||
}
|
||||
}
|
||||
if (include(JS_FORBIDDEN, id)) {
|
||||
if (forcedIdentifier) {
|
||||
tag = 'STRING';
|
||||
id = ("\"" + (id) + "\"");
|
||||
if (forcedIdentifier === 'accessor') {
|
||||
close_index = true;
|
||||
closeIndex = true;
|
||||
if (this.tag() !== '@') {
|
||||
this.tokens.pop();
|
||||
}
|
||||
|
@ -78,7 +80,7 @@
|
|||
}
|
||||
}
|
||||
this.token(tag, id);
|
||||
if (close_index) {
|
||||
if (closeIndex) {
|
||||
this.token(']', ']');
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -76,22 +76,24 @@ exports.Lexer = class Lexer
|
|||
identifierToken: ->
|
||||
return false unless id = @match IDENTIFIER
|
||||
@i += id.length
|
||||
if id is 'all' and @tag() is 'FOR'
|
||||
@token 'ALL', id
|
||||
return true
|
||||
forcedIdentifier = @tagAccessor() or @match ASSIGNED, 1
|
||||
tag = 'IDENTIFIER'
|
||||
if include(JS_KEYWORDS, id) or
|
||||
not forcedIdentifier and include(COFFEE_KEYWORDS, id)
|
||||
tag = id.toUpperCase()
|
||||
tag = 'LEADING_WHEN' if tag is 'WHEN' and include LINE_BREAK, @tag()
|
||||
else if id is 'all' and @tag() is 'FOR'
|
||||
tag = 'ALL'
|
||||
if include UNARY, tag
|
||||
if tag is 'WHEN' and include LINE_BREAK, @tag()
|
||||
tag = 'LEADING_WHEN'
|
||||
else if include UNARY, tag
|
||||
tag = 'UNARY'
|
||||
else if include JS_FORBIDDEN, id
|
||||
if include JS_FORBIDDEN, id
|
||||
if forcedIdentifier
|
||||
tag = 'STRING'
|
||||
id = "\"#{id}\""
|
||||
if forcedIdentifier is 'accessor'
|
||||
close_index = true
|
||||
closeIndex = on
|
||||
@tokens.pop() if @tag() isnt '@'
|
||||
@token 'INDEX_START', '['
|
||||
else if include(RESERVED, id)
|
||||
|
@ -103,7 +105,7 @@ exports.Lexer = class Lexer
|
|||
else if include LOGIC, id
|
||||
tag = 'LOGIC'
|
||||
@token tag, id
|
||||
@token ']', ']' if close_index
|
||||
@token ']', ']' if closeIndex
|
||||
true
|
||||
|
||||
# Matches numbers, including decimals, hex, and exponential notation.
|
||||
|
|
Loading…
Reference in New Issue