xref: /aoo42x/main/l10ntools/source/srclex.l (revision 254802d4)
1 
2 %{
3 /**************************************************************
4  *
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements.  See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership.  The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License.  You may obtain a copy of the License at
12  *
13  *   http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied.  See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  *
22  *************************************************************/
23 /*
24  * lexer for parsing ressource source files (*.src)
25  *
26  */
27 
28 
29 /* enlarge token buffer to tokenize whole strings */
30 #undef YYLMAX
31 #define YYLMAX 64000
32 
33 /* to enable debug output define LEXDEBUG */
34 #define LEXDEBUG		1
35 #ifdef LEXDEBUG
36 #define OUTPUT	fprintf
37 #else
38 #define OUTPUT(Par1,Par2);
39 #endif
40 
41 /* table of possible token ids */
42 #include "tokens.h"
43 #include <stdlib.h>
44 #include <stdio.h>
45 
46 #if defined __GNUC__
47 #pragma GCC system_header
48 #elif defined __SINPRO_CC
49 #pragma disable_warn
50 #elif defined _MSC_VER
51 #pragma warning(push, 1)
52 #endif
53 
54 /* external functions (C++ code, declared as extern "C" */
55 extern int WorkOnTokenSet( int, char* );
56 extern int InitExport( char * , char * );
57 extern int Parse( int nTyp, char *pTokenText );
58 extern int EndExport();
59 extern int SetError();
60 extern int GetError();
61 extern char *GetOutputFile( int argc, char* argv[]);
62 extern FILE *GetNextFile();
63 extern int isQuiet();
64 extern void Close();
65 extern char* getFilename();
66 
67 /* forwards */
68 void YYWarning();
69 %}
70 
71 %p 24000
72 %e 1200
73 %n 500
74 
75 %%
76 
77 ^[\t ]*"#pragma".*	{
78 	WorkOnTokenSet( PRAGMA, yytext );
79 }
80 
81 ^[ \t]*\n {
82 	WorkOnTokenSet( EMPTYLINE, yytext );
83 }
84 
85 [\t ]+ 				|
86 ^[\t ]*"#include".*	|
87 ^[\t ]*"#undef".* 	|
88 "//".*				|
89 ";" 				|
90 "<"					|
91 ">"					|
92 \n	{
93 	WorkOnTokenSet( IGNOREDTOKENS, yytext );
94 }
95 "/*"	{
96 	char c1 = 0, c2 = input();
97 	char pChar[2];
98 	pChar[1] = 0x00;
99 	pChar[0] = c2;
100 
101 	WorkOnTokenSet( COMMENT, yytext );
102 	WorkOnTokenSet( COMMENT, pChar );
103 	for(;;) {
104 		if ( c2 == EOF )
105 			break;
106 		if ( c1 == '*' && c2 == '/' )
107 			break;
108 		c1 = c2;
109 		c2 = input();
110 		pChar[0] = c2;
111 		WorkOnTokenSet( COMMENT, pChar );
112 	}
113 }
114 
115 ^[\t ]*"#ifndef".+$	|
116 ^[\t ]*"#ifdef".+$	|
117 ^[\t ]*"#if".+$		|
118 ^[\t ]*"#elif".*$	|
119 ^[\t ]*"#else".*$	|
120 ^[\t ]*"#endif".*$	{
121 	WorkOnTokenSet( CONDITION, yytext );
122 }
123 
124 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
125 /* defined Res */
126 	WorkOnTokenSet( DEFINEDRES, yytext );
127 }
128 
129 [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{"	|
130 [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{"	{
131 /* RESSOURCE // String TTT_XX ... */
132 	WorkOnTokenSet( RESSOURCE, yytext );
133 }
134 
135 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"?	{
136 /* SMALRESSOURCE // String ... */
137 	WorkOnTokenSet( SMALRESSOURCE, yytext );
138 }
139 
140 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n?	{
141 /* TEXTLINE // TextType = "A Text" */
142 	WorkOnTokenSet( TEXTLINE, yytext );
143 }
144 
145 [\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]*))*;	{
146 /* LONGTEXTLINE // TextType = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
147 	WorkOnTokenSet( LONGTEXTLINE, yytext );
148 }
149 
150 \".*\" {
151 /* TEXT // "A Text" */
152 	WorkOnTokenSet( TEXT, yytext );
153 }
154 
155 "{"[ \t]*\\?	{
156 /* LEVELUP */
157 	WorkOnTokenSet( LEVELUP, yytext );
158 }
159 
160 "}"[ \t]*;([ \t]*\\)?	{
161 /* LEVELDOWN */
162 	WorkOnTokenSet( LEVELDOWN, yytext );
163 }
164 
165 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".*	{
166 /* APPFONTMAPPING Type = MAP_APPFONT( ... ) */
167 	WorkOnTokenSet( APPFONTMAPPING, yytext );
168 }
169 
170 [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
171 /* TEXTREFID // TextType = 12345 */
172 	WorkOnTokenSet( TEXTREFID, yytext );
173 }
174 
175 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.*	|
176 [a-zA-Z0-9_]+[ \t]*"=".*	{
177 /* ASSIGNMENT Type = ... */
178  WorkOnTokenSet( ASSIGNMENT, yytext );
179 }
180 
181 
182 
183 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<"	{
184 /* LISTASSIGNMENT Type [ ... ] = ... */
185 	WorkOnTokenSet( LISTASSIGNMENT, yytext );
186 }
187 
188 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*	{
189 /* LISTASSIGNMENT Type [ ... ] = ... */
190 	WorkOnTokenSet( LISTASSIGNMENT, yytext );
191 }
192 
193 "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"	{
194 /* UIENTRIES */
195 	WorkOnTokenSet( UIENTRIES, yytext );
196 }
197 
198 "<"?[ \t]*L?\".*\".*">" {
199 /* LISTTEXT */
200 	WorkOnTokenSet( LISTTEXT, yytext );
201 }
202 
203 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\"	{
204 /* RSCDEFINE #define ... */
205 	WorkOnTokenSet( RSCDEFINE, yytext );
206 }
207 
208 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
209 /* #define ... */
210 	WorkOnTokenSet( NORMDEFINE, yytext );
211 }
212 
213 "\\" {
214 /* RSCDEFINELEND */
215 	WorkOnTokenSet( RSCDEFINELEND, yytext );
216 }
217 
218 [a-zA-Z0-9_]+[ \t]*; {
219 /* allowed other tokens like "49 ;" or "SFX_... ;" */
220 	WorkOnTokenSet( ANYTOKEN, yytext );
221 }
222 
223 .	{
224 	WorkOnTokenSet( UNKNOWNCHAR, yytext );
225 /*	YYWarning( "Unknown Char" ); */
226 }
227 
228 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
229 /* _LISTTEXT */
230 	WorkOnTokenSet( _LISTTEXT, yytext );
231 }
232 
233 %%
234 
235 /*****************************************************************************/
236 int	yywrap(void)
237 /*****************************************************************************/
238 {
239 	FILE *pFile;
240 	pFile = GetNextFile();
241 	if ( pFile ) {
242 		yyin = pFile;
243 		yylineno = 0;
244 		return 0;
245 	}
246 
247 	/* end of input reached */
248 	return 1;
249 }
250 
251 /*****************************************************************************/
252 void YYWarning( char *s )
253 /*****************************************************************************/
254 {
255 	/* write warning to stderr */
256 	fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
257 }
258 
259 /*****************************************************************************/
260 void yyerror( char *s )
261 /*****************************************************************************/
262 {
263 	/* write error to stderr */
264 	fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
265 	SetError();
266 }
267 
268 /*****************************************************************************/
269 int
270 #ifdef WNT
271 _cdecl
272 #endif
273 main( int argc, char* argv[])
274 /*****************************************************************************/
275 {
276 	/* error level */
277 	int nRetValue = 0;
278 	char *pOutput;
279 	FILE *pFile;
280 
281 	pOutput = GetOutputFile( argc, argv );
282 
283 	if ( !pOutput ) {
284 		fprintf( stdout, "Syntax:TRANSEX[-p Prj][-r PrjRoot]-i FileIn...[-o FileOut][-m DataBase][-e][-b][-u][-L l1,l2,...]\n" );
285 		fprintf( stdout, " Prj:      Project\n" );
286 		fprintf( stdout, " PrjRoot:  Path to project root (..\\.. etc.)\n" );
287 		fprintf( stdout, " FileIn:   Source files (*.src)\n" );
288 		fprintf( stdout, " FileOut:  Destination file (*.*)\n" );
289 		fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
290 		fprintf( stdout, " -QQ: quiet output\n" );
291 		fprintf( stdout, " -e: Disable writing errorlog\n" );
292 		fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" );
293 		fprintf( stdout, " -u: [english] and [german] are allowed, Id is Taken from DataBase \n" );
294 		fprintf( stdout, " -NOUTF8: disable UTF8 as language independent encoding\n" );
295 		fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US...)\n" );
296 		fprintf( stdout, "     A fallback language can be defined like this: l1=f1.\n" );
297 		fprintf( stdout, "     f1, f2,... are also elements of (de,en-US...)\n" );
298 		fprintf( stdout, "     Example: -L de,es=en-US\n" );
299 		fprintf( stdout, "              Restriction to de and es, en-US will be fallback for es\n" );
300 		return 1;
301 	}
302 
303 	InitExport( pOutput , getFilename() );
304 	pFile = GetNextFile();
305 	if ( !pFile )
306 		return 1;
307 
308 	yyin = pFile;
309 
310 	/* create global instance of class Export */
311 
312 	/* start parser */
313 	yylex();
314 	Close();
315 
316 	/* get error info. and end export */
317 	nRetValue = GetError();
318 	EndExport();
319 
320 	/* return error level */
321 	return nRetValue;
322 }
323 
324