4 * lexer for parsing ressource source files (*.src)
8 /* enlarge token buffer to tokenize whole strings */
12 /* to enable debug output define LEXDEBUG */
15 #define OUTPUT fprintf
17 #define OUTPUT(Par1,Par2);
20 /* table of possible token ids */
28 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
29 #pragma GCC diagnostic ignored "-Wunused-function"
30 #pragma GCC diagnostic ignored "-Wunused-label"
31 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
33 #elif defined __SINPRO_CC
35 #elif defined _MSC_VER
36 #pragma warning(push, 1)
39 /* external functions (C++ code, declared as extern "C" */
40 extern "C" int WorkOnTokenSet( int, char* );
41 extern "C" FILE * init(int, char **);
42 extern "C" int SetError();
43 extern "C" int GetError();
44 extern "C" void Close();
51 %option never-interactive
60 WorkOnTokenSet( PRAGMA, yytext );
64 WorkOnTokenSet( EMPTYLINE, yytext );
75 WorkOnTokenSet( IGNOREDTOKENS, yytext );
78 char c1 = 0,c2 = yyinput();
83 WorkOnTokenSet( COMMEND, yytext );
84 WorkOnTokenSet( COMMEND, pChar );
88 if ( c1 == '*' && c2 == '/' )
93 WorkOnTokenSet( COMMEND, pChar );
103 WorkOnTokenSet( CONDITION, yytext );
106 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
108 WorkOnTokenSet( DEFINEDRES, yytext );
111 [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{" |
112 [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{" {
113 /* RESSOURCE // String TTT_XX ... */
114 WorkOnTokenSet( RESSOURCE, yytext );
117 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
118 /* SMALRESSOURCE // String ... */
119 WorkOnTokenSet( SMALRESSOURCE, yytext );
122 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? {
123 /* TEXTLINE // TextTyp = "A Text" */
124 WorkOnTokenSet( TEXTLINE, yytext );
127 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?(\n[ \t]*)?=([ \t]*\n)?(([a-zA-Z0-9_]+)|(\".*\")|([ \t\n]*))*\".*\"(([a-zA-Z0-9_]+)|(\".*\")|([ \t\n]*))*; {
128 /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
129 WorkOnTokenSet( LONGTEXTLINE, yytext );
133 /* TEXT // "A Text" */
134 WorkOnTokenSet( TEXT, yytext );
139 WorkOnTokenSet( LEVELUP, yytext );
142 "}"[ \t]*;([ \t]*\\)? {
144 WorkOnTokenSet( LEVELDOWN, yytext );
147 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
148 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
149 WorkOnTokenSet( APPFONTMAPPING, yytext );
152 [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
153 /* TEXTREFID // TextTyp = 12345 */
154 WorkOnTokenSet( TEXTREFID, yytext );
157 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
158 [a-zA-Z0-9_]+[ \t]*"=".* {
159 /* ASSIGNMENT Typ = ... */
160 WorkOnTokenSet( ASSIGNMENT, yytext );
165 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
166 /* LISTASSIGNMENT Typ [ ... ] = ... */
167 WorkOnTokenSet( LISTASSIGNMENT, yytext );
170 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* {
171 /* LISTASSIGNMENT Typ [ ... ] = ... */
172 WorkOnTokenSet( LISTASSIGNMENT, yytext );
175 "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{" {
177 WorkOnTokenSet( UIENTRIES, yytext );
180 "<"?[ \t]*L?\".*\".*">" {
182 WorkOnTokenSet( LISTTEXT, yytext );
185 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
186 /* RSCDEFINE #define ... */
187 WorkOnTokenSet( RSCDEFINE, yytext );
190 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
192 WorkOnTokenSet( NORMDEFINE, yytext );
197 WorkOnTokenSet( RSCDEFINELEND, yytext );
200 [a-zA-Z0-9_]+[ \t]*; {
201 /* allowed other tokens like "49 ;" or "SFX_... ;" */
202 WorkOnTokenSet( ANYTOKEN, yytext );
206 WorkOnTokenSet( UNKNOWNCHAR, yytext );
207 /* YYWarning( "Unknown Char" ); */
210 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
212 WorkOnTokenSet( _LISTTEXT, yytext );
217 /*****************************************************************************/
219 /*****************************************************************************/
224 /*****************************************************************************/
225 void YYWarning( const char *s )
226 /*****************************************************************************/
228 /* write warning to stderr */
229 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
232 /*****************************************************************************/
233 void yyerror( const char *s )
234 /*****************************************************************************/
236 /* write error to stderr */
237 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
241 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
243 yyin = init(argc, argv);