Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3点改动 #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/LexicalParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var lex =

var lex =
{
InputElementDiv:"<WhiteSpace>|<LineTerminator>|<Comment>|<ReservedWord>|<Identifier>|<NumericLiteral>|<Punctuator>|<StringLiteral>|<DivPunctuator>",
InputElementRegExp:"<WhiteSpace>|<LineTerminator>|<Comment>|<ReservedWord>|<Identifier>|<NumericLiteral>|<Punctuator>|<RegularExpressionLiteral>|<StringLiteral>",
Expand Down Expand Up @@ -101,4 +102,4 @@ function LexicalParser()
inputElementRegExp.lastIndex = inputElement.lastIndex;
return token;
};
}
}
3 changes: 2 additions & 1 deletion source/Parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Parser()

function Parser()
{
this.lexicalParser = new LexicalParser();
this.syntacticalParser = new SyntacticalParser();
Expand Down
31 changes: 17 additions & 14 deletions source/SyntacticalParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var rules =

var rules =
{
"IdentifierName":[["Identifier"], ["break"], ["do"], ["instanceof"], ["typeof"], ["case"], ["else"], ["new"], ["var"], ["catch"], ["finally"], ["return"], ["void"], ["continue"], ["for"], ["switch"], ["while"], ["debugger"], ["function"], ["this"], ["with"], ["default"], ["if"], ["throw"], ["delete"], ["in"], ["try"]],
"Literal":[["NullLiteral"], ["BooleanLiteral"], ["NumericLiteral"], ["StringLiteral"], ["RegularExpressionLiteral"]],
Expand Down Expand Up @@ -80,24 +81,26 @@
"SourceElements":[["SourceElement"], ["SourceElements", "SourceElement"]], "SourceElement":[["Statement"], ["FunctionDeclaration"]]

};

function Symbol(symbolName, token)
{
this.name = symbolName;
this.token = token;
this.childNodes = [];
this. toString =
function(indent)
{
if(!indent)
indent = "";
if(this.childNodes.length == 1)
return this.childNodes[0]. toString (indent);
var str = indent + this.name + (this.token != undefined && this.name != this.token ? ":" + this.token:"") + "\n";
for(var i = 0;i < this.childNodes.length;i++)
str += this.childNodes[i]. toString (indent + " ");
return str;
};
this.childNodes = [];
}

Symbol.prototype.toString = function(indent)
{
if(!indent)
indent = "";
if(this.childNodes.length == 1)
return this.childNodes[0]. toString (indent);
var str = indent + this.name + (this.token != undefined && this.name != this.token ? ":" + this.token:"") + "\n";
for(var i = 0;i < this.childNodes.length;i++)
str += this.childNodes[i]. toString (indent + " ");
return str;
};

function SyntacticalParser()
{
var currentRule;
Expand Down
424 changes: 424 additions & 0 deletions test/JSinJS-all.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions test/build-4-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

var fs = require('fs');


var rootPath='../source';

var LexicalParser = fs.readFileSync(rootPath+'/LexicalParser.js','utf-8');
var SyntacticalParser = fs.readFileSync(rootPath+'/SyntacticalParser.js','utf-8');
var Parser = fs.readFileSync(rootPath+'/Parser.js','utf-8');
var patch = fs.readFileSync('./node-patch.js','utf-8');

var breakLine='\r\n';

var data=[LexicalParser,SyntacticalParser,Parser,patch].join(breakLine);

fs.writeFileSync('./JSinJS-all.js',data,'utf-8');
6 changes: 6 additions & 0 deletions test/node-patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


module.exports={
Parser : Parser
}

53 changes: 53 additions & 0 deletions test/parse-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

var fs = require('fs');

var Parser=require("./JSinJS-all").Parser;


var fileList=[
"my-code.js",
"backbone-0.5.3.js",
"mootools-1.4.1.js",
"prototype-1.7.0.0.js",
"ext.js",
"jquery-1.7.1.js",
"ext-core-3.1.0.js",
"ext-debug.js",
"ext-dev.js",
"ext-all.js",
"ext-all-debug.js",
"ext-all-dev.js"
]

var testcase="./testcase";

function parseFile( idx ){

var filePath=testcase+"/"+fileList[idx||0];

var code = fs.readFileSync(filePath, "UTF-8");

var count=0;
var start=Date.now();
var parser = new Parser();
var lastToken;
var tree ;
try{
tree= parser.parse(code ,function(token){
count++;
lastToken=token;
});
}catch(e){
console.log(count, lastToken);
throw e;
}
var end=Date.now();
console.log( "token count : "+count);
console.log( "time cost : "+ (end-start) );

return tree;
}

var testFileIdx= process.argv[2]||0;
parseFile(testFileIdx);

Loading