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 */
49 #pragma GCC diagnostic ignored "-Wunused-function"
50 #pragma GCC diagnostic ignored "-Wunused-label"
51 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
52 #elif defined _MSC_VER
53 #pragma warning(push, 1)
55 #define YY_NO_UNISTD_H
62 %option never-interactive
71 WorkOnTokenSet( PRAGMA, yytext );
75 WorkOnTokenSet( EMPTYLINE, yytext );
86 WorkOnTokenSet( IGNOREDTOKENS, yytext );
95 WorkOnTokenSet( COMMENT, yytext );
96 WorkOnTokenSet( COMMENT, pChar );
100 if ( c1 == '*' && c2 == '/' )
105 WorkOnTokenSet( COMMENT, pChar );
109 ^[\t ]*"#ifndef".+$ |
115 WorkOnTokenSet( CONDITION, yytext );
118 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
120 WorkOnTokenSet( DEFINEDRES, yytext );
123 [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{" |
124 [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{" {
125 /* RESOURCE // String TTT_XX ... */
126 WorkOnTokenSet( RESOURCE, yytext );
129 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
130 /* SMALRESOURCE // String ... */
131 WorkOnTokenSet( SMALRESOURCE, yytext );
134 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? {
135 /* TEXTLINE // TextTyp = "A Text" */
136 WorkOnTokenSet( TEXTLINE, yytext );
139 [\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]*))*; {
140 /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
141 WorkOnTokenSet( LONGTEXTLINE, yytext );
145 /* TEXT // "A Text" */
146 WorkOnTokenSet( TEXT, yytext );
151 WorkOnTokenSet( LEVELUP, yytext );
154 "}"[ \t]*;([ \t]*\\)? {
156 WorkOnTokenSet( LEVELDOWN, yytext );
159 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
160 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
161 WorkOnTokenSet( APPFONTMAPPING, yytext );
164 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
165 [a-zA-Z0-9_]+[ \t]*"=".* {
166 /* ASSIGNMENT Typ = ... */
167 WorkOnTokenSet( ASSIGNMENT, yytext );
172 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
173 /* LISTASSIGNMENT Typ [ ... ] = ... */
174 WorkOnTokenSet( LISTASSIGNMENT, yytext );
177 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* {
178 /* LISTASSIGNMENT Typ [ ... ] = ... */
179 WorkOnTokenSet( LISTASSIGNMENT, yytext );
182 "<"?[ \t]*L?\".*\".*">" {
184 WorkOnTokenSet( LISTTEXT, yytext );
187 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
188 /* RSCDEFINE #define ... */
189 WorkOnTokenSet( RSCDEFINE, yytext );
192 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
194 WorkOnTokenSet( NORMDEFINE, yytext );
199 WorkOnTokenSet( RSCDEFINELEND, yytext );
202 [a-zA-Z0-9_]+[ \t]*; {
203 /* allowed other tokens like "49 ;" or "SFX_... ;" */
204 WorkOnTokenSet( ANYTOKEN, yytext );
208 WorkOnTokenSet( UNKNOWNCHAR, yytext );
209 /* YYWarning( "Unknown Char" ); */
212 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
214 WorkOnTokenSet( _LISTTEXT, yytext );
219 /*****************************************************************************/
221 /*****************************************************************************/
226 /*****************************************************************************/
227 void YYWarning( const char *s )
228 /*****************************************************************************/
230 /* write warning to stderr */
231 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
234 /*****************************************************************************/
235 void yyerror( const char *s )
236 /*****************************************************************************/
238 /* write error to stderr */
239 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
243 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
245 yyin = init(argc, argv);