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

Binary notation integers (0b100 as 4).

This commit is contained in:
Revence Kalibwani 2011-10-21 21:44:56 +03:00
parent d359764fba
commit 264f881a81
3 changed files with 23 additions and 4 deletions

View file

@ -107,11 +107,14 @@
};
Lexer.prototype.numberToken = function() {
var match, number;
var is_binary, match, number, numlen;
if (!(match = NUMBER.exec(this.chunk))) return 0;
number = match[0];
numlen = number.length;
is_binary = /0b([01]+)/.exec(number);
if (is_binary) number = (parseInt(is_binary[1], 2)).toString();
this.token('NUMBER', number);
return number.length;
return numlen;
};
Lexer.prototype.stringToken = function() {
@ -620,7 +623,7 @@
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
NUMBER = /^0x[\da-f]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
NUMBER = /^0x[\da-f]+|^0b[01]+|^\d*\.?\d+(?:e[+-]?\d+)?/i;
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;