%{ # include # include "builder.h" # include "build.tab.h" # include "stringrep.h" std::string strbuf; %} %x regexp %x strsq %x strdq %x comment %option noyywrap nounput batch debug %{ # define YY_USER_ACTION yylloc->last_column += yyleng; %} %% [,:=[\]()] return yytext[0]; "+=" return TOK_ADDSET; "default" return TOK_DEFAULT; "action" return TOK_ACTION; "rule" return TOK_RULE; "requires" return TOK_REQUIRES; "set" return TOK_SET; "matches" return TOK_MATCHES; "perform" return TOK_PERFORM; "produces" return TOK_PRODUCES; "check" return TOK_CHECK; "clean" return TOK_CLEAN; "target" return TOK_TARGET; "input" return TOK_INPUT; \n+ { yylloc->last_line += yyleng; yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column = 0; } [ \t\r]* { yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column+1; } "/" { BEGIN( regexp ); strbuf = ""; } [^\n/\\]* strbuf += yytext; "\\/" strbuf += "/"; "\\" strbuf += "\\"; "/" { BEGIN( INITIAL ); yylval->strval = stringdup( strbuf.c_str() ); return REGEXP; } "#".* /* single line comment */ [a-zA-Z][a-zA-Z0-9]* { { yylval->tval = bld.getTargetType( yytext ); if( yylval->tval >= 0 ) { return TARGETTYPE; } else if( bld.isFunction( yytext ) ) { yylval->strval = stringdup( yytext ); return FUNCTION; } bld.error( yylloc, "Invalid token" ); } } [^ \t\r\n\'\":=,/][^ \t\r\n\'\"=,]+[^ \t\r\n\'\":=,] { yylval->strval = stringdup( yytext ); return STRING; } \" { BEGIN( strdq ); strbuf = ""; } \' { BEGIN( strsq ); strbuf = ""; } [^\\\n\"]+ { strbuf += yytext; } [^\\\n\']+ { strbuf += yytext; } \\n strbuf += "\n"; \\t strbuf += "\t"; \\r strbuf += "\r"; \\b strbuf += "\b"; \\f strbuf += "\f"; \" { BEGIN( INITIAL ); yylval->strval = stringdup( strbuf.c_str() ); return STRING; } \' { BEGIN( INITIAL ); yylval->strval = stringdup( strbuf.c_str() ); return STRING; } . { bld.error( yylloc, "Invalid character found!" ); } %% void Builder::scanBegin() { yy_flex_debug = false; if( !(yyin = fopen( file.c_str(), "r" )) ) { error( std::string("cannot open file: ") + file ); } } void Builder::scanEnd() { fclose( yyin ); }