homunculus
Advanced tools
Comparing version 0.5.9 to 0.5.10
{ | ||
"name": "homunculus", | ||
"version": "0.5.9", | ||
"version": "0.5.10", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
@@ -47,3 +47,4 @@ var Lexer = require('./Lexer'); | ||
'"': true, | ||
')': true | ||
')': true, | ||
'$': true | ||
}.hasOwnProperty(this.peek)) { | ||
@@ -54,2 +55,4 @@ this.dealPt(temp); | ||
} | ||
//url只能省略一次,即url()中第一个出现的非空白token,多个的话不能省略 | ||
this.url = false; | ||
} | ||
@@ -69,2 +72,8 @@ for(var i = 0, matches = this.rule.matches(), len = matches.length; i < len; i++) { | ||
switch(token.type()) { | ||
//单位必须紧跟数字,否则便不是单位 | ||
case Token.BLANK: | ||
case Token.TAB: | ||
case Token.LINE: | ||
this.number = false; | ||
break; | ||
//@import和@media之后进入值状态 | ||
@@ -71,0 +80,0 @@ case Token.HEAD: |
@@ -35,3 +35,3 @@ var Rule = require('./Rule'); | ||
self.addMatch(new RegMatch(Token.NUMBER, /^-?\d+\.?\d*/i)); | ||
self.addMatch(new RegMatch(Token.NUMBER, /^\.\d+/i)); | ||
self.addMatch(new RegMatch(Token.NUMBER, /^-?\.\d+/i)); | ||
self.addMatch(new CompleteEqual(Token.UNITS, '%', null, true)); | ||
@@ -38,0 +38,0 @@ |
@@ -52,2 +52,14 @@ var INode = require('../Node'); | ||
CNDT: 'cndt', | ||
ADDEXPR: 'addexpr', | ||
MTPLEXPR: 'mtplexpr', | ||
PRMREXPR: 'prmrexpr', | ||
PARAM: 'param', | ||
COUNTER: 'counter', | ||
CALC: 'calc', | ||
TOGGLE: 'toggle', | ||
ATTR: 'attr', | ||
FILTER: 'filter', | ||
TRANSLATE: 'translate', | ||
VARS: 'vars', | ||
BRACKET: 'bracket', | ||
getKey: function(s) { | ||
@@ -54,0 +66,0 @@ if(!s) { |
@@ -7,2 +7,3 @@ var IParser = require('../Parser'); | ||
var Node = require('./Node'); | ||
var needValue = require('./needValue'); | ||
var S = {}; | ||
@@ -61,3 +62,2 @@ S[Token.BLANK] = S[Token.TAB] = S[Token.COMMENT] = S[Token.LINE] = true; | ||
this.ignores = {}; | ||
this.invalids = {}; | ||
this.tree = {}; | ||
@@ -263,13 +263,21 @@ }, | ||
} | ||
while(this.look | ||
&& [Token.ID, Token.NUMBER].indexOf(this.look.type()) > -1 | ||
&& !MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
if(this.look && MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
} | ||
node.add(this.match()); | ||
if(this.look && this.look.type() == Token.HACK) { | ||
else { | ||
while(this.look | ||
&& [Token.ID, Token.NUMBER, Token.UNITS, Token.PROPERTY].indexOf(this.look.type()) > -1 | ||
&& !MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
} | ||
} | ||
while(this.look && this.look.type() == Token.HACK) { | ||
node.add(this.match()); | ||
if(this.look && MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
if(this.look && this.look.type() == Token.HACK) { | ||
} | ||
else { | ||
while(this.look | ||
&& [Token.ID, Token.NUMBER, Token.UNITS, Token.PROPERTY].indexOf(this.look.type()) > -1 | ||
&& !MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
@@ -284,3 +292,5 @@ } | ||
node.add(this.match('(')); | ||
node.add(this.key()); | ||
var k = this.key(); | ||
node.add(k); | ||
//有可能整个变量作为一个键值,无需再有:value部分 | ||
if(this.look && this.look.content() == ':') { | ||
@@ -296,3 +306,3 @@ node.add(this.match(':')); | ||
node.add(this.match()); | ||
node.add(this.match(Token.STRING)); | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
node.add(this.match(';')); | ||
@@ -310,2 +320,28 @@ return node; | ||
while(this.look) { | ||
if(this.look.type() == Token.VARS) { | ||
var isFnCall = false; | ||
for(var i = this.index; i < this.length; i++) { | ||
var t = this.tokens[i]; | ||
if(!S.hasOwnProperty(t.type())) { | ||
isFnCall = t.content() == '('; | ||
break; | ||
} | ||
} | ||
if(isFnCall) { | ||
node2.add(this.fnc()); | ||
} | ||
else { | ||
node2.add(this.match()); | ||
if(this.look && this.look.content() == ':') { | ||
node2.add( | ||
this.match(), | ||
this.value() | ||
); | ||
} | ||
else { | ||
node2.add(this.match(';')); | ||
} | ||
} | ||
break; | ||
} | ||
switch(this.look.content().toLowerCase()) { | ||
@@ -396,3 +432,3 @@ case 'font-family': | ||
} | ||
node.add(this.match(Token.STRING)); | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
node.add(this.match(';')); | ||
@@ -405,7 +441,26 @@ return node; | ||
this.match(), | ||
this.match(Token.ID), | ||
this.match('('), | ||
this.match(')'), | ||
this.block() | ||
this.match([Token.ID, Token.PROPERTY]), | ||
this.match('(') | ||
); | ||
if(this.look | ||
&& (this.look.type() == Token.STRING | ||
|| this.look.type() == Token.VARS)) { | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
} | ||
node.add(this.match(')')); | ||
while(this.look && this.look.content() == ',') { | ||
node.add( | ||
this.match(), | ||
this.match([Token.ID, Token.PROPERTY]), | ||
this.match('(') | ||
); | ||
if(this.look | ||
&& (this.look.type() == Token.STRING | ||
|| this.look.type() == Token.VARS)) { | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
} | ||
} | ||
if(this.look && this.look.content() == '{') { | ||
node.add(this.block()); | ||
} | ||
return node; | ||
@@ -517,3 +572,12 @@ }, | ||
else { | ||
node.add(this.match(), this.match(';')); | ||
node.add(this.match()); | ||
if(this.look && this.look.content() == ':') { | ||
node.add( | ||
this.match(), | ||
this.value() | ||
); | ||
} | ||
else { | ||
node.add(this.match(';')); | ||
} | ||
} | ||
@@ -530,5 +594,9 @@ } | ||
var node = new Node(Node.STYLE); | ||
node.add(this.key(name)); | ||
node.add(this.match(':')); | ||
node.add(this.value()); | ||
var k = this.key(name); | ||
node.add(k); | ||
if(needValue(k) | ||
|| this.look && this.look.content() == ':') { | ||
node.add(this.match(':')); | ||
node.add(this.value()); | ||
} | ||
while(this.look && this.look.type() == Token.HACK) { | ||
@@ -547,3 +615,16 @@ node.add(this.match()); | ||
} | ||
node.add(this.match(name || Token.KEYWORD)); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
if(name) { | ||
if(this.look.type() == Token.VARS) { | ||
node.add(this.match()); | ||
} | ||
else { | ||
node.add(this.match(name)); | ||
} | ||
} | ||
else { | ||
node.add(this.match([Token.STRING, Token.KEYWORD])); | ||
} | ||
return node; | ||
@@ -561,2 +642,5 @@ }, | ||
switch(s) { | ||
case 'var': | ||
node.add(this.vars()); | ||
break; | ||
case 'url': | ||
@@ -617,2 +701,5 @@ node.add(this.url()); | ||
switch(s) { | ||
case 'var': | ||
node.add(this.vars()); | ||
break; | ||
case 'url': | ||
@@ -838,7 +925,6 @@ node.add(this.url()); | ||
); | ||
while(this.look && this.look.content() != ')') { | ||
node.add(this.param()); | ||
while(this.look && this.look.content() == ',') { | ||
node.add(this.match()); | ||
node.add(this.param()); | ||
if(this.look && this.look.content() == ',') { | ||
node.add(this.match()); | ||
} | ||
} | ||
@@ -870,2 +956,12 @@ node.add(this.match(')')); | ||
}, | ||
vars: function() { | ||
var node = new Node(Node.VARS); | ||
node.add( | ||
this.match(), | ||
this.match('('), | ||
this.match(), | ||
this.match(')') | ||
); | ||
return node; | ||
}, | ||
rgb: function(alpha) { | ||
@@ -1061,7 +1157,4 @@ var node = new Node(alpha ? Node.RGBA : Node.RGB); | ||
return this.ignores; | ||
}, | ||
invalid: function() { | ||
return this.invalids; | ||
} | ||
}); | ||
module.exports = Parser; |
@@ -52,9 +52,22 @@ var Class = require('../util/Class'); | ||
args.forEach(function(node) { | ||
node.parent(self); | ||
var last = self.children[self.children.length - 1]; | ||
if(last) { | ||
last.next(node); | ||
node.prev(last); | ||
if(Array.isArray(node)) { | ||
node.forEach(function(node2) { | ||
node2.parent(self); | ||
var last = self.children[self.children.length - 1]; | ||
if(last) { | ||
last.next(node2); | ||
node2.prev(last); | ||
} | ||
self.children.push(node2); | ||
}); | ||
} | ||
self.children.push(node); | ||
else { | ||
node.parent(self); | ||
var last = self.children[self.children.length - 1]; | ||
if(last) { | ||
last.next(node); | ||
node.prev(last); | ||
} | ||
self.children.push(node); | ||
} | ||
}); | ||
@@ -61,0 +74,0 @@ return self; |
@@ -47,3 +47,4 @@ define(function(require, exports, module) {var Lexer = require('./Lexer'); | ||
'"': true, | ||
')': true | ||
')': true, | ||
'$': true | ||
}.hasOwnProperty(this.peek)) { | ||
@@ -54,2 +55,4 @@ this.dealPt(temp); | ||
} | ||
//url只能省略一次,即url()中第一个出现的非空白token,多个的话不能省略 | ||
this.url = false; | ||
} | ||
@@ -69,2 +72,8 @@ for(var i = 0, matches = this.rule.matches(), len = matches.length; i < len; i++) { | ||
switch(token.type()) { | ||
//单位必须紧跟数字,否则便不是单位 | ||
case Token.BLANK: | ||
case Token.TAB: | ||
case Token.LINE: | ||
this.number = false; | ||
break; | ||
//@import和@media之后进入值状态 | ||
@@ -71,0 +80,0 @@ case Token.HEAD: |
@@ -35,3 +35,3 @@ define(function(require, exports, module) {var Rule = require('./Rule'); | ||
self.addMatch(new RegMatch(Token.NUMBER, /^-?\d+\.?\d*/i)); | ||
self.addMatch(new RegMatch(Token.NUMBER, /^\.\d+/i)); | ||
self.addMatch(new RegMatch(Token.NUMBER, /^-?\.\d+/i)); | ||
self.addMatch(new CompleteEqual(Token.UNITS, '%', null, true)); | ||
@@ -38,0 +38,0 @@ |
@@ -52,2 +52,14 @@ define(function(require, exports, module) {var INode = require('../Node'); | ||
CNDT: 'cndt', | ||
ADDEXPR: 'addexpr', | ||
MTPLEXPR: 'mtplexpr', | ||
PRMREXPR: 'prmrexpr', | ||
PARAM: 'param', | ||
COUNTER: 'counter', | ||
CALC: 'calc', | ||
TOGGLE: 'toggle', | ||
ATTR: 'attr', | ||
FILTER: 'filter', | ||
TRANSLATE: 'translate', | ||
VARS: 'vars', | ||
BRACKET: 'bracket', | ||
getKey: function(s) { | ||
@@ -54,0 +66,0 @@ if(!s) { |
@@ -7,2 +7,3 @@ define(function(require, exports, module) {var IParser = require('../Parser'); | ||
var Node = require('./Node'); | ||
var needValue = require('./needValue'); | ||
var S = {}; | ||
@@ -61,3 +62,2 @@ S[Token.BLANK] = S[Token.TAB] = S[Token.COMMENT] = S[Token.LINE] = true; | ||
this.ignores = {}; | ||
this.invalids = {}; | ||
this.tree = {}; | ||
@@ -263,13 +263,21 @@ }, | ||
} | ||
while(this.look | ||
&& [Token.ID, Token.NUMBER].indexOf(this.look.type()) > -1 | ||
&& !MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
if(this.look && MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
} | ||
node.add(this.match()); | ||
if(this.look && this.look.type() == Token.HACK) { | ||
else { | ||
while(this.look | ||
&& [Token.ID, Token.NUMBER, Token.UNITS, Token.PROPERTY].indexOf(this.look.type()) > -1 | ||
&& !MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
} | ||
} | ||
while(this.look && this.look.type() == Token.HACK) { | ||
node.add(this.match()); | ||
if(this.look && MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
if(this.look && this.look.type() == Token.HACK) { | ||
} | ||
else { | ||
while(this.look | ||
&& [Token.ID, Token.NUMBER, Token.UNITS, Token.PROPERTY].indexOf(this.look.type()) > -1 | ||
&& !MT.hasOwnProperty(this.look.content().toLowerCase())) { | ||
node.add(this.match()); | ||
@@ -284,3 +292,5 @@ } | ||
node.add(this.match('(')); | ||
node.add(this.key()); | ||
var k = this.key(); | ||
node.add(k); | ||
//有可能整个变量作为一个键值,无需再有:value部分 | ||
if(this.look && this.look.content() == ':') { | ||
@@ -296,3 +306,3 @@ node.add(this.match(':')); | ||
node.add(this.match()); | ||
node.add(this.match(Token.STRING)); | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
node.add(this.match(';')); | ||
@@ -310,2 +320,28 @@ return node; | ||
while(this.look) { | ||
if(this.look.type() == Token.VARS) { | ||
var isFnCall = false; | ||
for(var i = this.index; i < this.length; i++) { | ||
var t = this.tokens[i]; | ||
if(!S.hasOwnProperty(t.type())) { | ||
isFnCall = t.content() == '('; | ||
break; | ||
} | ||
} | ||
if(isFnCall) { | ||
node2.add(this.fnc()); | ||
} | ||
else { | ||
node2.add(this.match()); | ||
if(this.look && this.look.content() == ':') { | ||
node2.add( | ||
this.match(), | ||
this.value() | ||
); | ||
} | ||
else { | ||
node2.add(this.match(';')); | ||
} | ||
} | ||
break; | ||
} | ||
switch(this.look.content().toLowerCase()) { | ||
@@ -396,3 +432,3 @@ case 'font-family': | ||
} | ||
node.add(this.match(Token.STRING)); | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
node.add(this.match(';')); | ||
@@ -405,7 +441,26 @@ return node; | ||
this.match(), | ||
this.match(Token.ID), | ||
this.match('('), | ||
this.match(')'), | ||
this.block() | ||
this.match([Token.ID, Token.PROPERTY]), | ||
this.match('(') | ||
); | ||
if(this.look | ||
&& (this.look.type() == Token.STRING | ||
|| this.look.type() == Token.VARS)) { | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
} | ||
node.add(this.match(')')); | ||
while(this.look && this.look.content() == ',') { | ||
node.add( | ||
this.match(), | ||
this.match([Token.ID, Token.PROPERTY]), | ||
this.match('(') | ||
); | ||
if(this.look | ||
&& (this.look.type() == Token.STRING | ||
|| this.look.type() == Token.VARS)) { | ||
node.add(this.match([Token.VARS, Token.STRING])); | ||
} | ||
} | ||
if(this.look && this.look.content() == '{') { | ||
node.add(this.block()); | ||
} | ||
return node; | ||
@@ -517,3 +572,12 @@ }, | ||
else { | ||
node.add(this.match(), this.match(';')); | ||
node.add(this.match()); | ||
if(this.look && this.look.content() == ':') { | ||
node.add( | ||
this.match(), | ||
this.value() | ||
); | ||
} | ||
else { | ||
node.add(this.match(';')); | ||
} | ||
} | ||
@@ -530,5 +594,9 @@ } | ||
var node = new Node(Node.STYLE); | ||
node.add(this.key(name)); | ||
node.add(this.match(':')); | ||
node.add(this.value()); | ||
var k = this.key(name); | ||
node.add(k); | ||
if(needValue(k) | ||
|| this.look && this.look.content() == ':') { | ||
node.add(this.match(':')); | ||
node.add(this.value()); | ||
} | ||
while(this.look && this.look.type() == Token.HACK) { | ||
@@ -547,3 +615,16 @@ node.add(this.match()); | ||
} | ||
node.add(this.match(name || Token.KEYWORD)); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
if(name) { | ||
if(this.look.type() == Token.VARS) { | ||
node.add(this.match()); | ||
} | ||
else { | ||
node.add(this.match(name)); | ||
} | ||
} | ||
else { | ||
node.add(this.match([Token.STRING, Token.KEYWORD])); | ||
} | ||
return node; | ||
@@ -561,2 +642,5 @@ }, | ||
switch(s) { | ||
case 'var': | ||
node.add(this.vars()); | ||
break; | ||
case 'url': | ||
@@ -617,2 +701,5 @@ node.add(this.url()); | ||
switch(s) { | ||
case 'var': | ||
node.add(this.vars()); | ||
break; | ||
case 'url': | ||
@@ -838,7 +925,6 @@ node.add(this.url()); | ||
); | ||
while(this.look && this.look.content() != ')') { | ||
node.add(this.param()); | ||
while(this.look && this.look.content() == ',') { | ||
node.add(this.match()); | ||
node.add(this.param()); | ||
if(this.look && this.look.content() == ',') { | ||
node.add(this.match()); | ||
} | ||
} | ||
@@ -870,2 +956,12 @@ node.add(this.match(')')); | ||
}, | ||
vars: function() { | ||
var node = new Node(Node.VARS); | ||
node.add( | ||
this.match(), | ||
this.match('('), | ||
this.match(), | ||
this.match(')') | ||
); | ||
return node; | ||
}, | ||
rgb: function(alpha) { | ||
@@ -1061,7 +1157,4 @@ var node = new Node(alpha ? Node.RGBA : Node.RGB); | ||
return this.ignores; | ||
}, | ||
invalid: function() { | ||
return this.invalids; | ||
} | ||
}); | ||
module.exports = Parser;}); |
@@ -52,9 +52,22 @@ define(function(require, exports, module) {var Class = require('../util/Class'); | ||
args.forEach(function(node) { | ||
node.parent(self); | ||
var last = self.children[self.children.length - 1]; | ||
if(last) { | ||
last.next(node); | ||
node.prev(last); | ||
if(Array.isArray(node)) { | ||
node.forEach(function(node2) { | ||
node2.parent(self); | ||
var last = self.children[self.children.length - 1]; | ||
if(last) { | ||
last.next(node2); | ||
node2.prev(last); | ||
} | ||
self.children.push(node2); | ||
}); | ||
} | ||
self.children.push(node); | ||
else { | ||
node.parent(self); | ||
var last = self.children[self.children.length - 1]; | ||
if(last) { | ||
last.next(node); | ||
node.prev(last); | ||
} | ||
self.children.push(node); | ||
} | ||
}); | ||
@@ -61,0 +74,0 @@ return self; |
Sorry, the diff of this file is not supported yet
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
531904
81
15565