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
24 #include "sal/config.h"
36 #include <rtl/string.hxx>
37 #include <rtl/ustring.hxx>
38 #include <rtl/textenc.h>
39 #include <sal/types.h>
40 #include <unoidl/unoidl.hxx>
42 #include "sourceprovider-parser-requires.hxx"
43 #include <sourceprovider-parser.hxx>
44 #include "sourceprovider-scanner.hxx"
46 namespace unoidl::detail {
48 static std::size_t sourceProviderScannerInput(
49 SourceProviderScannerData * data, char * buffer, std::size_t size)
51 assert(data != nullptr);
52 if (data->sourcePosition == data->sourceEnd) {
55 assert(data->sourcePosition < data->sourceEnd);
56 size = std::min<std::size_t>(size, data->sourceEnd - data->sourcePosition);
57 std::memcpy(buffer, data->sourcePosition, size);
58 data->sourcePosition += size;
64 #define YY_INPUT(buf, result, max_size) ((result) = \
65 ::unoidl::detail::sourceProviderScannerInput(yyextra, (buf), (max_size)))
69 int nonZeroIntegerLiteral(
70 char const * text, std::size_t length, sal_Int16 radix, sal_uInt64 * value,
71 unoidl::detail::SourceProviderScannerData * data)
73 assert(text != nullptr);
75 assert(value != nullptr);
76 assert(data != nullptr);
77 std::size_t n = length;
78 switch (text[length - 1]) {
88 *value = OString(text, n).toUInt64(radix);
90 data->errorMessage = "out-of-range integer literal "
91 + OUString(text, length, RTL_TEXTENCODING_ASCII_US);
101 %x comment1 comment2 doc docdepr
106 ALPHA {UPPER}|{LOWER}
107 ALNUM {DIGIT}|{ALPHA}
112 \n *yylloc = yylineno;
115 "#" BEGIN comment1; //TODO: only at start of line
117 <comment1>\n *yylloc = yylineno; BEGIN INITIAL;
121 "/***" BEGIN comment2;
123 <comment2,doc>"*/" BEGIN INITIAL;
124 <docdepr>"*/" BEGIN INITIAL; return TOK_DEPRECATED;
127 <comment2,doc,docdepr>\n *yylloc = yylineno;
128 <comment2,doc,docdepr><<EOF>> {
129 yyextra->errorMessage = "unterminated comment";
134 <doc>"@deprecated" BEGIN docdepr;
138 [%&()*+,\-/:;<=>[\]^{|}~] return yytext[0];
140 "..." return TOK_ELLIPSIS;
141 "::" return TOK_COLONS;
142 "<<" return TOK_LEFTSHIFT;
143 ">>" return TOK_RIGHTSHIFT;
145 "FALSE" return TOK_FALSE;
146 "False" return TOK_FALSE;
147 "TRUE" return TOK_TRUE;
148 "True" return TOK_TRUE;
149 "any" return TOK_ANY;
150 "attribute" return TOK_ATTRIBUTE;
151 "boolean" return TOK_BOOLEAN;
152 "bound" return TOK_BOUND;
153 "byte" return TOK_BYTE;
154 "char" return TOK_CHAR;
155 "const" return TOK_CONST;
156 "constants" return TOK_CONSTANTS;
157 "constrained" return TOK_CONSTRAINED;
158 "double" return TOK_DOUBLE;
159 "enum" return TOK_ENUM;
160 "exception" return TOK_EXCEPTION;
161 "float" return TOK_FLOAT;
162 "get" return TOK_GET;
163 "hyper" return TOK_HYPER;
165 "inout" return TOK_INOUT;
166 "interface" return TOK_INTERFACE;
167 "long" return TOK_LONG;
168 "maybeambiguous" return TOK_MAYBEAMBIGUOUS;
169 "maybedefault" return TOK_MAYBEDEFAULT;
170 "maybevoid" return TOK_MAYBEVOID;
171 "module" return TOK_MODULE;
172 "optional" return TOK_OPTIONAL;
173 "out" return TOK_OUT;
174 "property" return TOK_PROPERTY;
175 "published" return TOK_PUBLISHED;
176 "raises" return TOK_RAISES;
177 "readonly" return TOK_READONLY;
178 "removable" return TOK_REMOVABLE;
179 "sequence" return TOK_SEQUENCE;
180 "service" return TOK_SERVICE;
181 "set" return TOK_SET;
182 "short" return TOK_SHORT;
183 "singleton" return TOK_SINGLETON;
184 "string" return TOK_STRING;
185 "struct" return TOK_STRUCT;
186 "transient" return TOK_TRANSIENT;
187 "type" return TOK_TYPE;
188 "typedef" return TOK_TYPEDEF;
189 "unsigned" return TOK_UNSIGNED;
190 "void" return TOK_VOID;
192 {UPPER}("_"?{ALNUM})*|{LOWER}{ALNUM}* {
193 yylval->sval = new OString(yytext);
194 return TOK_IDENTIFIER;
197 ({ALPHA}|"_")({ALNUM}|"_")* {
198 yyextra->errorMessage = "illegal identifier "
199 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
210 return nonZeroIntegerLiteral(yytext, yyleng, 8, &yylval->ival, yyextra);
213 [1-9]{DIGIT}*[LUlu]? {
214 return nonZeroIntegerLiteral(yytext, yyleng, 10, &yylval->ival, yyextra);
217 0[Xx][0-9A-Fa-f]+[LUlu]? {
218 return nonZeroIntegerLiteral(
219 yytext + 2, yyleng - 2, 16, &yylval->ival, yyextra);
222 {DIGIT}+[Ee][+\-]?{DIGIT}+[Ff]? |
223 {DIGIT}*"."{DIGIT}+([Ee][+\-]?{DIGIT}+)?[Ff]? {
224 rtl_math_ConversionStatus s;
225 yylval->fval = rtl_math_stringToDouble(
226 yytext, yytext + yyleng, '.', 0, &s, nullptr);
227 if (s == rtl_math_ConversionStatus_OutOfRange) {
228 yyextra->errorMessage = "out-of-range floating-point literal "
229 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
235 {DIGIT}({ALNUM}|"_")* {
236 yyextra->errorMessage = "illegal numeric literal "
237 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
243 yyextra->errorMessage = c >= ' ' && c <= '~'
244 ? OUString("invalid character \"" + OUStringChar(c) + "\"")
247 + OUString::number(static_cast<unsigned char>(c), 16).toAsciiUpperCase());
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */