From: kramm Date: Tue, 6 Jan 2009 21:37:20 +0000 (+0000) Subject: small optimizations, improved regexp handling X-Git-Tag: release-0-9-0~369 X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=3e6fba5b536ae697de61ed6a349dffca6d1de68a;hp=aaf7a97f44b72dc94bb1139654ef089240fea994;p=swftools.git small optimizations, improved regexp handling --- diff --git a/lib/as3/tokenizer.lex b/lib/as3/tokenizer.lex index 47dc605..79cdf8a 100644 --- a/lib/as3/tokenizer.lex +++ b/lib/as3/tokenizer.lex @@ -31,18 +31,6 @@ #include "tokenizer.h" #include "files.h" -static void countlines(char*text, int len) { - int t; - for(t=0;t=0;--t) { if(text[t]!=' ' && - text[t]!='.') + text[t]!=':') break; } char*s = malloc(t+1); @@ -406,10 +395,47 @@ void handleLabel(char*text, int len) avm2_lval.id = s; } +static int handleregexp() +{ + char*s = malloc(yyleng); + int len=yyleng-1; + memcpy(s, yytext+1, len); + s[len] = 0; + int t; + for(t=len;t>=0;--t) { + if(s[t]=='/') { + s[t] = 0; + break; + } + } + avm2_lval.regexp.pattern = s; + if(t==len) { + avm2_lval.regexp.options = 0; + } else { + avm2_lval.regexp.options = s+t+1; + } + return T_REGEXP; +} + void initialize_scanner(); #define YY_USER_INIT initialize_scanner(); -#define c() {countlines(yytext, yyleng);} +/* count the number of lines+columns consumed by this token */ +static inline void l() { + int t; + for(t=0;t{ -{REGEXP} {c(); BEGIN(INITIAL);return m(T_REGEXP);} +{REGEXP} {c(); BEGIN(INITIAL);return handleregexp();} {HEXWITHSIGN} {c(); BEGIN(INITIAL);return handlehex();} {INTWITHSIGN} {c(); BEGIN(INITIAL);return handleint();} {FLOATWITHSIGN} {c(); BEGIN(INITIAL);return handlefloat();} } \xef\xbb\xbf {/* utf 8 bom */} -{S} {c();} +{S} {l();} {HEXINT} {c(); BEGIN(INITIAL);return handlehex();} {INT} {c(); BEGIN(INITIAL);return handleint();} @@ -466,10 +492,10 @@ REGEXP [/]([^/\n]|\\[/])*[/][a-zA-Z]* 3rr0r {/* for debugging: generates a tokenizer-level error */ syntaxerror("3rr0r");} -{NAME}{S}*:{S}*for/{_} {c();handleLabel(yytext, yyleng-3);return T_FOR;} -{NAME}{S}*:{S}*do/{_} {c();handleLabel(yytext, yyleng-2);return T_DO;} -{NAME}{S}*:{S}*while/{_} {c();handleLabel(yytext, yyleng-5);return T_WHILE;} -{NAME}{S}*:{S}*switch/{_} {c();handleLabel(yytext, yyleng-6);return T_SWITCH;} +{NAME}{S}*:{S}*for/{_} {l();handleLabel(yytext, yyleng-3);return T_FOR;} +{NAME}{S}*:{S}*do/{_} {l();handleLabel(yytext, yyleng-2);return T_DO;} +{NAME}{S}*:{S}*while/{_} {l();handleLabel(yytext, yyleng-5);return T_WHILE;} +{NAME}{S}*:{S}*switch/{_} {l();handleLabel(yytext, yyleng-6);return T_SWITCH;} for {c();avm2_lval.id="";return T_FOR;} do {c();avm2_lval.id="";return T_DO;} while {c();avm2_lval.id="";return T_WHILE;} @@ -552,7 +578,7 @@ as {c();return m(KW_AS);} {NAME} {c();BEGIN(INITIAL);return mkid(T_IDENTIFIER);} [+-\/*^~@$!%&\(=\[\]\{\}|?:;,<>] {c();BEGIN(REGEXPOK);return m(yytext[0]);} -[\)\]] {c();BEGIN(INITIAL);return m(yytext[0]);} +[\)\]] {c();BEGIN(INITIAL);return m(yytext[0]);} . {char c1=yytext[0]; char buf[128]; @@ -573,7 +599,7 @@ as {c();return m(KW_AS);} exit(1); yyterminate(); } -<> {c(); +<> {l(); void*b = leave_file(); if (!b) { yyterminate();