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>
38 #include <unoidl/unoidl.hxx>
40 #include "sourceprovider-parser-requires.hxx"
41 #include <sourceprovider-parser.hxx>
42 #include "sourceprovider-scanner.hxx"
44 namespace unoidl { namespace detail {
46 static std::size_t sourceProviderScannerInput(
47 SourceProviderScannerData * data, char * buffer, std::size_t size)
49 assert(data != nullptr);
50 if (data->sourcePosition == data->sourceEnd) {
53 assert(data->sourcePosition < data->sourceEnd);
54 size = std::min<std::size_t>(size, data->sourceEnd - data->sourcePosition);
55 std::memcpy(buffer, data->sourcePosition, size);
56 data->sourcePosition += size;
62 #define YY_INPUT(buf, result, max_size) ((result) = \
63 ::unoidl::detail::sourceProviderScannerInput(yyextra, (buf), (max_size)))
67 int nonZeroIntegerLiteral(
68 char const * text, std::size_t length, sal_Int16 radix, sal_uInt64 * value,
69 unoidl::detail::SourceProviderScannerData * data)
71 assert(text != nullptr);
73 assert(value != nullptr);
74 assert(data != nullptr);
75 std::size_t n = length;
76 switch (text[length - 1]) {
86 *value = OString(text, n).toUInt64(radix);
88 data->errorMessage = "out-of-range integer literal "
89 + OUString(text, length, RTL_TEXTENCODING_ASCII_US);
99 %x comment1 comment2 doc docdepr
104 ALPHA {UPPER}|{LOWER}
105 ALNUM {DIGIT}|{ALPHA}
110 \n *yylloc = yylineno;
113 "#" BEGIN comment1; //TODO: only at start of line
115 <comment1>\n *yylloc = yylineno; BEGIN INITIAL;
119 "/***" BEGIN comment2;
121 <comment2,doc>"*/" BEGIN INITIAL;
122 <docdepr>"*/" BEGIN INITIAL; return TOK_DEPRECATED;
125 <comment2,doc,docdepr>\n *yylloc = yylineno;
126 <comment2,doc,docdepr><<EOF>> {
127 yyextra->errorMessage = "unterminated comment";
132 <doc>"@deprecated" BEGIN docdepr;
136 [%&()*+,\-/:;<=>[\]^{|}~] return yytext[0];
138 "..." return TOK_ELLIPSIS;
139 "::" return TOK_COLONS;
140 "<<" return TOK_LEFTSHIFT;
141 ">>" return TOK_RIGHTSHIFT;
143 "FALSE" return TOK_FALSE;
144 "False" return TOK_FALSE;
145 "TRUE" return TOK_TRUE;
146 "True" return TOK_TRUE;
147 "any" return TOK_ANY;
148 "attribute" return TOK_ATTRIBUTE;
149 "boolean" return TOK_BOOLEAN;
150 "bound" return TOK_BOUND;
151 "byte" return TOK_BYTE;
152 "char" return TOK_CHAR;
153 "const" return TOK_CONST;
154 "constants" return TOK_CONSTANTS;
155 "constrained" return TOK_CONSTRAINED;
156 "double" return TOK_DOUBLE;
157 "enum" return TOK_ENUM;
158 "exception" return TOK_EXCEPTION;
159 "float" return TOK_FLOAT;
160 "get" return TOK_GET;
161 "hyper" return TOK_HYPER;
163 "inout" return TOK_INOUT;
164 "interface" return TOK_INTERFACE;
165 "long" return TOK_LONG;
166 "maybeambiguous" return TOK_MAYBEAMBIGUOUS;
167 "maybedefault" return TOK_MAYBEDEFAULT;
168 "maybevoid" return TOK_MAYBEVOID;
169 "module" return TOK_MODULE;
170 "optional" return TOK_OPTIONAL;
171 "out" return TOK_OUT;
172 "property" return TOK_PROPERTY;
173 "published" return TOK_PUBLISHED;
174 "raises" return TOK_RAISES;
175 "readonly" return TOK_READONLY;
176 "removable" return TOK_REMOVABLE;
177 "sequence" return TOK_SEQUENCE;
178 "service" return TOK_SERVICE;
179 "set" return TOK_SET;
180 "short" return TOK_SHORT;
181 "singleton" return TOK_SINGLETON;
182 "string" return TOK_STRING;
183 "struct" return TOK_STRUCT;
184 "transient" return TOK_TRANSIENT;
185 "type" return TOK_TYPE;
186 "typedef" return TOK_TYPEDEF;
187 "unsigned" return TOK_UNSIGNED;
188 "void" return TOK_VOID;
190 {UPPER}("_"?{ALNUM})*|{LOWER}{ALNUM}* {
191 yylval->sval = new OString(yytext);
192 return TOK_IDENTIFIER;
195 ({ALPHA}|"_")({ALNUM}|"_")* {
197 yylval->sval=new OString(yytext);return TOK_IDENTIFIER;
199 yyextra->errorMessage = "illegal identifier "
200 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
212 return nonZeroIntegerLiteral(yytext, yyleng, 8, &yylval->ival, yyextra);
215 [1-9]{DIGIT}*[LUlu]? {
216 return nonZeroIntegerLiteral(yytext, yyleng, 10, &yylval->ival, yyextra);
219 0[Xx][0-9A-Fa-f]+[LUlu]? {
220 return nonZeroIntegerLiteral(
221 yytext + 2, yyleng - 2, 16, &yylval->ival, yyextra);
224 {DIGIT}+[Ee][+\-]?{DIGIT}+[Ff]? |
225 {DIGIT}*"."{DIGIT}+([Ee][+\-]?{DIGIT}+)?[Ff]? {
226 rtl_math_ConversionStatus s;
227 yylval->fval = rtl_math_stringToDouble(
228 yytext, yytext + yyleng, '.', 0, &s, nullptr);
229 if (s == rtl_math_ConversionStatus_OutOfRange) {
230 yyextra->errorMessage = "out-of-range floating-point literal "
231 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
237 {DIGIT}({ALNUM}|"_")* {
238 yyextra->errorMessage = "illegal numeric literal "
239 + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
245 yyextra->errorMessage = c >= ' ' && c <= '~'
246 ? OUString("invalid character \"" + OUStringChar(c) + "\"")
249 + OUString::number(static_cast<unsigned char>(c), 16).toAsciiUpperCase());
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */