homunculus
Advanced tools
Comparing version 0.2.3 to 0.2.4-1
@@ -35,3 +35,3 @@ (function(factory) { | ||
var regMatch = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() { | ||
var id = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() { | ||
return !!(self.keyWords().hasOwnProperty(this.content())); | ||
@@ -41,3 +41,3 @@ }, function() { | ||
}); | ||
regMatch.callback = function(token) { | ||
id.callback = function(token) { | ||
var s = token.content(); | ||
@@ -49,3 +49,3 @@ if(isProperty) { | ||
}; | ||
self.addMatch(regMatch); | ||
self.addMatch(id); | ||
@@ -52,0 +52,0 @@ self.addMatch(new RegMatch(Token.NUMBER, /^\.\d+(?:E[+-]?\d*)?/i, { |
@@ -367,2 +367,3 @@ (function(factory) { | ||
} | ||
node.add(this.match(';')); | ||
return node; | ||
@@ -369,0 +370,0 @@ }, |
@@ -11,2 +11,3 @@ (function(factory) { | ||
var character = require('../util/character'); | ||
var nid = 0; | ||
var Node = Class(function(type, children) { | ||
@@ -26,4 +27,8 @@ this.type = type; | ||
this.ne = null; | ||
this.id = nid++; | ||
return this; | ||
}).methods({ | ||
nid: function() { | ||
return this.id; | ||
}, | ||
name: function(t) { | ||
@@ -30,0 +35,0 @@ if(!character.isUndefined(t)) { |
{ | ||
"name": "homunculus", | ||
"version": "0.2.3", | ||
"version": "0.2.4-1", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
@@ -13,2 +13,6 @@ # A lexer&parser by Javascript | ||
## 使用说明 | ||
* 解析语法并返回语法树和此法单元序列。 | ||
* CommonJS/AMD/CMD自适应。 | ||
## API | ||
@@ -117,2 +121,5 @@ * getClass(type:String, lan:String):class | ||
当调用语法分析器解析后,会返回生成ast,这是一个树状数据结构,每个节点都是对应语法解析器目录下的Node.js的实例。<br/> | ||
demo目录下是一个用js的parser分析输入js代码并画出ast形状的页面。 | ||
demo目录下是一个用js的parser分析输入js代码并画出ast形状的页面。 | ||
## License | ||
[MIT License] |
@@ -27,3 +27,3 @@ var Rule = require('./Rule'); | ||
var regMatch = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() { | ||
var id = new RegMatch(Token.ID, /^[$a-zA-Z_][$\w]*/, Lexer.SPECIAL, function() { | ||
return !!(self.keyWords().hasOwnProperty(this.content())); | ||
@@ -33,3 +33,3 @@ }, function() { | ||
}); | ||
regMatch.callback = function(token) { | ||
id.callback = function(token) { | ||
var s = token.content(); | ||
@@ -41,3 +41,3 @@ if(isProperty) { | ||
}; | ||
self.addMatch(regMatch); | ||
self.addMatch(id); | ||
@@ -44,0 +44,0 @@ self.addMatch(new RegMatch(Token.NUMBER, /^\.\d+(?:E[+-]?\d*)?/i, { |
@@ -359,2 +359,3 @@ var IParser = require('../Parser'); | ||
} | ||
node.add(this.match(';')); | ||
return node; | ||
@@ -361,0 +362,0 @@ }, |
var Class = require('../util/Class'); | ||
var character = require('../util/character'); | ||
var nid = 0; | ||
var Node = Class(function(type, children) { | ||
@@ -17,4 +18,8 @@ this.type = type; | ||
this.ne = null; | ||
this.id = nid++; | ||
return this; | ||
}).methods({ | ||
nid: function() { | ||
return this.id; | ||
}, | ||
name: function(t) { | ||
@@ -21,0 +26,0 @@ if(!character.isUndefined(t)) { |
@@ -316,2 +316,8 @@ var homunculus = require('../'); | ||
}); | ||
it('keyword can not be label', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('var:'); | ||
}).to.throwError(); | ||
}); | ||
it('keyword after get/set', function() { | ||
@@ -993,3 +999,9 @@ var parser = homunculus.getParser('js'); | ||
expect(varstmt.size()).to.be(3); | ||
expect(varstmt.leaves().length).to.be(3); | ||
}); | ||
it('node #nid', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a'); | ||
expect(node.nid()).to.be.a('number'); | ||
}); | ||
it('#ast should return as parse return', function() { | ||
@@ -996,0 +1008,0 @@ var parser = homunculus.getParser('js'); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1286701
32967
123