diff options
author | Lennart Poettering <lennart@poettering.net> | 2005-11-21 23:44:56 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2005-11-21 23:44:56 +0000 |
commit | b4b06a5275762a16e3f74fdc8626adff647a5129 (patch) | |
tree | 84046c665c81ab3095e76c859d0d298e48722c98 | |
parent | 139375b1124e4d74a71f444161604d7877d6a764 (diff) |
beef up lexer a little
git-svn-id: file:///home/lennart/svn/public/sse/trunk@18 5fbabb74-0606-0410-a5e4-b5cc6a42724e
-rw-r--r-- | feed/Makefile | 3 | ||||
-rw-r--r-- | feed/sse_lex_c.l | 78 | ||||
-rw-r--r-- | feed/test-lex-c.c | 17 |
3 files changed, 63 insertions, 35 deletions
diff --git a/feed/Makefile b/feed/Makefile index aeb8883..94c2540 100644 --- a/feed/Makefile +++ b/feed/Makefile @@ -1,4 +1,5 @@ -CLAGS=-Wextra -g -O2 -pipe +CFLAGS=-Wextra -O3 -pipe +#CFLAGS=-Wextra -g -O0 -pipe LIBS=-lfl all: sse_lex_c diff --git a/feed/sse_lex_c.l b/feed/sse_lex_c.l index 52f46a7..4674b73 100644 --- a/feed/sse_lex_c.l +++ b/feed/sse_lex_c.l @@ -4,6 +4,48 @@ #include <stdio.h> +static void print_with_subwords(const char *w) { + const char *e; + + printf("%s\n", w); + + if ((e = strchr(w, '_'))) { + + /* Split at dashes.*/ + + do { + for (; *e == '_'; e++); + + if (strlen(e) < 3) + break; + + printf("S:%s\n", e); + + e = strchr(e, '_'); + } while (e); + + } else { + + /* Split a place where an uppercase letter follows a lowercase + * letter */ + + e = w; + for (;;) { + for (; *e && !(islower(*e) && isupper(*(e+1))); e++); + + if (!*e) + break; + + e++; + + if (strlen(e) < 3) + break; + + printf("S:%s\n", e); + } + } + +} %} @@ -46,40 +88,7 @@ NIDCHAR [^_a-zA-Z0-9] <CHAR>. ; <CHARESC>. { BEGIN CHAR; } -<DEF>auto{NIDCHAR} | -<DEF>break{NIDCHAR} | -<DEF>case{NIDCHAR} | -<DEF>char{NIDCHAR} | -<DEF>const{NIDCHAR} | -<DEF>continue{NIDCHAR} | -<DEF>default{NIDCHAR} | -<DEF>do{NIDCHAR} | -<DEF>double{NIDCHAR} | -<DEF>else{NIDCHAR} | -<DEF>enum{NIDCHAR} | -<DEF>extern{NIDCHAR} | -<DEF>float{NIDCHAR} | -<DEF>for{NIDCHAR} | -<DEF>goto{NIDCHAR} | -<DEF>if{NIDCHAR} | -<DEF>int{NIDCHAR} | -<DEF>long{NIDCHAR} | -<DEF>register{NIDCHAR} | -<DEF>return{NIDCHAR} | -<DEF>short{NIDCHAR} | -<DEF>signed{NIDCHAR} | -<DEF>sizeof{NIDCHAR} | -<DEF>static{NIDCHAR} | -<DEF>struct{NIDCHAR} | -<DEF>switch{NIDCHAR} | -<DEF>typedef{NIDCHAR} | -<DEF>union{NIDCHAR} | -<DEF>unsigned{NIDCHAR} | -<DEF>void{NIDCHAR} | -<DEF>volatile{NIDCHAR} | -<DEF>while{NIDCHAR} { yyless(yyleng-1); } - -<DEF>[a-zA-Z_][a-zA-Z_0-9]{3,} { printf("%s\n", yytext); } +<DEF>[a-zA-Z_][a-zA-Z_0-9]{3,} { print_with_subwords(yytext); } <DEF>[0-9]+ ; <DEF>0x[0-9a-fA-F]+ ; @@ -89,6 +98,7 @@ NIDCHAR [^_a-zA-Z0-9] %% + int main(int argc, char *argv[]) { if (argc <= 1) diff --git a/feed/test-lex-c.c b/feed/test-lex-c.c index d43f10f..9b984bb 100644 --- a/feed/test-lex-c.c +++ b/feed/test-lex-c.c @@ -118,3 +118,20 @@ int main(int argc, char argv[]) { FOO_BAR(blafasel); } + + + + dies_ist_ein_test +___DIES___IST___EIN__TEST_______ + + alpha beta gamma + _________ + + + DiesIstEinTest + + Dies_Ist_Ein_Test___ + + ArschTritt + + deppVomLande |