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();
|
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() {
|
Lexer.prototype.identifierToken = function() {
|
||||||
var close_index, forcedIdentifier, id, tag;
|
var closeIndex, forcedIdentifier, id, tag;
|
||||||
if (!(id = this.match(IDENTIFIER))) {
|
if (!(id = this.match(IDENTIFIER))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.i += id.length;
|
this.i += id.length;
|
||||||
|
if (id === 'all' && this.tag() === 'FOR') {
|
||||||
|
this.token('ALL', id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
forcedIdentifier = this.tagAccessor() || this.match(ASSIGNED, 1);
|
forcedIdentifier = this.tagAccessor() || this.match(ASSIGNED, 1);
|
||||||
tag = 'IDENTIFIER';
|
tag = 'IDENTIFIER';
|
||||||
if (include(JS_KEYWORDS, id) || !forcedIdentifier && include(COFFEE_KEYWORDS, id)) {
|
if (include(JS_KEYWORDS, id) || !forcedIdentifier && include(COFFEE_KEYWORDS, id)) {
|
||||||
tag = id.toUpperCase();
|
tag = id.toUpperCase();
|
||||||
if (tag === 'WHEN' && include(LINE_BREAK, this.tag())) {
|
if (tag === 'WHEN' && include(LINE_BREAK, this.tag())) {
|
||||||
tag = 'LEADING_WHEN';
|
tag = 'LEADING_WHEN';
|
||||||
}
|
} else if (include(UNARY, tag)) {
|
||||||
} else if (id === 'all' && this.tag() === 'FOR') {
|
|
||||||
tag = 'ALL';
|
|
||||||
}
|
|
||||||
if (include(UNARY, tag)) {
|
|
||||||
tag = 'UNARY';
|
tag = 'UNARY';
|
||||||
} else if (include(JS_FORBIDDEN, id)) {
|
}
|
||||||
|
}
|
||||||
|
if (include(JS_FORBIDDEN, id)) {
|
||||||
if (forcedIdentifier) {
|
if (forcedIdentifier) {
|
||||||
tag = 'STRING';
|
tag = 'STRING';
|
||||||
id = ("\"" + (id) + "\"");
|
id = ("\"" + (id) + "\"");
|
||||||
if (forcedIdentifier === 'accessor') {
|
if (forcedIdentifier === 'accessor') {
|
||||||
close_index = true;
|
closeIndex = true;
|
||||||
if (this.tag() !== '@') {
|
if (this.tag() !== '@') {
|
||||||
this.tokens.pop();
|
this.tokens.pop();
|
||||||
}
|
}
|
||||||
|
@ -78,7 +80,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.token(tag, id);
|
this.token(tag, id);
|
||||||
if (close_index) {
|
if (closeIndex) {
|
||||||
this.token(']', ']');
|
this.token(']', ']');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -76,22 +76,24 @@ exports.Lexer = class Lexer
|
||||||
identifierToken: ->
|
identifierToken: ->
|
||||||
return false unless id = @match IDENTIFIER
|
return false unless id = @match IDENTIFIER
|
||||||
@i += id.length
|
@i += id.length
|
||||||
|
if id is 'all' and @tag() is 'FOR'
|
||||||
|
@token 'ALL', id
|
||||||
|
return true
|
||||||
forcedIdentifier = @tagAccessor() or @match ASSIGNED, 1
|
forcedIdentifier = @tagAccessor() or @match ASSIGNED, 1
|
||||||
tag = 'IDENTIFIER'
|
tag = 'IDENTIFIER'
|
||||||
if include(JS_KEYWORDS, id) or
|
if include(JS_KEYWORDS, id) or
|
||||||
not forcedIdentifier and include(COFFEE_KEYWORDS, id)
|
not forcedIdentifier and include(COFFEE_KEYWORDS, id)
|
||||||
tag = id.toUpperCase()
|
tag = id.toUpperCase()
|
||||||
tag = 'LEADING_WHEN' if tag is 'WHEN' and include LINE_BREAK, @tag()
|
if tag is 'WHEN' and include LINE_BREAK, @tag()
|
||||||
else if id is 'all' and @tag() is 'FOR'
|
tag = 'LEADING_WHEN'
|
||||||
tag = 'ALL'
|
else if include UNARY, tag
|
||||||
if include UNARY, tag
|
|
||||||
tag = 'UNARY'
|
tag = 'UNARY'
|
||||||
else if include JS_FORBIDDEN, id
|
if include JS_FORBIDDEN, id
|
||||||
if forcedIdentifier
|
if forcedIdentifier
|
||||||
tag = 'STRING'
|
tag = 'STRING'
|
||||||
id = "\"#{id}\""
|
id = "\"#{id}\""
|
||||||
if forcedIdentifier is 'accessor'
|
if forcedIdentifier is 'accessor'
|
||||||
close_index = true
|
closeIndex = on
|
||||||
@tokens.pop() if @tag() isnt '@'
|
@tokens.pop() if @tag() isnt '@'
|
||||||
@token 'INDEX_START', '['
|
@token 'INDEX_START', '['
|
||||||
else if include(RESERVED, id)
|
else if include(RESERVED, id)
|
||||||
|
@ -103,7 +105,7 @@ exports.Lexer = class Lexer
|
||||||
else if include LOGIC, id
|
else if include LOGIC, id
|
||||||
tag = 'LOGIC'
|
tag = 'LOGIC'
|
||||||
@token tag, id
|
@token tag, id
|
||||||
@token ']', ']' if close_index
|
@token ']', ']' if closeIndex
|
||||||
true
|
true
|
||||||
|
|
||||||
# Matches numbers, including decimals, hex, and exponential notation.
|
# Matches numbers, including decimals, hex, and exponential notation.
|
||||||
|
|
Loading…
Reference in New Issue