Skip to content

Commit

Permalink
add HexNumberLiteral
Browse files Browse the repository at this point in the history
- add scanner for Hex Number
- fix test cases
- build v0.0.24
  • Loading branch information
mohayonao committed May 13, 2014
1 parent f1ce000 commit b2d43bf
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 47 deletions.
33 changes: 31 additions & 2 deletions build/scscript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(global) {
"use strict";

var sc = { VERSION: "0.0.23" };
var sc = { VERSION: "0.0.24" };

// src/sc/sc.js
(function(sc) {
Expand Down Expand Up @@ -1657,7 +1657,9 @@ var sc = { VERSION: "0.0.23" };
};

Lexer.prototype.scanNumericLiteral = function(neg) {
return this.scanNAryNumberLiteral(neg) || this.scanDecimalNumberLiteral(neg);
return this.scanNAryNumberLiteral(neg) ||
this.scanHexNumberLiteral(neg) ||
this.scanDecimalNumberLiteral(neg);
};

Lexer.prototype.scanNegativeNumericLiteral = function() {
Expand Down Expand Up @@ -1781,6 +1783,33 @@ var sc = { VERSION: "0.0.23" };
return value;
};

Lexer.prototype.scanHexNumberLiteral = function(neg) {
var re, start, items;
var integer, pi;
var value, type;
var token;

re = /^(0x(?:[\da-fA-F](?:_(?=[\da-fA-F]))?)+)(pi)?/;
start = this.index;
items = re.exec(this.source.slice(this.index));

if (!items) {
return;
}

integer = items[1].replace(/_/g, "");
pi = !!items[2];

type = Token.IntegerLiteral;
value = +integer;

token = makeNumberToken(type, value, neg, pi);

this.index += items[0].length;

return this.makeToken(token.type, token.value, start);
};

Lexer.prototype.scanDecimalNumberLiteral = function(neg) {
var re, start, items, integer, frac, pi;
var value, type;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scscript",
"version": "0.0.23",
"version": "0.0.24",
"author": "Nao Yonamine <mohayonao@gmail.com>",
"homepage": "http://mohayonao.github.io/SCScript/",
"bugs": "https://github.com/mohayonao/SCScript/issues",
Expand Down
31 changes: 30 additions & 1 deletion src/sc/lang/compiler/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@
};

Lexer.prototype.scanNumericLiteral = function(neg) {
return this.scanNAryNumberLiteral(neg) || this.scanDecimalNumberLiteral(neg);
return this.scanNAryNumberLiteral(neg) ||
this.scanHexNumberLiteral(neg) ||
this.scanDecimalNumberLiteral(neg);
};

Lexer.prototype.scanNegativeNumericLiteral = function() {
Expand Down Expand Up @@ -482,6 +484,33 @@
return value;
};

Lexer.prototype.scanHexNumberLiteral = function(neg) {
var re, start, items;
var integer, pi;
var value, type;
var token;

re = /^(0x(?:[\da-fA-F](?:_(?=[\da-fA-F]))?)+)(pi)?/;
start = this.index;
items = re.exec(this.source.slice(this.index));

if (!items) {
return;
}

integer = items[1].replace(/_/g, "");
pi = !!items[2];

type = Token.IntegerLiteral;
value = +integer;

token = makeNumberToken(type, value, neg, pi);

this.index += items[0].length;

return this.makeToken(token.type, token.value, start);
};

Lexer.prototype.scanDecimalNumberLiteral = function(neg) {
var re, start, items, integer, frac, pi;
var value, type;
Expand Down
Loading

0 comments on commit b2d43bf

Please sign in to comment.