%s NORMAL QUOTE1 QUOTE2 QUOTE3 %{ /* * $Header: /usr/build/vile/vile/filters/RCS/py-filt.l,v 1.11 2003/05/20 20:38:41 tom Exp $ * * Filter to add vile "attribution" sequences to a Python script */ #include DefineFilter("py"); static char *Comment_attr; static char *Ident2_attr; static char *Keyword_attr; static char *Number_attr; static char *String_attr; %} COMMENT #.*\n KEYWORD [a-zA-Z_][a-zA-Z0-9_]* SIGN [-+] DECIMAL [0-9_]+ OCTAL 0[0-7_]+ HEXADECIMAL 0x[0-9a-fA-F_]+ REAL [-+]?([0-9_]*\.[0-9][0-9_]*)([eE][+-]?[0-9_]+)? NUMBER {SIGN}?({DECIMAL}|{OCTAL}|{HEXADECIMAL})[L]?|{REAL} %% {KEYWORD} { WriteToken(keyword_attr(yytext)); } {COMMENT} { WriteToken(Comment_attr); } {NUMBER} { WriteToken(Number_attr); } \' { BeginQuote(QUOTE1, String_attr); } \' { FinishQuote(NORMAL); } (\\.|.) { flt_bfr_append(yytext, yyleng); } [\n] { flt_bfr_append(yytext, yyleng); } \" { BeginQuote(QUOTE2, String_attr); } \" { FinishQuote(NORMAL); } (\\.|.) { flt_bfr_append(yytext, yyleng); } [\n] { flt_bfr_append(yytext, yyleng); } \"\"\" { BeginQuote(QUOTE3, String_attr); } \"\"\" { FinishQuote(NORMAL); } (\\.|.) { flt_bfr_append(yytext, yyleng); } [\n] { flt_bfr_append(yytext, yyleng); } . { ECHO; } %% static void init_filter(int before GCC_UNUSED) { } static void do_filter(FILE *inputs) { yyin = inputs; Comment_attr = class_attr(NAME_COMMENT); Ident2_attr = class_attr(NAME_IDENT2); Keyword_attr = class_attr(NAME_KEYWORD); Number_attr = class_attr(NAME_NUMBER); String_attr = class_attr(NAME_LITERAL); BEGIN(NORMAL); while (yylex() > 0) { } flt_bfr_finish(); }