From: nishi Date: Wed, 19 Jun 2024 01:07:08 +0000 (+0000) Subject: escape seq works X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5d5f52cef34275595efd45d3afd3ace63a894371;p=dataworks.git escape seq works git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@358 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Grammar/dw.l b/Grammar/dw.l index c8099f1..0e08627 100644 --- a/Grammar/dw.l +++ b/Grammar/dw.l @@ -38,6 +38,37 @@ extern YYSTYPE yylval; double __dw_atof(const char* str); char* __dw_strcat(const char* a, const char* b); char* str = NULL; + +void proc_esc(void){ + if(yytext[1] == 'x'){ + char cbuf[2]; + int ch = 0; + if(yytext[2] >= '0' && yytext[2] <= '9'){ + ch |= yytext[2] - '0'; + }else if(yytext[2] >= 'a' && yytext[2] <= 'f'){ + ch |= yytext[2] - 'a' + 10; + }else if(yytext[2] >= 'A' && yytext[2] <= 'F'){ + ch |= yytext[2] - 'A' + 10; + } + ch = ch << 4; + if(yytext[3] >= '0' && yytext[3] <= '9'){ + ch |= yytext[3] - '0'; + }else if(yytext[3] >= 'a' && yytext[3] <= 'f'){ + ch |= yytext[3] - 'a' + 10; + }else if(yytext[3] >= 'A' && yytext[3] <= 'F'){ + ch |= yytext[3] - 'A' + 10; + } + cbuf[0] = ch; + cbuf[1] = 0; + char* tmp = str; + str = __dw_strcat(tmp, cbuf); + free(tmp); + }else{ + char* tmp = str; + str = __dw_strcat(tmp, yytext + 1); + free(tmp); + } +} %} %x DQ SQ @@ -53,10 +84,8 @@ char* str = NULL; str = __dw_strcat(tmp, yytext); free(tmp); } -\\. { - char* tmp = str; - str = __dw_strcat(tmp, yytext + 1); - free(tmp); +\\(x[0-9a-fA-F]{2}|.) { + proc_esc(); } \" { yylval.node.string = strdup(str); @@ -77,10 +106,8 @@ char* str = NULL; str = __dw_strcat(tmp, yytext); free(tmp); } -\\. { - char* tmp = str; - str = __dw_strcat(tmp, yytext + 1); - free(tmp); +\\(x[0-9a-fA-F]{2}|.) { + proc_esc(); } \' { yylval.node.string = strdup(str);