mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
fixing issue #745 ... precedence of huh operator.
This commit is contained in:
parent
4f486bc444
commit
b21057d166
6 changed files with 29 additions and 37 deletions
|
@ -567,8 +567,6 @@
|
||||||
return new Op('--', $1, null, true);
|
return new Op('--', $1, null, true);
|
||||||
}), o("Expression ++", function() {
|
}), o("Expression ++", function() {
|
||||||
return new Op('++', $1, null, true);
|
return new Op('++', $1, null, true);
|
||||||
}), o("Expression ? Expression", function() {
|
|
||||||
return new Op('?', $1, $3);
|
|
||||||
}), o("Expression + Expression", function() {
|
}), o("Expression + Expression", function() {
|
||||||
return new Op('+', $1, $3);
|
return new Op('+', $1, $3);
|
||||||
}), o("Expression - Expression", function() {
|
}), o("Expression - Expression", function() {
|
||||||
|
@ -594,7 +592,7 @@
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
operators = [["right", '?'], ["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'RELATION'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'RELATION'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||||
tokens = [];
|
tokens = [];
|
||||||
for (name in grammar) {
|
for (name in grammar) {
|
||||||
if (!__hasProp.call(grammar, name)) continue;
|
if (!__hasProp.call(grammar, name)) continue;
|
||||||
|
|
19
lib/lexer.js
19
lib/lexer.js
|
@ -313,7 +313,7 @@
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.literalToken = function() {
|
Lexer.prototype.literalToken = function() {
|
||||||
var match, prev, ptag, pval, tag, value;
|
var _ref2, match, prev, tag, value;
|
||||||
if (match = OPERATOR.exec(this.chunk)) {
|
if (match = OPERATOR.exec(this.chunk)) {
|
||||||
value = match[0];
|
value = match[0];
|
||||||
if (CODE.test(value)) {
|
if (CODE.test(value)) {
|
||||||
|
@ -324,15 +324,14 @@
|
||||||
}
|
}
|
||||||
this.i += value.length;
|
this.i += value.length;
|
||||||
tag = value;
|
tag = value;
|
||||||
|
prev = last(this.tokens);
|
||||||
if (value === '=') {
|
if (value === '=') {
|
||||||
pval = this.value();
|
if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
|
||||||
if (!pval.reserved && include(JS_FORBIDDEN, pval)) {
|
|
||||||
this.assignmentError();
|
this.assignmentError();
|
||||||
}
|
}
|
||||||
if (('or' === pval || 'and' === pval)) {
|
if (('or' === (_ref2 = prev[1]) || 'and' === _ref2)) {
|
||||||
prev = last(this.tokens);
|
|
||||||
prev[0] = 'COMPOUND_ASSIGN';
|
prev[0] = 'COMPOUND_ASSIGN';
|
||||||
prev[1] = COFFEE_ALIASES[pval] + '=';
|
prev[1] = COFFEE_ALIASES[prev[1]] + '=';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,15 +349,17 @@
|
||||||
tag = 'UNARY';
|
tag = 'UNARY';
|
||||||
} else if (include(SHIFT, value)) {
|
} else if (include(SHIFT, value)) {
|
||||||
tag = 'SHIFT';
|
tag = 'SHIFT';
|
||||||
} else if ((prev = last(this.tokens)) && !prev.spaced && include(CALLABLE, ptag = prev[0])) {
|
} else if (value === '?' && prev.spaced) {
|
||||||
|
tag = 'LOGIC';
|
||||||
|
} else if (prev && !prev.spaced && include(CALLABLE, prev[0])) {
|
||||||
if (value === '(') {
|
if (value === '(') {
|
||||||
if (ptag === '?') {
|
if (prev[0] === '?') {
|
||||||
prev[0] = 'FUNC_EXIST';
|
prev[0] = 'FUNC_EXIST';
|
||||||
}
|
}
|
||||||
tag = 'CALL_START';
|
tag = 'CALL_START';
|
||||||
} else if (value === '[') {
|
} else if (value === '[') {
|
||||||
tag = 'INDEX_START';
|
tag = 'INDEX_START';
|
||||||
switch (ptag) {
|
switch (prev[0]) {
|
||||||
case '?':
|
case '?':
|
||||||
prev[0] = 'INDEX_SOAK';
|
prev[0] = 'INDEX_SOAK';
|
||||||
break;
|
break;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -535,7 +535,6 @@ grammar =
|
||||||
o "Expression --", -> new Op '--', $1, null, true
|
o "Expression --", -> new Op '--', $1, null, true
|
||||||
o "Expression ++", -> new Op '++', $1, null, true
|
o "Expression ++", -> new Op '++', $1, null, true
|
||||||
|
|
||||||
o "Expression ? Expression", -> new Op '?', $1, $3
|
|
||||||
o "Expression + Expression", -> new Op '+', $1, $3
|
o "Expression + Expression", -> new Op '+', $1, $3
|
||||||
o "Expression - Expression", -> new Op '-', $1, $3
|
o "Expression - Expression", -> new Op '-', $1, $3
|
||||||
o "Expression == Expression", -> new Op '==', $1, $3
|
o "Expression == Expression", -> new Op '==', $1, $3
|
||||||
|
@ -571,9 +570,9 @@ grammar =
|
||||||
#
|
#
|
||||||
# (2 + 3) * 4
|
# (2 + 3) * 4
|
||||||
operators = [
|
operators = [
|
||||||
["right", '?']
|
|
||||||
["left", 'CALL_START', 'CALL_END']
|
["left", 'CALL_START', 'CALL_END']
|
||||||
["nonassoc", '++', '--']
|
["nonassoc", '++', '--']
|
||||||
|
["left", '?']
|
||||||
["right", 'UNARY']
|
["right", 'UNARY']
|
||||||
["left", 'MATH']
|
["left", 'MATH']
|
||||||
["left", '+', '-']
|
["left", '+', '-']
|
||||||
|
|
|
@ -307,13 +307,12 @@ exports.Lexer = class Lexer
|
||||||
value = @chunk.charAt 0
|
value = @chunk.charAt 0
|
||||||
@i += value.length
|
@i += value.length
|
||||||
tag = value
|
tag = value
|
||||||
|
prev = last @tokens
|
||||||
if value is '='
|
if value is '='
|
||||||
pval = @value()
|
@assignmentError() if not prev[1].reserved and include JS_FORBIDDEN, prev[1]
|
||||||
@assignmentError() if not pval.reserved and include JS_FORBIDDEN, pval
|
if prev[1] in ['or', 'and']
|
||||||
if pval in ['or', 'and']
|
|
||||||
prev = last @tokens
|
|
||||||
prev[0] = 'COMPOUND_ASSIGN'
|
prev[0] = 'COMPOUND_ASSIGN'
|
||||||
prev[1] = COFFEE_ALIASES[pval] + '='
|
prev[1] = COFFEE_ALIASES[prev[1]] + '='
|
||||||
return true
|
return true
|
||||||
if ';' is value then tag = 'TERMINATOR'
|
if ';' is value then tag = 'TERMINATOR'
|
||||||
else if include LOGIC , value then tag = 'LOGIC'
|
else if include LOGIC , value then tag = 'LOGIC'
|
||||||
|
@ -322,14 +321,14 @@ exports.Lexer = class Lexer
|
||||||
else if include COMPOUND_ASSIGN, value then tag = 'COMPOUND_ASSIGN'
|
else if include COMPOUND_ASSIGN, value then tag = 'COMPOUND_ASSIGN'
|
||||||
else if include UNARY , value then tag = 'UNARY'
|
else if include UNARY , value then tag = 'UNARY'
|
||||||
else if include SHIFT , value then tag = 'SHIFT'
|
else if include SHIFT , value then tag = 'SHIFT'
|
||||||
else if (prev = last @tokens) and not prev.spaced and
|
else if value is '?' and prev.spaced then tag = 'LOGIC'
|
||||||
include(CALLABLE, ptag = prev[0])
|
else if prev and not prev.spaced and include CALLABLE, prev[0]
|
||||||
if value is '('
|
if value is '('
|
||||||
prev[0] = 'FUNC_EXIST' if ptag is '?'
|
prev[0] = 'FUNC_EXIST' if prev[0] is '?'
|
||||||
tag = 'CALL_START'
|
tag = 'CALL_START'
|
||||||
else if value is '['
|
else if value is '['
|
||||||
tag = 'INDEX_START'
|
tag = 'INDEX_START'
|
||||||
switch ptag
|
switch prev[0]
|
||||||
when '?' then prev[0] = 'INDEX_SOAK'
|
when '?' then prev[0] = 'INDEX_SOAK'
|
||||||
when '::' then prev[0] = 'INDEX_PROTO'
|
when '::' then prev[0] = 'INDEX_PROTO'
|
||||||
@token tag, value
|
@token tag, value
|
||||||
|
|
|
@ -24,9 +24,6 @@ func = -> i += 1
|
||||||
result = func() ? 101
|
result = func() ? 101
|
||||||
ok result is 10
|
ok result is 10
|
||||||
|
|
||||||
ok (non ? existent ? variables ? 1) is 1
|
|
||||||
|
|
||||||
|
|
||||||
# Only evaluate once.
|
# Only evaluate once.
|
||||||
counter = 0
|
counter = 0
|
||||||
getNextNode = ->
|
getNextNode = ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue