1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
11 %option bison-locations
12 %option extra-type="unoidl::detail::SourceProviderScannerData *"
13 %option never-interactive
22 #include "sal/config.h"
34 #include "rtl/string.hxx"
35 #include "rtl/ustring.hxx"
36 #include "rtl/textenc.h"
37 #include "sal/types.h"
39 #include "sourceprovider-parser-requires.hxx"
40 #include "sourceprovider-parser.hxx"
41 #include "sourceprovider-scanner.hxx"
43 namespace unoidl { namespace detail {
45 static std::size_t sourceProviderScannerInput(
46 SourceProviderScannerData * data, char * buffer, std::size_t size)
49 if (data->sourcePosition == data->sourceEnd) {
52 assert(data->sourcePosition < data->sourceEnd);
53 size = std::min<std::size_t>(size, data->sourceEnd - data->sourcePosition);
54 std::memcpy(buffer, data->sourcePosition, size);
55 data->sourcePosition += size;
61 #define YY_INPUT(buf, result, max_size) ((result) = \
62 ::unoidl::detail::sourceProviderScannerInput(yyextra, (buf), (max_size)))
66 int nonZeroIntegerLiteral(
67 char const * text, std::size_t length, sal_Int16 radix, sal_uInt64 * value,
68 unoidl::detail::SourceProviderScannerData * data)
74 std::size_t n = length;
75 switch (text[length - 1]) {
85 *value = OString(text, n).toUInt64(radix);
87 data->errorMessage = "out-of-range integer literal "
88 + OUString(text, length, RTL_TEXTENCODING_ASCII_US);
98 %x comment1 comment2 doc docdepr
103 ALPHA {UPPER}|{LOWER}
104 ALNUM {DIGIT}|{ALPHA}
109 \n *yylloc = yylineno;
112 "#" BEGIN comment1; //TODO: only at start of line
114 <comment1>\n *yylloc = yylineno; BEGIN INITIAL;
118 "/***" BEGIN comment2;
120 <comment2,doc>"*/" BEGIN INITIAL;
121 <docdepr>"*/" BEGIN INITIAL; return TOK_DEPRECATED;
124 <comment2,doc,docdepr>\n *yylloc = yylineno;
125 <comment2,doc,docdepr><<EOF>> {
126 yyextra->errorMessage = "unterminated comment";
131 <doc>"@deprecated" BEGIN docdepr;
135 [%&()*+,\-/:;<=>[\]^{|}~] return yytext[0];
137 "..." return TOK_ELLIPSIS;
138 "::" return TOK_COLONS;
139 "<<" return TOK_LEFTSHIFT;
140 ">>" return TOK_RIGHTSHIFT;
142 "FALSE" return TOK_FALSE;
143 "False" return TOK_FALSE;
144 "TRUE" return TOK_TRUE;
145 "True" return TOK_TRUE;
146 "any" return TOK_ANY;
147 "attribute" return TOK_ATTRIBUTE;
148 "boolean" return TOK_BOOLEAN;
149 "bound" return TOK_BOUND;
150 "byte" return TOK_BYTE;
151 "char" return TOK_CHAR;
152 "const" return TOK_CONST;
153 "constants" return TOK_CONSTANTS;
154 "constrained" return TOK_CONSTRAINED;
155 "double" return TOK_DOUBLE;
156 "enum" return TOK_ENUM;
157 "exception" return TOK_EXCEPTION;
158 "float" return TOK_FLOAT;
159 "get" return TOK_GET;
160 "hyper" return TOK_HYPER;
162 "inout" return TOK_INOUT;
163 "interface" return TOK_INTERFACE;
164 "long" return TOK_LONG;
165 "maybeambiguous" return TOK_MAYBEAMBIGUOUS;
166 "maybedefault" return TOK_MAYBEDEFAULT;
167 "maybevoid" return TOK_MAYBEVOID;
168 "module" return TOK_MODULE;
169 "optional" return TOK_OPTIONAL;
170 "out" return TOK_OUT;
171 "property" return TOK_PROPERTY;
172 "published" return TOK_PUBLISHED;
173 "raises" return TOK_RAISES;
174 "readonly" return TOK_READONLY;
175 "removable" return TOK_REMOVABLE;
176 "sequence" return TOK_SEQUENCE;
177 "service" return TOK_SERVICE;
178 "set" return TOK_SET;
179 "short" return TOK_SHORT;
180 "singleton" return TOK_SINGLETON;
181 "string" return TOK_STRING;
182 "struct" return TOK_STRUCT;
183 "transient" return TOK_TRANSIENT;
184 "type" return TOK_TYPE;
185 "typedef" return TOK_TYPEDEF;
186 "unsigned" return TOK_UNSIGNED;
187 "void" return TOK_VOID;
189 {UPPER}("_"?{ALNUM})*|{LOWER}{ALNUM}* {
190 yylval->sval = new OString(yytext);
191 return TOK_IDENTIFIER;
194 ({ALPHA}|"_")({ALNUM}|"_")* {
196 yylval->sval=new OString(yytext);return TOK_IDENTIFIER;
198 yyextra->errorMessage = "illegal identifier "
199 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
211 return nonZeroIntegerLiteral(yytext, yyleng, 8, &yylval->ival, yyextra);
214 [1-9]{DIGIT}*[LUlu]? {
215 return nonZeroIntegerLiteral(yytext, yyleng, 10, &yylval->ival, yyextra);
218 0[Xx][0-9A-Fa-f]+[LUlu]? {
219 return nonZeroIntegerLiteral(
220 yytext + 2, yyleng - 2, 16, &yylval->ival, yyextra);
223 {DIGIT}+[Ee][+\-]?{DIGIT}+[Ff]? |
224 {DIGIT}*"."{DIGIT}+([Ee][+\-]?{DIGIT}+)?[Ff]? {
225 rtl_math_ConversionStatus s;
226 yylval->fval = rtl_math_stringToDouble(
227 yytext, yytext + yyleng, '.', 0, &s, 0);
228 if (s == rtl_math_ConversionStatus_OutOfRange) {
229 yyextra->errorMessage = "out-of-range floating-point literal "
230 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
236 {DIGIT}({ALNUM}|"_")* {
237 yyextra->errorMessage = "illegal numeric literal "
238 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
243 unsigned char c = yytext[0];
244 yyextra->errorMessage = c >= ' ' && c <= '~'
245 ? OUString("invalid character \"" + OUString(sal_Unicode(c)) + "\"")
247 "invalid byte x" + OUString::number(c, 16).toAsciiUpperCase());
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */