%{ # 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; "create" return TOK_CREATE; "file" return TOK_FILE; "from" return TOK_FROM; "files" return TOK_FILES; "in" return TOK_IN; "using" return TOK_USING; "rule" return TOK_RULE; "requires" return TOK_REQUIRES; "for" return TOK_FOR; "set" return TOK_SET; "matches" return TOK_MATCHES; "matching" return TOK_MATCHING; "all" return TOK_ALL; "one" return TOK_ONE; "perform" return TOK_PERFORM; "produces" return TOK_PRODUCES; "command" return TOK_COMMAND; "check" return TOK_CHECK; "clean" return TOK_CLEAN; "directories" return TOK_DIRECTORIES; "targets" return TOK_TARGETS; "..."\n { yylloc->last_line += yyleng; yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column = 0; } \n+ { yylloc->last_line += yyleng; yylloc->first_line = yylloc->last_line; yylloc->first_column = yylloc->last_column = 0; return TOK_EOL; } [ \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 */ [^ \t\r\n\'\":+=,/][^ \t\r\n\'\":+=,]* { yylval->strval = stringdup( yytext ); return STRING; } [^ \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; } %% 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 ); }