4 * This file is part of the LibreOffice project.
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/.
10 * This file incorporates work covered by the following license notice:
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 .
22 * lexer for parsing resource source files (*.src)
25 /* enlarge token buffer to tokenize whole strings */
29 /* to enable debug output define LEXDEBUG */
32 #define OUTPUT fprintf
34 #define OUTPUT(Par1,Par2);
37 /* table of possible token ids */
45 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
46 #pragma GCC diagnostic ignored "-Wunused-function"
47 #pragma GCC diagnostic ignored "-Wunused-label"
49 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
50 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
52 #elif defined __SINPRO_CC
54 #elif defined _MSC_VER
55 #pragma warning(push, 1)
58 /* external functions (C++ code, declared as extern "C" */
59 extern "C" int WorkOnTokenSet( int, char* );
60 extern "C" FILE * init(int, char **);
61 extern "C" int SetError();
62 extern "C" int GetError();
63 extern "C" void Close();
70 %option never-interactive
79 WorkOnTokenSet( PRAGMA, yytext );
83 WorkOnTokenSet( EMPTYLINE, yytext );
94 WorkOnTokenSet( IGNOREDTOKENS, yytext );
103 WorkOnTokenSet( COMMENT, yytext );
104 WorkOnTokenSet( COMMENT, pChar );
108 if ( c1 == '*' && c2 == '/' )
113 WorkOnTokenSet( COMMENT, pChar );
117 ^[\t ]*"#ifndef".+$ |
123 WorkOnTokenSet( CONDITION, yytext );
126 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
128 WorkOnTokenSet( DEFINEDRES, yytext );
131 [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{" |
132 [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{" {
133 /* RESOURCE // String TTT_XX ... */
134 WorkOnTokenSet( RESOURCE, yytext );
137 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
138 /* SMALRESOURCE // String ... */
139 WorkOnTokenSet( SMALRESOURCE, yytext );
142 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? {
143 /* TEXTLINE // TextTyp = "A Text" */
144 WorkOnTokenSet( TEXTLINE, yytext );
147 [\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]*))*; {
148 /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
149 WorkOnTokenSet( LONGTEXTLINE, yytext );
153 /* TEXT // "A Text" */
154 WorkOnTokenSet( TEXT, yytext );
159 WorkOnTokenSet( LEVELUP, yytext );
162 "}"[ \t]*;([ \t]*\\)? {
164 WorkOnTokenSet( LEVELDOWN, yytext );
167 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
168 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
169 WorkOnTokenSet( APPFONTMAPPING, yytext );
172 [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
173 /* TEXTREFID // TextTyp = 12345 */
174 WorkOnTokenSet( TEXTREFID, yytext );
177 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
178 [a-zA-Z0-9_]+[ \t]*"=".* {
179 /* ASSIGNMENT Typ = ... */
180 WorkOnTokenSet( ASSIGNMENT, yytext );
185 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
186 /* LISTASSIGNMENT Typ [ ... ] = ... */
187 WorkOnTokenSet( LISTASSIGNMENT, yytext );
190 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* {
191 /* LISTASSIGNMENT Typ [ ... ] = ... */
192 WorkOnTokenSet( LISTASSIGNMENT, yytext );
195 "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{" {
197 WorkOnTokenSet( UIENTRIES, yytext );
200 "<"?[ \t]*L?\".*\".*">" {
202 WorkOnTokenSet( LISTTEXT, yytext );
205 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
206 /* RSCDEFINE #define ... */
207 WorkOnTokenSet( RSCDEFINE, yytext );
210 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
212 WorkOnTokenSet( NORMDEFINE, yytext );
217 WorkOnTokenSet( RSCDEFINELEND, yytext );
220 [a-zA-Z0-9_]+[ \t]*; {
221 /* allowed other tokens like "49 ;" or "SFX_... ;" */
222 WorkOnTokenSet( ANYTOKEN, yytext );
226 WorkOnTokenSet( UNKNOWNCHAR, yytext );
227 /* YYWarning( "Unknown Char" ); */
230 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
232 WorkOnTokenSet( _LISTTEXT, yytext );
237 /*****************************************************************************/
239 /*****************************************************************************/
244 /*****************************************************************************/
245 void YYWarning( const char *s )
246 /*****************************************************************************/
248 /* write warning to stderr */
249 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
252 /*****************************************************************************/
253 void yyerror( const char *s )
254 /*****************************************************************************/
256 /* write error to stderr */
257 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
261 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
263 yyin = init(argc, argv);