Line data Source code
1 : %{
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : /*
21 : * lexer for parsing cfg source files
22 : */
23 :
24 : /* enlarge token buffer to tokenize whole strings */
25 : #undef YYLMAX
26 : #define YYLMAX 64000
27 :
28 : /* to enable debug output define LEXDEBUG */
29 : #define LEXDEBUG 1
30 : #ifdef LEXDEBUG
31 : #define OUTPUT fprintf
32 : #else
33 : #define OUTPUT(Par1,Par2);
34 : #endif
35 :
36 : /* table of possible token ids */
37 : #include "tokens.h"
38 : #include <stdlib.h>
39 : #include <stdio.h>
40 :
41 : #include "sal/main.h"
42 :
43 : #if defined __GNUC__
44 : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
45 : #pragma GCC diagnostic ignored "-Wunused-function"
46 : #pragma GCC diagnostic ignored "-Wunused-label"
47 : #endif
48 : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
49 : #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
50 : #endif
51 : #elif defined __SINPRO_CC
52 : #pragma disable_warn
53 : #elif defined _MSC_VER
54 : #pragma warning(push, 1)
55 : #endif
56 :
57 : int yycolumn = 1;
58 : #define YY_USER_ACTION yycolumn += yyleng;
59 :
60 : /* external functions (C++ code, declared as extern "C" */
61 : extern "C" void workOnTokenSet( int, char* );
62 : extern "C" FILE * init(int, char **);
63 :
64 : int bText=0;
65 : %}
66 :
67 : %option yylineno
68 : %option never-interactive
69 :
70 : %p 24000
71 : %e 1200
72 : %n 500
73 :
74 : %%
75 :
76 : \<[^\>]*"xml:lang="\""x-no-translate"\"[^\<]*\/\> {
77 0 : bText = 0;
78 0 : workOnTokenSet( CFG_TOKEN_NO_TRANSLATE, yytext );
79 : }
80 0 :
81 : \<.*\/\> {
82 0 : bText = 0;
83 0 : workOnTokenSet( ANYTOKEN, yytext );
84 : }
85 0 :
86 : \<[^\>]*"xml:lang="\".*\"[^\<]*\> {
87 0 : bText = 1;
88 0 : workOnTokenSet( CFG_TEXT_START, yytext );
89 : }
90 0 :
91 :
92 : \<[^\/\!][^\>]*\> {
93 0 : bText = 0;
94 0 : workOnTokenSet( CFG_TAG, yytext );
95 : }
96 0 :
97 : "<!"DOCTYPE[^\>]*\> {
98 0 : bText = 0;
99 0 : workOnTokenSet( CFG_TAG, yytext );
100 : }
101 0 :
102 :
103 0 : \<\!\-\- {
104 0 : char c1 = 0, c2 = 0;
105 0 : int c3 = yyinput();
106 : char pChar[2];
107 0 : pChar[1] = 0x00;
108 0 : pChar[0] = c3;
109 :
110 0 : workOnTokenSet( COMMENT, yytext );
111 0 : workOnTokenSet( COMMENT, pChar );
112 :
113 0 : for(;;) {
114 0 : if ( c3 == EOF )
115 0 : break;
116 0 : if ( c1 == '-' && c2 == '-' && c3 == '>' )
117 0 : break;
118 0 : c1 = c2;
119 0 : c2 = c3;
120 0 : c3 = yyinput();
121 :
122 0 : pChar[0] = c3;
123 0 : workOnTokenSet( COMMENT, pChar );
124 : }
125 : }
126 0 :
127 : \<\/[^\>]*\> {
128 0 : bText = 0;
129 0 : workOnTokenSet( CFG_CLOSETAG, yytext );
130 : }
131 0 :
132 : \<[^\>\!]*\> {
133 0 : bText = 0;
134 0 : if ( yytext[ 1 ] == '!' && yytext[ 2 ] == '-' && yytext[ 3 ] == '-' )
135 0 : workOnTokenSet( COMMENT, yytext );
136 : else
137 0 : workOnTokenSet( CFG_UNKNOWNTAG, yytext );
138 : }
139 0 :
140 : .|\n {
141 0 : yycolumn = 1;
142 0 : if ( bText == 1 )
143 0 : workOnTokenSet( CFG_TEXTCHAR, yytext );
144 : else
145 0 : workOnTokenSet( UNKNOWNCHAR, yytext );
146 : }
147 0 :
148 :
149 0 : %%
150 0 :
151 : /*****************************************************************************/
152 : int yywrap(void)
153 0 : /*****************************************************************************/
154 : {
155 : return 1;
156 0 : }
157 :
158 : /*****************************************************************************/
159 : void YYWarning( const char *s )
160 0 : /*****************************************************************************/
161 : {
162 : /* write warning to stderr */
163 : fprintf( stderr,
164 : "Warning: \"%s\" in line %d, column %d: \"%s\"\n", s, yylineno, yycolumn, yytext );
165 0 : }
166 0 :
167 : /*****************************************************************************/
168 : void yyerror ( const char *s )
169 0 : /*****************************************************************************/
170 : {
171 : /* write error to stderr */
172 : fprintf( stderr,
173 : "Error: \"%s\" in line %d, column %d: \"%s\"\n", s, yylineno, yycolumn, yytext );
174 0 : exit(EXIT_FAILURE);
175 0 : }
176 :
177 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
178 0 : yyin = init(argc, argv);
179 0 : yylex();
180 0 : return EXIT_SUCCESS;
181 0 : }
|