LCOV - code coverage report
Current view: top level - unoidl/source - sourceprovider-scanner.l (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 115 0.0 %
Date: 2014-04-14 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       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             : 
      10             : %option bison-bridge
      11             : %option bison-locations
      12             : %option extra-type="unoidl::detail::SourceProviderScannerData *"
      13             : %option never-interactive
      14             : %option nounistd
      15             : %option noyywrap
      16             : %option reentrant
      17             : %option warn
      18             : %option yylineno
      19             : 
      20             : %top {
      21             : 
      22             : #include "sal/config.h"
      23             : 
      24             : #include <algorithm>
      25             : #include <cassert>
      26             : #include <cstddef>
      27             : #include <cstring>
      28             : 
      29             : }
      30             : 
      31             : %{
      32             : 
      33             : #include "rtl/math.h"
      34             : #include "rtl/string.hxx"
      35             : #include "rtl/ustring.hxx"
      36             : #include "rtl/textenc.h"
      37             : #include "sal/types.h"
      38             : 
      39             : #include "sourceprovider-parser-requires.hxx"
      40             : #include "sourceprovider-parser.hxx"
      41             : #include "sourceprovider-scanner.hxx"
      42             : 
      43             : namespace unoidl { namespace detail {
      44             : 
      45           0 : static std::size_t sourceProviderScannerInput(
      46             :     SourceProviderScannerData * data, char * buffer, std::size_t size)
      47             : {
      48             :     assert(data != 0);
      49           0 :     if (data->sourcePosition == data->sourceEnd) {
      50           0 :         return YY_NULL;
      51             :     }
      52             :     assert(data->sourcePosition < data->sourceEnd);
      53           0 :     size = std::min<std::size_t>(size, data->sourceEnd - data->sourcePosition);
      54           0 :     std::memcpy(buffer, data->sourcePosition, size);
      55           0 :     data->sourcePosition += size;
      56           0 :     return size;
      57             : }
      58             : 
      59             : } }
      60             : 
      61             : #define YY_INPUT(buf, result, max_size) ((result) = \
      62             :     ::unoidl::detail::sourceProviderScannerInput(yyextra, (buf), (max_size)))
      63             : 
      64             : namespace {
      65             : 
      66           0 : int nonZeroIntegerLiteral(
      67             :     char const * text, std::size_t length, sal_Int16 radix, sal_uInt64 * value,
      68             :     unoidl::detail::SourceProviderScannerData * data)
      69             : {
      70             :     assert(text != 0);
      71             :     assert(length != 0);
      72             :     assert(value != 0);
      73             :     assert(data != 0);
      74           0 :     std::size_t n = length;
      75           0 :     switch (text[length - 1]) {
      76             :     case 'L':
      77             :     case 'U':
      78             :     case 'l':
      79             :     case 'u':
      80           0 :         --n;
      81           0 :         break;
      82             :     default:
      83           0 :         break;
      84             :     }
      85           0 :     *value = OString(text, n).toUInt64(radix);
      86           0 :     if (*value == 0) {
      87           0 :         data->errorMessage = "out-of-range integer literal "
      88           0 :             + OUString(text, length, RTL_TEXTENCODING_ASCII_US);
      89           0 :         return TOK_ERROR;
      90             :     }
      91           0 :     return TOK_INTEGER;
      92             : }
      93             : 
      94             : }
      95             : 
      96             : %}
      97             : 
      98             : %x comment1 comment2 doc docdepr
      99             : 
     100             : DIGIT [0-9]
     101             : UPPER [A-Z]
     102             : LOWER [a-z]
     103             : ALPHA {UPPER}|{LOWER}
     104             : ALNUM {DIGIT}|{ALPHA}
     105             : 
     106             : %%
     107             : 
     108             : [ \t\r]
     109           0 : \n *yylloc = yylineno;
     110           0 : 
     111           0 : "//" BEGIN comment1;
     112           0 : "#" BEGIN comment1; //TODO: only at start of line
     113           0 : <comment1>.
     114           0 : <comment1>\n *yylloc = yylineno; BEGIN INITIAL;
     115           0 : 
     116           0 : "/*" BEGIN comment2;
     117           0 : "/**" BEGIN doc;
     118           0 : "/***" BEGIN comment2;
     119           0 : 
     120           0 : <comment2,doc>"*/" BEGIN INITIAL;
     121           0 : <docdepr>"*/" BEGIN INITIAL; return TOK_DEPRECATED;
     122             : 
     123             : <comment2,docdepr>.
     124           0 : <comment2,doc,docdepr>\n *yylloc = yylineno;
     125           0 : <comment2,doc,docdepr><<EOF>> {
     126           0 :     yyextra->errorMessage = "unterminated comment";
     127           0 :     return TOK_ERROR;
     128             : }
     129             : 
     130             : <doc>[ \t\r]
     131           0 : <doc>"@deprecated" BEGIN docdepr;
     132           0 : <doc>"*"
     133           0 : <doc>[^ \t\r\n*]+
     134           0 : 
     135           0 : [%&()*+,\-/:;<=>[\]^{|}~] return yytext[0];
     136             : 
     137           0 : "..." return TOK_ELLIPSIS;
     138           0 : "::" return TOK_COLONS;
     139           0 : "<<" return TOK_LEFTSHIFT;
     140           0 : ">>" return TOK_RIGHTSHIFT;
     141             : 
     142           0 : "FALSE" return TOK_FALSE;
     143           0 : "False" return TOK_FALSE;
     144           0 : "TRUE" return TOK_TRUE;
     145           0 : "True" return TOK_TRUE;
     146           0 : "any" return TOK_ANY;
     147           0 : "attribute" return TOK_ATTRIBUTE;
     148           0 : "boolean" return TOK_BOOLEAN;
     149           0 : "bound" return TOK_BOUND;
     150           0 : "byte" return TOK_BYTE;
     151           0 : "char" return TOK_CHAR;
     152           0 : "const" return TOK_CONST;
     153           0 : "constants" return TOK_CONSTANTS;
     154           0 : "constrained" return TOK_CONSTRAINED;
     155           0 : "double" return TOK_DOUBLE;
     156           0 : "enum" return TOK_ENUM;
     157           0 : "exception" return TOK_EXCEPTION;
     158           0 : "float" return TOK_FLOAT;
     159           0 : "get" return TOK_GET;
     160           0 : "hyper" return TOK_HYPER;
     161           0 : "in" return TOK_IN;
     162           0 : "inout" return TOK_INOUT;
     163           0 : "interface" return TOK_INTERFACE;
     164           0 : "long" return TOK_LONG;
     165           0 : "maybeambiguous" return TOK_MAYBEAMBIGUOUS;
     166           0 : "maybedefault" return TOK_MAYBEDEFAULT;
     167           0 : "maybevoid" return TOK_MAYBEVOID;
     168           0 : "module" return TOK_MODULE;
     169           0 : "optional" return TOK_OPTIONAL;
     170           0 : "out" return TOK_OUT;
     171           0 : "property" return TOK_PROPERTY;
     172           0 : "published" return TOK_PUBLISHED;
     173           0 : "raises" return TOK_RAISES;
     174           0 : "readonly" return TOK_READONLY;
     175           0 : "removable" return TOK_REMOVABLE;
     176           0 : "sequence" return TOK_SEQUENCE;
     177           0 : "service" return TOK_SERVICE;
     178           0 : "set" return TOK_SET;
     179           0 : "short" return TOK_SHORT;
     180           0 : "singleton" return TOK_SINGLETON;
     181           0 : "string" return TOK_STRING;
     182           0 : "struct" return TOK_STRUCT;
     183           0 : "transient" return TOK_TRANSIENT;
     184           0 : "type" return TOK_TYPE;
     185           0 : "typedef" return TOK_TYPEDEF;
     186           0 : "unsigned" return TOK_UNSIGNED;
     187           0 : "void" return TOK_VOID;
     188             : 
     189             : {UPPER}("_"?{ALNUM})*|{LOWER}{ALNUM}* {
     190           0 :     yylval->sval = new OString(yytext);
     191           0 :     return TOK_IDENTIFIER;
     192             : }
     193             : 
     194             : ({ALPHA}|"_")({ALNUM}|"_")* {
     195             : #if 1 //TODO
     196           0 :     yylval->sval=new OString(yytext);return TOK_IDENTIFIER;
     197             : #else
     198             :     yyextra->errorMessage = "illegal identifier "
     199             :         + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
     200             :     return TOK_ERROR;
     201             : #endif
     202             : }
     203             : 
     204             : 0+[LUlu]? |
     205             : 0[Xx]0+[LUlu]? {
     206           0 :     yylval->ival = 0;
     207           0 :     return TOK_INTEGER;
     208             : }
     209             : 
     210             : 0[0-7]+[LUlu]? {
     211           0 :     return nonZeroIntegerLiteral(yytext, yyleng, 8, &yylval->ival, yyextra);
     212             : }
     213             : 
     214             : [1-9]{DIGIT}*[LUlu]? {
     215           0 :     return nonZeroIntegerLiteral(yytext, yyleng, 10, &yylval->ival, yyextra);
     216             : }
     217             : 
     218             : 0[Xx][0-9A-Fa-f]+[LUlu]? {
     219             :     return nonZeroIntegerLiteral(
     220           0 :         yytext + 2, yyleng - 2, 16, &yylval->ival, yyextra);
     221             : }
     222             : 
     223             : {DIGIT}+[Ee][+\-]?{DIGIT}+[Ff]? |
     224             : {DIGIT}*"."{DIGIT}+([Ee][+\-]?{DIGIT}+)?[Ff]? {
     225             :     rtl_math_ConversionStatus s;
     226             :     yylval->fval = rtl_math_stringToDouble(
     227           0 :         yytext, yytext + yyleng, '.', 0, &s, 0);
     228           0 :     if (s == rtl_math_ConversionStatus_OutOfRange) {
     229           0 :         yyextra->errorMessage = "out-of-range floating-point literal "
     230           0 :             + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
     231           0 :         return TOK_ERROR;
     232             :     }
     233           0 :     return TOK_FLOATING;
     234             : }
     235             : 
     236             : {DIGIT}({ALNUM}|"_")* {
     237           0 :     yyextra->errorMessage = "illegal numeric literal "
     238           0 :         + OUString(yytext, yyleng, RTL_TEXTENCODING_ASCII_US);
     239           0 :     return TOK_ERROR;
     240             : }
     241             : 
     242             : . {
     243           0 :     unsigned char c = yytext[0];
     244           0 :     yyextra->errorMessage = c >= ' ' && c <= '~'
     245           0 :         ? OUString("invalid character \"" + OUString(sal_Unicode(c)) + "\"")
     246             :         : OUString(
     247           0 :             "invalid byte x" + OUString::number(c, 16).toAsciiUpperCase());
     248           0 :     return TOK_ERROR;
     249             : }
     250             : 
     251           0 : %%
     252           0 : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10