Line data Source code
1 :
2 : %{
3 : /*
4 : * This file is part of the LibreOffice project.
5 : *
6 : * This Source Code Form is subject to the terms of the Mozilla Public
7 : * License, v. 2.0. If a copy of the MPL was not distributed with this
8 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 : *
10 : * This file incorporates work covered by the following license notice:
11 : *
12 : * Licensed to the Apache Software Foundation (ASF) under one or more
13 : * contributor license agreements. See the NOTICE file distributed
14 : * with this work for additional information regarding copyright
15 : * ownership. The ASF licenses this file to you under the Apache
16 : * License, Version 2.0 (the "License"); you may not use this file
17 : * except in compliance with the License. You may obtain a copy of
18 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 : */
20 :
21 : /*
22 : * lexer for parsing resource source files (*.src)
23 : */
24 :
25 : #include "sal/config.h"
26 :
27 : /* enlarge token buffer to tokenize whole strings */
28 : #undef YYLMAX
29 : #define YYLMAX 64000
30 :
31 : /* to enable debug output define LEXDEBUG */
32 : #define LEXDEBUG 1
33 : #ifdef LEXDEBUG
34 : #define OUTPUT fprintf
35 : #else
36 : #define OUTPUT(Par1,Par2);
37 : #endif
38 :
39 : /* table of possible token ids */
40 : #include "tokens.h"
41 : #include <stdlib.h>
42 : #include <stdio.h>
43 :
44 : #include "sal/main.h"
45 :
46 : #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY
47 : #pragma GCC diagnostic ignored "-Wunused-function"
48 : #pragma GCC diagnostic ignored "-Wunused-label"
49 : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
50 : #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
51 : #endif
52 : #elif defined __SUNPRO_CC
53 : #pragma disable_warn
54 : #elif defined _MSC_VER
55 : #pragma warning(push, 1)
56 : #endif
57 : #define YY_NO_UNISTD_H
58 :
59 : /* external functions (C++ code, declared as extern "C" */
60 : extern "C" int WorkOnTokenSet( int, char* );
61 : extern "C" FILE * init(int, char **);
62 : extern "C" int SetError();
63 : extern "C" int GetError();
64 : extern "C" void Close();
65 :
66 : /* forwards */
67 : void YYWarning();
68 : %}
69 :
70 : %option yylineno
71 : %option never-interactive
72 :
73 : %p 24000
74 : %e 1200
75 : %n 500
76 :
77 : %%
78 :
79 : ^[\t ]*"#pragma".* {
80 0 : WorkOnTokenSet( PRAGMA, yytext );
81 : }
82 0 :
83 : ^[ \t]*\n {
84 539 : WorkOnTokenSet( EMPTYLINE, yytext );
85 539 : }
86 539 :
87 : [\t ]+ |
88 : ^[\t ]*"#include".* |
89 : ^[\t ]*"#undef".* |
90 : "//".* |
91 : ";" |
92 : "<" |
93 : ">" |
94 : \n {
95 6635 : WorkOnTokenSet( IGNOREDTOKENS, yytext );
96 6635 : }
97 6635 : "/*" {
98 43 : char c1 = 0;
99 86 : int c2 = yyinput();
100 : char pChar[2];
101 43 : pChar[1] = 0x00;
102 43 : pChar[0] = c2;
103 :
104 43 : WorkOnTokenSet( COMMENT, yytext );
105 43 : WorkOnTokenSet( COMMENT, pChar );
106 : for(;;) {
107 12801 : if ( c2 == EOF )
108 0 : break;
109 12801 : if ( c1 == '*' && c2 == '/' )
110 43 : break;
111 12758 : c1 = c2;
112 12758 : c2 = yyinput();
113 12758 : pChar[0] = c2;
114 12758 : WorkOnTokenSet( COMMENT, pChar );
115 12758 : }
116 : }
117 43 :
118 : ^[\t ]*"#ifndef".+$ |
119 11 : ^[\t ]*"#ifdef".+$ |
120 11 : ^[\t ]*"#if".+$ |
121 11 : ^[\t ]*"#elif".*$ |
122 11 : ^[\t ]*"#else".*$ |
123 : ^[\t ]*"#endif".*$ {
124 135 : WorkOnTokenSet( CONDITION, yytext );
125 : }
126 135 :
127 : [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
128 11 : /* defined Res */
129 11 : WorkOnTokenSet( DEFINEDRES, yytext );
130 : }
131 11 :
132 : [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{" |
133 : [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{" {
134 : /* RESOURCE // String TTT_XX ... */
135 129 : WorkOnTokenSet( RESOURCE, yytext );
136 : }
137 129 :
138 : ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
139 : /* SMALRESOURCE // String ... */
140 377 : WorkOnTokenSet( SMALRESOURCE, yytext );
141 : }
142 377 :
143 : [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? {
144 : /* TEXTLINE // TextTyp = "A Text" */
145 415 : WorkOnTokenSet( TEXTLINE, yytext );
146 : }
147 415 :
148 : [\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]*))*; {
149 : /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
150 0 : WorkOnTokenSet( LONGTEXTLINE, yytext );
151 : }
152 0 :
153 : \".*\" {
154 19 : /* TEXT // "A Text" */
155 19 : WorkOnTokenSet( TEXT, yytext );
156 : }
157 19 :
158 : "{"[ \t]*\\? {
159 59 : /* LEVELUP */
160 59 : WorkOnTokenSet( LEVELUP, yytext );
161 : }
162 59 :
163 : "}"[ \t]*;([ \t]*\\)? {
164 569 : /* LEVELDOWN */
165 569 : WorkOnTokenSet( LEVELDOWN, yytext );
166 : }
167 569 :
168 : [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
169 205 : /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
170 205 : WorkOnTokenSet( APPFONTMAPPING, yytext );
171 : }
172 205 :
173 : [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
174 12 : /* TEXTREFID // TextTyp = 12345 */
175 12 : WorkOnTokenSet( TEXTREFID, yytext );
176 : }
177 12 :
178 : [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
179 : [a-zA-Z0-9_]+[ \t]*"=".* {
180 : /* ASSIGNMENT Typ = ... */
181 1090 : WorkOnTokenSet( ASSIGNMENT, yytext );
182 : }
183 1090 :
184 :
185 :
186 1 : [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
187 : /* LISTASSIGNMENT Typ [ ... ] = ... */
188 1 : WorkOnTokenSet( LISTASSIGNMENT, yytext );
189 : }
190 1 :
191 : "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* {
192 : /* LISTASSIGNMENT Typ [ ... ] = ... */
193 3 : WorkOnTokenSet( LISTASSIGNMENT, yytext );
194 : }
195 3 :
196 : "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{" {
197 : /* UIENTRIES */
198 0 : WorkOnTokenSet( UIENTRIES, yytext );
199 : }
200 0 :
201 : "<"?[ \t]*L?\".*\".*">" {
202 4 : /* LISTTEXT */
203 4 : WorkOnTokenSet( LISTTEXT, yytext );
204 : }
205 4 :
206 : [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
207 265 : /* RSCDEFINE #define ... */
208 265 : WorkOnTokenSet( RSCDEFINE, yytext );
209 : }
210 265 :
211 : [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
212 72 : /* #define ... */
213 72 : WorkOnTokenSet( NORMDEFINE, yytext );
214 : }
215 72 :
216 : "\\" {
217 226 : /* RSCDEFINELEND */
218 226 : WorkOnTokenSet( RSCDEFINELEND, yytext );
219 : }
220 226 :
221 : [a-zA-Z0-9_]+[ \t]*; {
222 0 : /* allowed other tokens like "49 ;" or "SFX_... ;" */
223 0 : WorkOnTokenSet( ANYTOKEN, yytext );
224 : }
225 0 :
226 : . {
227 8868 : WorkOnTokenSet( UNKNOWNCHAR, yytext );
228 : /* YYWarning( "Unknown Char" ); */
229 : }
230 8868 :
231 : "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
232 0 : /* _LISTTEXT */
233 0 : WorkOnTokenSet( _LISTTEXT, yytext );
234 : }
235 0 :
236 0 : %%
237 0 :
238 : /*****************************************************************************/
239 : int yywrap(void)
240 13 : /*****************************************************************************/
241 : {
242 : return 1;
243 13 : }
244 :
245 : /*****************************************************************************/
246 : void YYWarning( const char *s )
247 0 : /*****************************************************************************/
248 : {
249 : /* write warning to stderr */
250 : fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
251 0 : }
252 0 :
253 : /*****************************************************************************/
254 : void yyerror( const char *s )
255 0 : /*****************************************************************************/
256 : {
257 : /* write error to stderr */
258 : fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
259 0 : SetError();
260 0 : }
261 0 :
262 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
263 26 : int e;
264 : yyin = init(argc, argv);
265 13 : yylex();
266 13 : e = GetError();
267 13 : Close();
268 13 : return EXIT_SUCCESS;
269 13 : }
|