Skip to content

Commit

Permalink
update version
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Jun 5, 2014
1 parent 5a1fc4c commit 763b5c9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ npm install homunculus
## API
* getClass(type:String, lan:String):class
* type: lexer parser node context token
* lan: js javascript es ecmascript as actionscript css
* lan: js javascript es es5 ecmascript es6 as actionscript css
* getLexer(lan:String):object
* lan: js javascript es ecmascript as actionscript css java c++ cpp cplusplus
* lan: js javascript es es5 ecmascript es6 as actionscript css java c++ cpp cplusplus
* getParser(lan:String):object
* lan: js javascript es ecmascript css
* lan: js javascript es es5 ecmascript es6 css
* getContext(lan:String):object
* lan: js javascript es ecmascript
* lan: js javascript es es5 ecmascript

## AST
当调用语法分析器解析后,会返回生成ast,这是一个树状数据结构,每个节点都是对应语法解析器目录下的Node.js的实例。<br/>
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
case 'es6':
case 'as':
Expand All @@ -51,6 +52,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
return JsParser;
case 'es6':
Expand All @@ -66,6 +68,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
return JsNode;
case 'es6':
Expand All @@ -81,6 +84,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
return JsContext;
default:
Expand All @@ -100,6 +104,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
case 'es6':
case 'as':
Expand All @@ -125,6 +130,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
return new JsParser(exports.getLexer(lan));
case 'es6':
Expand All @@ -142,6 +148,7 @@
case 'js':
case 'javascript':
case 'es':
case 'es5':
case 'ecmascript':
return new JsContext();
default:
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": "homunculus",
"version": "0.1.15",
"version": "0.2.0",
"description": "A lexer&parser by Javascript",
"maintainers": [
{
Expand Down
38 changes: 38 additions & 0 deletions tests/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,98 @@ describe('api of homunculus', function() {
expect(homunculus.getClass('lexer', 'js')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'javascript')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'es')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'es5')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'ecmascript')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'es6')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'as')).to.be(Lexer);
expect(homunculus.getClass('lexer', 'actionscript')).to.be(Lexer);

expect(homunculus.getClass('lexer', 'css')).to.be(CssLexer);

expect(function() {
homunculus.getClass('lexer', 'unknow');
}).to.throwError();

expect(homunculus.getClass('parser', 'js')).to.be(JsParser);
expect(homunculus.getClass('parser', 'javascript')).to.be(JsParser);
expect(homunculus.getClass('parser', 'es')).to.be(JsParser);
expect(homunculus.getClass('parser', 'es5')).to.be(JsParser);
expect(homunculus.getClass('parser', 'ecmascript')).to.be(JsParser);
expect(homunculus.getClass('parser', 'es6')).to.be(Es6Parser);

expect(homunculus.getClass('parser', 'css')).to.be(CssParser);

expect(function() {
homunculus.getClass('parser', 'unknow');
}).to.throwError();

expect(homunculus.getClass('node', 'js')).to.be(JsNode);
expect(homunculus.getClass('node', 'javascript')).to.be(JsNode);
expect(homunculus.getClass('node', 'es')).to.be(JsNode);
expect(homunculus.getClass('node', 'es5')).to.be(JsNode);
expect(homunculus.getClass('node', 'ecmascript')).to.be(JsNode);
expect(homunculus.getClass('node', 'es6')).to.be(Es6Node);

expect(homunculus.getClass('node', 'css')).to.be(CssNode);

expect(function() {
homunculus.getClass('node', 'unknow');
}).to.throwError();

expect(homunculus.getClass('token')).to.be(Token);

expect(homunculus.getClass('context', 'js')).to.be(JsContext);
expect(homunculus.getClass('context', 'javascript')).to.be(JsContext);
expect(homunculus.getClass('context', 'es')).to.be(JsContext);
expect(homunculus.getClass('context', 'es5')).to.be(JsContext);
expect(homunculus.getClass('context', 'ecmascript')).to.be(JsContext);

expect(function() {
homunculus.getClass('context', 'unknow');
}).to.throwError();
expect(function() {
homunculus.getClass('unknow', 'unknow');
}).to.throwError();
});
it('#getLexer', function() {
expect(homunculus.getLexer('js')).to.be.a(Lexer);
expect(homunculus.getLexer('javascript')).to.be.a(Lexer);
expect(homunculus.getLexer('es')).to.be.a(Lexer);
expect(homunculus.getLexer('es5')).to.be.a(Lexer);
expect(homunculus.getLexer('ecmascript')).to.be.a(Lexer);
expect(homunculus.getLexer('es6')).to.be.a(Lexer);
expect(homunculus.getLexer('as')).to.be.a(Lexer);
expect(homunculus.getLexer('actionscript')).to.be.a(Lexer);

expect(homunculus.getLexer('css')).to.be.a(CssLexer);

expect(function() {
homunculus.getLexer('unknow');
}).to.throwError();
});
it('#getParser', function() {
expect(homunculus.getParser('js')).to.be.a(JsParser);
expect(homunculus.getParser('javascript')).to.be.a(JsParser);
expect(homunculus.getParser('es')).to.be.a(JsParser);
expect(homunculus.getParser('es5')).to.be.a(JsParser);
expect(homunculus.getParser('ecmascript')).to.be.a(JsParser);
expect(homunculus.getParser('es6')).to.be.a(Es6Parser);

expect(homunculus.getParser('css')).to.be.a(CssParser);

expect(function() {
homunculus.getParser('unknow');
}).to.throwError();
});
it('#getContext', function() {
expect(homunculus.getContext('js')).to.be.a(JsContext);
expect(homunculus.getContext('javascript')).to.be.a(JsContext);
expect(homunculus.getContext('es')).to.be.a(JsContext);
expect(homunculus.getContext('es5')).to.be.a(JsContext);
expect(homunculus.getContext('ecmascript')).to.be.a(JsContext);

expect(function() {
homunculus.getContext('unknow');
}).to.throwError();
});
});

0 comments on commit 763b5c9

Please sign in to comment.