diff options
Diffstat (limited to 'src/build.l')
| -rw-r--r-- | src/build.l | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/src/build.l b/src/build.l deleted file mode 100644 index 9065a49..0000000 --- a/src/build.l +++ /dev/null | |||
| @@ -1,173 +0,0 @@ | |||
| 1 | %{ | ||
| 2 | # include <string> | ||
| 3 | # include <string.h> | ||
| 4 | # include "buildparser.h" | ||
| 5 | # include "build.tab.h" | ||
| 6 | |||
| 7 | char *stringdup( const char *sin ) | ||
| 8 | { | ||
| 9 | char *n = new char[strlen(sin)+1]; | ||
| 10 | strcpy( n, sin ); | ||
| 11 | return n; | ||
| 12 | } | ||
| 13 | |||
| 14 | std::string strbuf; | ||
| 15 | %} | ||
| 16 | |||
| 17 | %x strsq | ||
| 18 | %x strdq | ||
| 19 | %x cmdstr | ||
| 20 | %x comment | ||
| 21 | %option noyywrap nounput batch debug | ||
| 22 | |||
| 23 | %{ | ||
| 24 | # define YY_USER_ACTION yylloc->last_column += yyleng; | ||
| 25 | %} | ||
| 26 | %% | ||
| 27 | |||
| 28 | [,:=[\]()] return yytext[0]; | ||
| 29 | "+=" return TOK_ADDSET; | ||
| 30 | |||
| 31 | "default" return TOK_DEFAULT; | ||
| 32 | "action" return TOK_ACTION; | ||
| 33 | "rule" return TOK_RULE; | ||
| 34 | "requires" return TOK_REQUIRES; | ||
| 35 | "set" return TOK_SET; | ||
| 36 | "matches" return TOK_MATCHES; | ||
| 37 | "perform" return TOK_PERFORM; | ||
| 38 | "produces" return TOK_PRODUCES; | ||
| 39 | "check" return TOK_CHECK; | ||
| 40 | "clean" return TOK_CLEAN; | ||
| 41 | "target" return TOK_TARGET; | ||
| 42 | "input" return TOK_INPUT; | ||
| 43 | "filter" return TOK_FILTER; | ||
| 44 | "prefix" return TOK_PREFIX; | ||
| 45 | "aggregate" return TOK_AGGREGATE; | ||
| 46 | "group" return TOK_GROUP; | ||
| 47 | |||
| 48 | \n+ { | ||
| 49 | yylloc->last_line += yyleng; | ||
| 50 | yylloc->first_line = yylloc->last_line; | ||
| 51 | yylloc->first_column = yylloc->last_column = 0; | ||
| 52 | } | ||
| 53 | |||
| 54 | [ \t\r]* { | ||
| 55 | yylloc->first_line = yylloc->last_line; | ||
| 56 | yylloc->first_column = yylloc->last_column+1; | ||
| 57 | } | ||
| 58 | |||
| 59 | "#".* /* single line comment */ | ||
| 60 | |||
| 61 | [a-zA-Z][a-zA-Z0-9]* { | ||
| 62 | { | ||
| 63 | if( bld.isTarget( yytext ) ) | ||
| 64 | { | ||
| 65 | yylval->strval = stringdup( yytext ); | ||
| 66 | return TARGETTYPE; | ||
| 67 | } | ||
| 68 | else if( bld.isPerform( yytext ) ) | ||
| 69 | { | ||
| 70 | yylval->strval = stringdup( yytext ); | ||
| 71 | return PERFORM; | ||
| 72 | } | ||
| 73 | else if( bld.isFunction( yytext ) ) | ||
| 74 | { | ||
| 75 | yylval->strval = stringdup( yytext ); | ||
| 76 | return FUNCTION; | ||
| 77 | } | ||
| 78 | bld.error( yylloc, "Invalid token" ); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | \" { | ||
| 83 | BEGIN( strdq ); | ||
| 84 | strbuf = ""; | ||
| 85 | } | ||
| 86 | \' { | ||
| 87 | BEGIN( strsq ); | ||
| 88 | strbuf = ""; | ||
| 89 | } | ||
| 90 | \` { | ||
| 91 | BEGIN( cmdstr ); | ||
| 92 | strbuf = ""; | ||
| 93 | } | ||
| 94 | |||
| 95 | <strdq>[^\\\n\"]+ { | ||
| 96 | strbuf += yytext; | ||
| 97 | } | ||
| 98 | |||
| 99 | <strsq>[^\\\n\']+ { | ||
| 100 | strbuf += yytext; | ||
| 101 | } | ||
| 102 | |||
| 103 | <cmdstr>[^\\\n\`]+ { | ||
| 104 | strbuf += yytext; | ||
| 105 | } | ||
| 106 | |||
| 107 | <strdq,strsq,cmdstr>\\n strbuf += "\n"; | ||
| 108 | <strdq,strsq,cmdstr>\\t strbuf += "\t"; | ||
| 109 | <strdq,strsq,cmdstr>\\r strbuf += "\r"; | ||
| 110 | <strdq,strsq,cmdstr>\\b strbuf += "\b"; | ||
| 111 | <strdq,strsq,cmdstr>\\f strbuf += "\f"; | ||
| 112 | <strdq,strsq,cmdstr>\\\\ strbuf += "\\"; | ||
| 113 | <strdq,strsq,cmdstr>\\\" strbuf += "\""; | ||
| 114 | <strdq,strsq,cmdstr>\\\' strbuf += "\'"; | ||
| 115 | <strdq,strsq,cmdstr>\\\` strbuf += "`"; | ||
| 116 | <strdq,strsq,cmdstr>\\. bld.error( yylloc, "Invalid escape sequence."); | ||
| 117 | |||
| 118 | <strdq>\" { | ||
| 119 | BEGIN( INITIAL ); | ||
| 120 | yylval->strval = stringdup( strbuf.c_str() ); | ||
| 121 | return STRING; | ||
| 122 | } | ||
| 123 | |||
| 124 | <strsq>\' { | ||
| 125 | BEGIN( INITIAL ); | ||
| 126 | yylval->strval = stringdup( strbuf.c_str() ); | ||
| 127 | return STRING; | ||
| 128 | } | ||
| 129 | |||
| 130 | <cmdstr>\` { | ||
| 131 | BEGIN( INITIAL ); | ||
| 132 | FILE *fpg = popen( strbuf.c_str(), "r" ); | ||
| 133 | strbuf = ""; | ||
| 134 | for(;;) | ||
| 135 | { | ||
| 136 | char buf[1024]; | ||
| 137 | int nRead = fread( buf, 1, 1024, fpg ); | ||
| 138 | if( nRead == 0 ) break; | ||
| 139 | for( int j = 0; j < nRead; j++ ) | ||
| 140 | { | ||
| 141 | if( buf[j] == '\n' || buf[j] == '\r' ) | ||
| 142 | buf[j] = ' '; | ||
| 143 | } | ||
| 144 | strbuf.append( buf, nRead ); | ||
| 145 | if( nRead < 1024 ) break; | ||
| 146 | } | ||
| 147 | yylval->strval = stringdup( strbuf.c_str() ); | ||
| 148 | pclose( fpg ); | ||
| 149 | return STRING; | ||
| 150 | } | ||
| 151 | |||
| 152 | . { | ||
| 153 | char buf[] = {"Character x is out of place"}; | ||
| 154 | buf[10] = yytext[0]; | ||
| 155 | bld.error( yylloc, buf ); | ||
| 156 | } | ||
| 157 | |||
| 158 | %% | ||
| 159 | |||
| 160 | void BuildParser::scanBegin() | ||
| 161 | { | ||
| 162 | yy_flex_debug = false; | ||
| 163 | if( !(yyin = fopen( file.c_str(), "r" )) ) | ||
| 164 | { | ||
| 165 | error( std::string("cannot open file: ") + file ); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | void BuildParser::scanEnd() | ||
| 170 | { | ||
| 171 | fclose( yyin ); | ||
| 172 | } | ||
| 173 | |||
