%{ # include # include "builder.h" # include "build.tab.h" # include "stringrep.h" std::string strbuf; %} %x strsq %x strdq %x comment %option noyywrap nounput batch debug %{ # define YY_USER_ACTION yylloc->columns (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; "all" return TOK_ALL; "one" return TOK_ONE; "perform" return TOK_PERFORM; "produces" return TOK_PRODUCES; "command" return TOK_COMMAND; "..."\n /* elipsis line continuation */ \n+ return TOX_EOL; [ \t\r]* /* whitespace */ \/\/.* /* single line comment */ "#".* /* single line comment */ [^ \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() { if( !(yyin = fopen( file.c_str(), "r" )) ) error( std::string("cannot open ") + file ); } void Builder::scanEnd() { fclose( yyin ); }