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 #include "sal/config.h"
27 /* enlarge token buffer to tokenize whole strings */
31 /* to enable debug output define LEXDEBUG */
34 #define OUTPUT fprintf
36 #define OUTPUT(Par1,Par2);
39 /* table of possible token ids */
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"
52 #elif defined __SUNPRO_CC
54 #elif defined _MSC_VER
55 #pragma warning(push, 1)
57 #define YY_NO_UNISTD_H
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();
71 %option never-interactive
80 WorkOnTokenSet( PRAGMA, yytext );
84 WorkOnTokenSet( EMPTYLINE, yytext );
95 WorkOnTokenSet( IGNOREDTOKENS, yytext );
104 WorkOnTokenSet( COMMENT, yytext );
105 WorkOnTokenSet( COMMENT, pChar );
109 if ( c1 == '*' && c2 == '/' )
114 WorkOnTokenSet( COMMENT, pChar );
118 ^[\t ]*"#ifndef".+$ |
124 WorkOnTokenSet( CONDITION, yytext );
127 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
129 WorkOnTokenSet( DEFINEDRES, yytext );
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 WorkOnTokenSet( RESOURCE, yytext );
138 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
139 /* SMALRESOURCE // String ... */
140 WorkOnTokenSet( SMALRESOURCE, yytext );
143 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? {
144 /* TEXTLINE // TextTyp = "A Text" */
145 WorkOnTokenSet( TEXTLINE, yytext );
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 WorkOnTokenSet( LONGTEXTLINE, yytext );
154 /* TEXT // "A Text" */
155 WorkOnTokenSet( TEXT, yytext );
160 WorkOnTokenSet( LEVELUP, yytext );
163 "}"[ \t]*;([ \t]*\\)? {
165 WorkOnTokenSet( LEVELDOWN, yytext );
168 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
169 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
170 WorkOnTokenSet( APPFONTMAPPING, yytext );
173 [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
174 /* TEXTREFID // TextTyp = 12345 */
175 WorkOnTokenSet( TEXTREFID, yytext );
178 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
179 [a-zA-Z0-9_]+[ \t]*"=".* {
180 /* ASSIGNMENT Typ = ... */
181 WorkOnTokenSet( ASSIGNMENT, yytext );
186 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
187 /* LISTASSIGNMENT Typ [ ... ] = ... */
188 WorkOnTokenSet( LISTASSIGNMENT, yytext );
191 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* {
192 /* LISTASSIGNMENT Typ [ ... ] = ... */
193 WorkOnTokenSet( LISTASSIGNMENT, yytext );
196 "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{" {
198 WorkOnTokenSet( UIENTRIES, yytext );
201 "<"?[ \t]*L?\".*\".*">" {
203 WorkOnTokenSet( LISTTEXT, yytext );
206 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
207 /* RSCDEFINE #define ... */
208 WorkOnTokenSet( RSCDEFINE, yytext );
211 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
213 WorkOnTokenSet( NORMDEFINE, yytext );
218 WorkOnTokenSet( RSCDEFINELEND, yytext );
221 [a-zA-Z0-9_]+[ \t]*; {
222 /* allowed other tokens like "49 ;" or "SFX_... ;" */
223 WorkOnTokenSet( ANYTOKEN, yytext );
227 WorkOnTokenSet( UNKNOWNCHAR, yytext );
228 /* YYWarning( "Unknown Char" ); */
231 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
233 WorkOnTokenSet( _LISTTEXT, yytext );
238 /*****************************************************************************/
240 /*****************************************************************************/
245 /*****************************************************************************/
246 void YYWarning( const char *s )
247 /*****************************************************************************/
249 /* write warning to stderr */
250 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
253 /*****************************************************************************/
254 void yyerror( const char *s )
255 /*****************************************************************************/
257 /* write error to stderr */
258 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
262 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
264 yyin = init(argc, argv);