1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

bringing back half assignments, but just for 'a = or b' and 'a = and b'

This commit is contained in:
Jeremy Ashkenas 2010-07-26 23:53:03 -04:00
parent 89cd25ab15
commit 9be1453886
3 changed files with 23 additions and 4 deletions

View file

@ -70,7 +70,7 @@
return this.literalToken();
};
Lexer.prototype.identifierToken = function() {
var close_index, forcedIdentifier, id, tag;
var _d, close_index, forcedIdentifier, id, tag;
if (!(id = this.match(IDENTIFIER, 1))) {
return false;
}
@ -86,6 +86,9 @@
if (id === 'all' && this.tag() === 'FOR') {
tag = 'ALL';
}
if (('AND' === (_d = this.tag() === '=' && tag) || 'OR' === _d)) {
return this.tag(1, CONVERSIONS[id] + '=');
}
if (include(JS_FORBIDDEN, id)) {
if (forcedIdentifier) {
tag = 'STRING';

View file

@ -88,6 +88,8 @@ exports.Lexer = class Lexer
tag = id.toUpperCase() if include(JS_KEYWORDS, id) or (not forcedIdentifier and include(COFFEE_KEYWORDS, id))
tag = 'LEADING_WHEN' if tag is 'WHEN' and include LINE_BREAK, @tag()
tag = 'ALL' if id is 'all' and @tag() is 'FOR'
if @tag() is '=' and tag in ['AND', 'OR']
return @tag 1, CONVERSIONS[id] + '='
if include(JS_FORBIDDEN, id)
if forcedIdentifier
tag = 'STRING'

View file

@ -18,9 +18,8 @@ func = -> i++
ok 1 > func() < 1
# `:` and `=` should be interchangeable, as should be `==` and `is`.
a = 1
b = 1
# `==` and `is` should be interchangeable.
a = b = 1
ok a is 1 and b is 1
ok a == b
@ -65,3 +64,18 @@ y = -5
ok x*-y is 50
ok x*+y is -50
# Half-operators.
one = two = null
one = or 1
two or= 2
ok one is 1
ok two is 2
one = and 'one'
two and= 'two'
ok one is 'one'
ok two is 'two'