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 */
48 #define YY_NO_UNISTD_H
55 %option never-interactive
64 WorkOnTokenSet( PRAGMA, yytext );
68 WorkOnTokenSet( EMPTYLINE, yytext );
79 WorkOnTokenSet( IGNOREDTOKENS, yytext );
88 WorkOnTokenSet( COMMENT, yytext );
89 WorkOnTokenSet( COMMENT, pChar );
93 if ( c1 == '*' && c2 == '/' )
98 WorkOnTokenSet( COMMENT, pChar );
102 ^[\t ]*"#ifndef".+$ |
108 WorkOnTokenSet( CONDITION, yytext );
111 [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
113 WorkOnTokenSet( DEFINEDRES, yytext );
116 [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{" |
117 [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{" {
118 /* RESOURCE // String TTT_XX ... */
119 WorkOnTokenSet( RESOURCE, yytext );
122 ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
123 /* SMALRESOURCE // String ... */
124 WorkOnTokenSet( SMALRESOURCE, yytext );
127 [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n? {
128 /* TEXTLINE // TextTyp = "A Text" */
129 WorkOnTokenSet( TEXTLINE, yytext );
132 [\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]*))*; {
133 /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
134 WorkOnTokenSet( LONGTEXTLINE, yytext );
138 /* TEXT // "A Text" */
139 WorkOnTokenSet( TEXT, yytext );
144 WorkOnTokenSet( LEVELUP, yytext );
147 "}"[ \t]*;([ \t]*\\)? {
149 WorkOnTokenSet( LEVELDOWN, yytext );
152 [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".* {
153 /* APPFONTMAPPING Typ = MAP_APPFONT( ... ) */
154 WorkOnTokenSet( APPFONTMAPPING, yytext );
157 [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.* |
158 [a-zA-Z0-9_]+[ \t]*"=".* {
159 /* ASSIGNMENT Typ = ... */
160 WorkOnTokenSet( ASSIGNMENT, yytext );
165 [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
166 /* LISTASSIGNMENT Typ [ ... ] = ... */
167 WorkOnTokenSet( LISTASSIGNMENT, yytext );
170 "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]* {
171 /* LISTASSIGNMENT Typ [ ... ] = ... */
172 WorkOnTokenSet( LISTASSIGNMENT, yytext );
175 "<"?[ \t]*L?\".*\".*">" {
177 WorkOnTokenSet( LISTTEXT, yytext );
180 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\" {
181 /* RSCDEFINE #define ... */
182 WorkOnTokenSet( RSCDEFINE, yytext );
185 [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
187 WorkOnTokenSet( NORMDEFINE, yytext );
192 WorkOnTokenSet( RSCDEFINELEND, yytext );
195 [a-zA-Z0-9_]+[ \t]*; {
196 /* allowed other tokens like "49 ;" or "SFX_... ;" */
197 WorkOnTokenSet( ANYTOKEN, yytext );
201 WorkOnTokenSet( UNKNOWNCHAR, yytext );
202 /* YYWarning( "Unknown Char" ); */
205 "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
207 WorkOnTokenSet( LISTTEXT_, yytext );
212 /*****************************************************************************/
214 /*****************************************************************************/
219 /*****************************************************************************/
220 void YYWarning( const char *s )
221 /*****************************************************************************/
223 /* write warning to stderr */
224 fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
227 /*****************************************************************************/
228 void yyerror( const char *s )
229 /*****************************************************************************/
231 /* write error to stderr */
232 fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext );
236 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
237 yyin = init(argc, argv);