Adding TrevorBurnham's suggestion for 'a not in b'

This commit is contained in:
Jeremy Ashkenas 2010-06-21 22:25:28 -04:00
parent 3b28f52ff7
commit 38a9b7166b
6 changed files with 18 additions and 6 deletions

View File

@ -740,6 +740,8 @@
return new OpNode('instanceof', $1, $3);
}), o("Expression IN Expression", function() {
return new OpNode('in', $1, $3);
}), o("Expression ! IN Expression", function() {
return new OpNode('!', new ParentheticalNode(new OpNode('in', $1, $4)));
})
]
};

File diff suppressed because one or more lines are too long

View File

@ -180,7 +180,7 @@
stack[stack.length - 2] += stack.pop();
}
open = stack[stack.length - 1] > 0;
if (prev && prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, tag)) {
if (prev && prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, tag) && !(tag === '!' && post[0] === 'IN')) {
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
stack[stack.length - 1] += 1;
if (include(EXPRESSION_START, tag)) {
@ -419,7 +419,7 @@
// Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@'];
// If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', 'THIS', 'NULL', '@', '->', '=>', '[', '(', '{'];
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'THIS', 'NULL', '@', '->', '=>', '[', '(', '{'];
// Tokens indicating that the implicit call must enclose a block of expressions.
IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
// Tokens that always mark the end of an implicit call for single-liners.

View File

@ -566,6 +566,7 @@ grammar: {
o "Expression INSTANCEOF Expression", -> new OpNode 'instanceof', $1, $3
o "Expression IN Expression", -> new OpNode 'in', $1, $3
o "Expression ! IN Expression", -> new OpNode '!', new ParentheticalNode new OpNode 'in', $1, $4
]
}

View File

@ -126,7 +126,8 @@ exports.Rewriter: class Rewriter
tag: token[0]
stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT'
open: stack[stack.length - 1] > 0
if prev and prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, tag)
if prev and prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, tag) and
not (tag is '!' and post[0] is 'IN')
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
stack[stack.length - 1]: + 1
stack.push 0 if include(EXPRESSION_START, tag)
@ -282,7 +283,7 @@ IMPLICIT_FUNC: ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@']
# If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
IMPLICIT_CALL: ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START',
'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION',
'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT',
'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!',
'THIS', 'NULL',
'@', '->', '=>', '[', '(', '{']

View File

@ -34,3 +34,9 @@ func: -> val: + 1
ok 2 > (func null) < 2
ok val is 1
# Allow "if x not in y"
obj: {a: true}
ok 'b' not in obj
ok not ('a' not in obj)