mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
merged == and != into COMPARE
This commit is contained in:
parent
fc332bcfbd
commit
ebdcfb5227
5 changed files with 41 additions and 55 deletions
|
@ -575,10 +575,6 @@
|
|||
return new Op('+', $1, $3);
|
||||
}), o('Expression - Expression', function() {
|
||||
return new Op('-', $1, $3);
|
||||
}), o('Expression == Expression', function() {
|
||||
return new Op('==', $1, $3);
|
||||
}), o('Expression != Expression', function() {
|
||||
return new Op('!=', $1, $3);
|
||||
}), o('Expression MATH Expression', function() {
|
||||
return new Op($2, $1, $3);
|
||||
}), o('Expression SHIFT Expression', function() {
|
||||
|
@ -596,7 +592,7 @@
|
|||
})
|
||||
]
|
||||
};
|
||||
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", '==', '!=', 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||
tokens = [];
|
||||
for (name in grammar) {
|
||||
alternatives = grammar[name];
|
||||
|
|
23
lib/lexer.js
23
lib/lexer.js
|
@ -90,16 +90,9 @@
|
|||
}
|
||||
if (!forcedIdentifier) {
|
||||
if (COFFEE_ALIASES.hasOwnProperty(id)) {
|
||||
tag = id = COFFEE_ALIASES[id];
|
||||
}
|
||||
if (id === '!') {
|
||||
tag = 'UNARY';
|
||||
} else if (__indexOf.call(LOGIC, id) >= 0) {
|
||||
tag = 'LOGIC';
|
||||
} else if (__indexOf.call(BOOL, tag) >= 0) {
|
||||
id = tag.toLowerCase();
|
||||
tag = 'BOOL';
|
||||
id = COFFEE_ALIASES[id];
|
||||
}
|
||||
tag = id === '!' ? 'UNARY' : id === '==' || id === '!=' ? 'COMPARE' : id === '&&' || id === '||' ? 'LOGIC' : id === 'true' || id === 'false' || id === 'null' ? 'BOOL' : tag;
|
||||
}
|
||||
this.token(tag, id);
|
||||
if (colon) {
|
||||
|
@ -600,10 +593,10 @@
|
|||
is: '==',
|
||||
isnt: '!=',
|
||||
not: '!',
|
||||
yes: 'TRUE',
|
||||
no: 'FALSE',
|
||||
on: 'TRUE',
|
||||
off: 'FALSE'
|
||||
yes: 'true',
|
||||
no: 'false',
|
||||
on: 'true',
|
||||
off: 'false'
|
||||
}) {
|
||||
COFFEE_KEYWORDS.push(op);
|
||||
}
|
||||
|
@ -632,9 +625,9 @@
|
|||
NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
|
||||
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
|
||||
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'];
|
||||
LOGIC = ['&', '|', '^', '&&', '||'];
|
||||
LOGIC = ['&&', '||', '&', '|', '^'];
|
||||
SHIFT = ['<<', '>>', '>>>'];
|
||||
COMPARE = ['<=', '<', '>', '>='];
|
||||
COMPARE = ['==', '!=', '<', '>', '<=', '>='];
|
||||
MATH = ['*', '/', '%'];
|
||||
RELATION = ['IN', 'OF', 'INSTANCEOF'];
|
||||
BOOL = ['TRUE', 'FALSE', 'NULL'];
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -518,8 +518,6 @@ grammar =
|
|||
|
||||
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 MATH Expression', -> new Op $2, $1, $3
|
||||
o 'Expression SHIFT Expression', -> new Op $2, $1, $3
|
||||
|
@ -556,7 +554,7 @@ operators = [
|
|||
["left", '+', '-']
|
||||
["left", 'SHIFT']
|
||||
["left", 'RELATION']
|
||||
["left", '==', '!=', 'COMPARE']
|
||||
["left", 'COMPARE']
|
||||
["left", 'LOGIC']
|
||||
["left", '.']
|
||||
["nonassoc", 'INDENT', 'OUTDENT']
|
||||
|
@ -586,7 +584,7 @@ for all name, alternatives of grammar
|
|||
# precedence from low to high, and we have it high to low
|
||||
# (as in [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
|
||||
exports.parser = new Parser
|
||||
tokens: tokens.join ' '
|
||||
bnf: grammar
|
||||
operators: operators.reverse()
|
||||
startSymbol: 'Root'
|
||||
tokens : tokens.join ' '
|
||||
bnf : grammar
|
||||
operators : operators.reverse()
|
||||
startSymbol : 'Root'
|
||||
|
|
|
@ -114,14 +114,17 @@ exports.Lexer = class Lexer
|
|||
else if id in RESERVED
|
||||
@identifierError id
|
||||
unless forcedIdentifier
|
||||
tag = id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id
|
||||
if id is '!'
|
||||
tag = 'UNARY'
|
||||
else if id in LOGIC
|
||||
tag = 'LOGIC'
|
||||
else if tag in BOOL
|
||||
id = tag.toLowerCase()
|
||||
tag = 'BOOL'
|
||||
id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id
|
||||
tag = if id is '!'
|
||||
'UNARY'
|
||||
else if id in ['==', '!=']
|
||||
'COMPARE'
|
||||
else if id in ['&&', '||']
|
||||
'LOGIC'
|
||||
else if id in ['true', 'false', 'null']
|
||||
'BOOL'
|
||||
else
|
||||
tag
|
||||
@token tag, id
|
||||
@token ':', ':' if colon
|
||||
input.length
|
||||
|
@ -523,10 +526,10 @@ COFFEE_KEYWORDS.push op for all op of COFFEE_ALIASES =
|
|||
is : '=='
|
||||
isnt : '!='
|
||||
not : '!'
|
||||
yes : 'TRUE'
|
||||
no : 'FALSE'
|
||||
on : 'TRUE'
|
||||
off : 'FALSE'
|
||||
yes : 'true'
|
||||
no : 'false'
|
||||
on : 'true'
|
||||
off : 'false'
|
||||
|
||||
# The list of keywords that are reserved by JavaScript, but not used, or are
|
||||
# used by CoffeeScript internally. We throw an error when these are encountered,
|
||||
|
@ -597,13 +600,13 @@ COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=
|
|||
UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE']
|
||||
|
||||
# Logical tokens.
|
||||
LOGIC = ['&', '|', '^', '&&', '||']
|
||||
LOGIC = ['&&', '||', '&', '|', '^']
|
||||
|
||||
# Bit-shifting tokens.
|
||||
SHIFT = ['<<', '>>', '>>>']
|
||||
|
||||
# Comparison tokens.
|
||||
COMPARE = ['<=', '<', '>', '>=']
|
||||
COMPARE = ['==', '!=', '<', '>', '<=', '>=']
|
||||
|
||||
# Mathmatical tokens.
|
||||
MATH = ['*', '/', '%']
|
||||
|
|
Loading…
Reference in a new issue