homunculus
Advanced tools
Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "homunculus", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
@@ -17,14 +17,29 @@ var Match = require('./Match'); | ||
if(this.begin == code.substr(--index, this.begin.length)) { | ||
var i = code.indexOf(this.end, index + this.begin.length); | ||
if(i == -1) { | ||
if(this.contain) { | ||
this.msg = 'SyntaxError: unterminated ' + Token.type(this.type).toLowerCase(); | ||
//支持多个end匹配时不支持包含选项 | ||
if(!this.contain && Array.isArray(this.end)) { | ||
for(var j = 0, len = this.end.length; j < len; j++) { | ||
var i = code.indexOf(this.end[j], index + this.begin.length); | ||
if(i != -1) { | ||
this.result = code.slice(index, i); | ||
return true; | ||
} | ||
} | ||
i = code.length; | ||
//都不匹配时到末尾 | ||
this.result = code.slice(index); | ||
return true; | ||
} | ||
else if(this.contain) { | ||
i += this.end.length; | ||
else { | ||
var i = code.indexOf(this.end, index + this.begin.length); | ||
if(i == -1) { | ||
if(this.contain) { | ||
this.msg = 'SyntaxError: unterminated ' + Token.type(this.type).toLowerCase(); | ||
} | ||
i = code.length; | ||
} | ||
else if(this.contain) { | ||
i += this.end.length; | ||
} | ||
this.result = code.slice(index, i); | ||
return true; | ||
} | ||
this.result = code.slice(index, i); | ||
return true; | ||
} | ||
@@ -31,0 +46,0 @@ return false; |
@@ -16,6 +16,7 @@ var Rule = require('./Rule'); | ||
self.addMatch(new CompleteEqual(Token.TAB, character.TAB)); | ||
self.addMatch(new CompleteEqual(Token.ENTER, character.ENTER)); | ||
self.addMatch(new CompleteEqual(Token.LINE, character.ENTER + character.LINE)); | ||
self.addMatch(new CompleteEqual(Token.LINE, character.ENTER)); | ||
self.addMatch(new CompleteEqual(Token.LINE, character.LINE)); | ||
self.addMatch(new LineSearch(Token.COMMENT, '//', '\n')); | ||
self.addMatch(new LineSearch(Token.COMMENT, '//', [character.ENTER + character.LINE, character.ENTER, character.LINE])); | ||
self.addMatch(new LineSearch(Token.COMMENT, '/*', '*/', true)); | ||
@@ -38,3 +39,3 @@ self.addMatch(new LineParse(Token.STRING, '"', '"', false, Lexer.IS_REG)); | ||
['*=', '/=', '+=', '-=', '%=', '^=', '&=', '|=', '&&', '--', '++', '===', '==', '!==', '!=', '||', '>>>=', '<<<=', '<<<', '>>>', '>>=', '<<=', '<<', '>>', '>=', '<=', '...', '?:'].forEach(function(o) { | ||
['*=', '/=', '+=', '-=', '%=', '^=', '&=', '|=', '&&', '--', '++', '===', '==', '!==', '!=', '||', '>>>=', '<<<=', '<<<', '>>>', '>>=', '<<=', '<<', '>>', '>=', '<=', '...', '?:', '=>'].forEach(function(o) { | ||
self.addMatch(new CompleteEqual(Token.SIGN, o, Lexer.IS_REG)); | ||
@@ -51,6 +52,8 @@ }); | ||
self.addMatch(new CharacterSet(Token.BLANK, '\u00a0\f\u000b\u200b\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000')); | ||
self.addMatch(new CompleteEqual(Token.LINE, '\u2028')); | ||
self.addMatch(new CompleteEqual(Token.LINE, '\u2029')); | ||
self.addMatch(new CharacterSet(Token.BLANK, '\f\u000b\u00A0\uFEFF\u200b\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000')); | ||
}).statics({ | ||
KEYWORDS: 'abstract boolean break byte case catch class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with'.split(' ') | ||
KEYWORDS: 'boolean break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw throws true try typeof var void while with'.split(' ') | ||
}); | ||
module.exports = EcmascriptRule; |
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
1381826
26356