LibreOffice Module l10ntools (master) 1
cfglex.l
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
22/*
23 * lexer for parsing cfg source files
24 */
25
26#include <sal/config.h>
27
28/* enlarge token buffer to tokenize whole strings */
29#undef YYLMAX
30#define YYLMAX 64000
31
32/* to enable debug output define LEXDEBUG */
33#define LEXDEBUG 1
34#ifdef LEXDEBUG
35#define OUTPUT fprintf
36#else
37#define OUTPUT(Par1,Par2);
38#endif
39
40/* table of possible token ids */
41#include <tokens.h>
42#include <stdlib.h>
43#include <stdio.h>
44
45#include <sal/main.h>
46
47#include <cfglex.hxx>
48
49#define YY_NO_UNISTD_H
50
51static int yycolumn = 1;
52#define YY_USER_ACTION yycolumn += yyleng;
53
54static int bText=0;
static int bText
Definition: cfglex.l:54
static int yycolumn
Definition: cfglex.l:51
55%}
56
57%option yylineno
58%option nounput
59%option never-interactive
60
61%p 24000
62%e 1200
63%n 500
64
65%%
66
67<[^>]*"xml:lang="\""x-no-translate"\"[^<]*\/> {
68 bText = 0;
70}
void workOnTokenSet(int nTyp, char *pTokenText)
Definition: cfgmerge.cxx:82
#define CFG_TOKEN_NO_TRANSLATE
Definition: tokens.h:74
71
72<.*\/> {
73 bText = 0;
74 workOnTokenSet( ANYTOKEN, yytext );
75}
#define ANYTOKEN
Definition: tokens.h:31
76
77<[^>]*"xml:lang="\".*\"[^<]*> {
78 bText = 1;
80}
#define CFG_TEXT_START
Definition: tokens.h:63
81
82
83<[^\/\!][^>]*> {
84 bText = 0;
85 workOnTokenSet( CFG_TAG, yytext );
86}
#define CFG_TAG
Definition: tokens.h:62
87
88"<!"DOCTYPE[^>]*> {
89 bText = 0;
90 workOnTokenSet( CFG_TAG, yytext );
91}
92
93
94<\!\-\- {
95 char c1 = 0, c2 = 0;
96 int c3 = yyinput();
97 char pChar[2];
98 pChar[1] = 0x00;
99 pChar[0] = c3;
100
101 workOnTokenSet( COMMENT, yytext );
102 workOnTokenSet( COMMENT, pChar );
103
104 for(;;) {
105 if ( c3 == EOF )
106 break;
107 if ( c1 == '-' && c2 == '-' && c3 == '>' )
108 break;
109 c1 = c2;
110 c2 = c3;
111 c3 = yyinput();
112
113 pChar[0] = c3;
114 workOnTokenSet( COMMENT, pChar );
115 }
116}
#define COMMENT
Definition: tokens.h:29
const char * pChar
117
118<\/[^>]*> {
119 bText = 0;
120 workOnTokenSet( CFG_CLOSETAG, yytext );
121}
#define CFG_CLOSETAG
Definition: tokens.h:66
122
123<[^>\!]*> {
124 bText = 0;
125 if ( yytext[ 1 ] == '!' && yytext[ 2 ] == '-' && yytext[ 3 ] == '-' )
126 workOnTokenSet( COMMENT, yytext );
127 else
129}
#define CFG_UNKNOWNTAG
Definition: tokens.h:67
130
131.|\n {
132 yycolumn = 1;
133 if ( bText == 1 )
134 workOnTokenSet( CFG_TEXTCHAR, yytext );
135 else
136 workOnTokenSet( UNKNOWNCHAR, yytext );
137}
#define UNKNOWNCHAR
Definition: tokens.h:32
#define CFG_TEXTCHAR
Definition: tokens.h:65
138
139
140%%
141
142/*****************************************************************************/
143int yywrap(void)
144/*****************************************************************************/
145{
146 return 1;
147}
148
149/*****************************************************************************/
150void yyerror ( const char *s )
151/*****************************************************************************/
152{
153 /* write error to stderr */
154 fprintf( stderr,
155 "Error: \"%s\" in line %d, column %d: \"%s\"\n", s, yylineno, yycolumn, yytext );
156 exit(EXIT_FAILURE);
157}
158
160 yyin = init(argc, argv);
161 yylex();
162 return EXIT_SUCCESS;
163}
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
int yylex(void)
Definition: cfglex.l:65
int yywrap(void)
Definition: cfglex.l:143
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
Definition: cfglex.l:159
void yyerror(const char *s)
Definition: cfglex.l:150
FILE * init(int argc, char **argv)
Definition: cfgmerge.cxx:50