From bf8d483719b5bd59819d3c47e47f6e260cd82230 Mon Sep 17 00:00:00 2001 From: mohayonao Date: Wed, 14 May 2014 14:02:35 +0900 Subject: [PATCH] fix symbol literal - \ === '' - \0123 === '0123' - build v0.0.26 --- build/scscript.js | 8 ++++---- package.json | 2 +- src/sc/lang/compiler/lexer.js | 4 ++-- src/sc/lang/compiler/lexer_test.js | 22 ++++++++++++++++++++++ src/sc/lang/compiler/parser.js | 2 +- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/build/scscript.js b/build/scscript.js index 36d3d43..461b5ac 100644 --- a/build/scscript.js +++ b/build/scscript.js @@ -1,7 +1,7 @@ (function(global) { "use strict"; -var sc = { VERSION: "0.0.25" }; +var sc = { VERSION: "0.0.26" }; // src/sc/sc.js (function(sc) { @@ -1895,11 +1895,11 @@ var sc = { VERSION: "0.0.25" }; var re, start, items; var value; - re = /^\\([a-z_]\w*)?/i; + re = /^\\([a-zA-Z_]\w*|\d+)?/; start = this.index; items = re.exec(this.source.slice(this.index)); - value = items[1]; + value = items[1] || ""; this.index += items[0].length; @@ -2124,7 +2124,7 @@ var sc = { VERSION: "0.0.25" }; node = this.withScope(function() { var body; - body = this.parseFunctionBody(""); + body = this.parseFunctionBody(null); if (body.length === 1 && body[0].type === Syntax.BlockExpression) { body = body[0].body; } diff --git a/package.json b/package.json index daaca4a..db1e9ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scscript", - "version": "0.0.25", + "version": "0.0.26", "author": "Nao Yonamine ", "homepage": "http://mohayonao.github.io/SCScript/", "bugs": "https://github.com/mohayonao/SCScript/issues", diff --git a/src/sc/lang/compiler/lexer.js b/src/sc/lang/compiler/lexer.js index ef47669..2f4788a 100644 --- a/src/sc/lang/compiler/lexer.js +++ b/src/sc/lang/compiler/lexer.js @@ -596,11 +596,11 @@ var re, start, items; var value; - re = /^\\([a-z_]\w*)?/i; + re = /^\\([a-zA-Z_]\w*|\d+)?/; start = this.index; items = re.exec(this.source.slice(this.index)); - value = items[1]; + value = items[1] || ""; this.index += items[0].length; diff --git a/src/sc/lang/compiler/lexer_test.js b/src/sc/lang/compiler/lexer_test.js index 3c545c4..0ba2d46 100644 --- a/src/sc/lang/compiler/lexer_test.js +++ b/src/sc/lang/compiler/lexer_test.js @@ -409,6 +409,28 @@ } }, ], + "\\": [ + { + type: Token.SymbolLiteral, + value: "", + range: [ 0, 1 ], + loc: { + start: { line: 1, column: 0 }, + end : { line: 1, column: 1 } + } + }, + ], + "\\0123": [ + { + type: Token.SymbolLiteral, + value: "0123", + range: [ 0, 5 ], + loc: { + start: { line: 1, column: 0 }, + end : { line: 1, column: 5 } + } + }, + ], "'symbol'": [ { type: Token.SymbolLiteral, diff --git a/src/sc/lang/compiler/parser.js b/src/sc/lang/compiler/parser.js index 92f33a9..0ee64cf 100644 --- a/src/sc/lang/compiler/parser.js +++ b/src/sc/lang/compiler/parser.js @@ -167,7 +167,7 @@ node = this.withScope(function() { var body; - body = this.parseFunctionBody(""); + body = this.parseFunctionBody(null); if (body.length === 1 && body[0].type === Syntax.BlockExpression) { body = body[0].body; }