- Timestamp:
- 04/16/14 19:28:15 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/framscript.l
r221 r224 11 11 #define YY_NEVER_INTERACTIVE 1 12 12 13 static SString quote DoubleQuotes(const SString &src);13 static SString quoteMultiline(const SString &src); 14 14 15 15 %} … … 19 19 %x asmcode2 20 20 %x comment 21 %x heredoc21 %x multiline 22 22 23 23 %% … … 31 31 "null" {framscriptlval.setEmpty(); return CONSTANT;} 32 32 \"([^\\\"]|\\.)*\" {framscriptlval.setString(SString(yytext+1,yyleng-2));return CONSTANT;} 33 "<<<".*\n {trctx.herelimit=SString(yytext+3,yyleng-4); trctx.tmp=""; BEGIN heredoc; } 33 \"\"\" {trctx.tmp=""; trctx.multilimit='\"'; BEGIN multiline;} 34 "'''" {trctx.tmp=""; trctx.multilimit='\''; BEGIN multiline;} 34 35 "@line "[0-9]+\n {trctx.line=atol(yytext+6);} 35 36 "@file "[^\n\t\r]+\n {trctx.srcname=SString(yytext+6,yyleng-7);} … … 71 72 <comment>\*\/ BEGIN 0; 72 73 <comment>. ; 73 <heredoc>[^\n]*\n { 74 trctx.line++; 75 SString tmp(yytext,yyleng-1); 76 if (tmp==trctx.herelimit) 77 { framscriptlval.setString(quoteDoubleQuotes(trctx.tmp)); BEGIN 0; return CONSTANT;} 74 <multiline>.* { 75 char* end=strstr(yytext,trctx.multilimit=='\"' ? "\"\"\"" : "'''"); 76 if (end) 77 { 78 trctx.tmp+=SString(yytext,end-yytext); 79 framscriptlval.setString(quoteMultiline(trctx.tmp)); 80 yyless((end-yytext)+3); 81 BEGIN 0; 82 return CONSTANT; 83 } 78 84 else 79 { trctx.tmp+=tmp; trctx.tmp+="\n";}85 trctx.tmp+=SString(yytext,yyleng); 80 86 } 87 <multiline>\n {trctx.line++; trctx.tmp+="\n";} 81 88 [ \t\r\f] ; 82 89 \n {trctx.line++;} … … 102 109 %% 103 110 104 //exclusively for heredoc, but it should not be needed, there is some unexpected difference between quoting \n and \" in framscript parsing (TODO)105 static SString quote DoubleQuotes(const SString &src)111 //exclusively for multiline, but it should not be needed, there is some unexpected difference between quoting \n and \" in framscript parsing (TODO) 112 static SString quoteMultiline(const SString &src) 106 113 { 107 114 int len=src.len(); … … 110 117 while(len>0) 111 118 { 112 if (*t=='\"') 113 ret+="\\\""; 114 else 115 ret+=*t; 119 switch(*t) 120 { 121 case '\"': ret+="\\\""; break; 122 case '\\': ret+="\\\\"; break; 123 default: ret+=*t; 124 } 116 125 t++; len--; 117 126 }
Note: See TracChangeset
for help on using the changeset viewer.