Add strip lex helper method
This commit is contained in:
Vendored
+13
-7
@@ -564,13 +564,19 @@ pushState:function begin(condition) {
|
||||
lexer.options = {};
|
||||
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
|
||||
|
||||
|
||||
function strip(start, end) {
|
||||
return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng-end);
|
||||
}
|
||||
|
||||
|
||||
var YYSTATE=YY_START
|
||||
switch($avoiding_name_collisions) {
|
||||
case 0:yy_.yytext = "\\"; return 14;
|
||||
break;
|
||||
case 1:
|
||||
if(yy_.yytext.slice(-1) !== "\\") this.begin("mu");
|
||||
if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu");
|
||||
if(yy_.yytext.slice(-1) === "\\") strip(0,1), this.begin("emu");
|
||||
if(yy_.yytext) return 14;
|
||||
|
||||
break;
|
||||
@@ -578,11 +584,11 @@ case 2:return 14;
|
||||
break;
|
||||
case 3:
|
||||
if(yy_.yytext.slice(-1) !== "\\") this.popState();
|
||||
if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1);
|
||||
if(yy_.yytext.slice(-1) === "\\") strip(0,1);
|
||||
return 14;
|
||||
|
||||
break;
|
||||
case 4:yy_.yytext = yy_.yytext.substr(0, yy_.yyleng-4); this.popState(); return 15;
|
||||
case 4:strip(0,4); this.popState(); return 15;
|
||||
break;
|
||||
case 5:return 25;
|
||||
break;
|
||||
@@ -600,7 +606,7 @@ case 11:return 22;
|
||||
break;
|
||||
case 12:this.popState(); this.begin('com');
|
||||
break;
|
||||
case 13:yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15;
|
||||
case 13:strip(3,5); this.popState(); return 15;
|
||||
break;
|
||||
case 14:return 22;
|
||||
break;
|
||||
@@ -618,9 +624,9 @@ case 20:this.popState(); return 24;
|
||||
break;
|
||||
case 21:this.popState(); return 18;
|
||||
break;
|
||||
case 22:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 32;
|
||||
case 22:yy_.yytext = strip(1,2).replace(/\\"/g,'"'); return 32;
|
||||
break;
|
||||
case 23:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\'/g,"'"); return 32;
|
||||
case 23:yy_.yytext = strip(1,2).replace(/\\'/g,"'"); return 32;
|
||||
break;
|
||||
case 24:return 40;
|
||||
break;
|
||||
@@ -632,7 +638,7 @@ case 27:return 33;
|
||||
break;
|
||||
case 28:return 38;
|
||||
break;
|
||||
case 29:yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 38;
|
||||
case 29:yy_.yytext = strip(1,2); return 38;
|
||||
break;
|
||||
case 30:return 'INVALID';
|
||||
break;
|
||||
|
||||
+16
-8
@@ -1,6 +1,15 @@
|
||||
|
||||
%x mu emu com
|
||||
|
||||
%{
|
||||
|
||||
function strip(start, end) {
|
||||
return yytext = yytext.substr(start, yyleng-end);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
/*
|
||||
ID is the inverse of control characters.
|
||||
Control characters ranges:
|
||||
@@ -17,7 +26,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]
|
||||
"\\\\"/("{{") yytext = "\\"; return 'CONTENT';
|
||||
[^\x00]*?/("{{") {
|
||||
if(yytext.slice(-1) !== "\\") this.begin("mu");
|
||||
if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1), this.begin("emu");
|
||||
if(yytext.slice(-1) === "\\") strip(0,1), this.begin("emu");
|
||||
if(yytext) return 'CONTENT';
|
||||
}
|
||||
|
||||
@@ -25,11 +34,11 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]
|
||||
|
||||
<emu>[^\x00]{2,}?/("{{"|<<EOF>>) {
|
||||
if(yytext.slice(-1) !== "\\") this.popState();
|
||||
if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1);
|
||||
if(yytext.slice(-1) === "\\") strip(0,1);
|
||||
return 'CONTENT';
|
||||
}
|
||||
|
||||
<com>[\s\S]*?"--}}" yytext = yytext.substr(0, yyleng-4); this.popState(); return 'COMMENT';
|
||||
<com>[\s\S]*?"--}}" strip(0,4); this.popState(); return 'COMMENT';
|
||||
|
||||
<mu>"{{>" return 'OPEN_PARTIAL';
|
||||
<mu>"{{#" return 'OPEN_BLOCK';
|
||||
@@ -39,7 +48,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]
|
||||
<mu>"{{{" return 'OPEN_UNESCAPED';
|
||||
<mu>"{{&" return 'OPEN';
|
||||
<mu>"{{!--" this.popState(); this.begin('com');
|
||||
<mu>"{{!"[\s\S]*?"}}" yytext = yytext.substr(3,yyleng-5); this.popState(); return 'COMMENT';
|
||||
<mu>"{{!"[\s\S]*?"}}" strip(3,5); this.popState(); return 'COMMENT';
|
||||
<mu>"{{" return 'OPEN';
|
||||
|
||||
<mu>"=" return 'EQUALS';
|
||||
@@ -49,8 +58,8 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]
|
||||
<mu>\s+ /*ignore whitespace*/
|
||||
<mu>"}}}" this.popState(); return 'CLOSE_UNESCAPED';
|
||||
<mu>"}}" this.popState(); return 'CLOSE';
|
||||
<mu>'"'("\\"["]|[^"])*'"' yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING';
|
||||
<mu>"'"("\\"[']|[^'])*"'" yytext = yytext.substr(1,yyleng-2).replace(/\\'/g,"'"); return 'STRING';
|
||||
<mu>'"'("\\"["]|[^"])*'"' yytext = strip(1,2).replace(/\\"/g,'"'); return 'STRING';
|
||||
<mu>"'"("\\"[']|[^'])*"'" yytext = strip(1,2).replace(/\\'/g,"'"); return 'STRING';
|
||||
<mu>"@" return 'DATA';
|
||||
<mu>"true"/[}\s] return 'BOOLEAN';
|
||||
<mu>"false"/[}\s] return 'BOOLEAN';
|
||||
@@ -58,8 +67,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]
|
||||
|
||||
<mu>{ID} return 'ID';
|
||||
|
||||
<mu>'['[^\]]*']' yytext = yytext.substr(1, yyleng-2); return 'ID';
|
||||
<mu>'['[^\]]*']' yytext = strip(1,2); return 'ID';
|
||||
<mu>. return 'INVALID';
|
||||
|
||||
<INITIAL,mu><<EOF>> return 'EOF';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user