LCOV - code coverage report
Current view: top level - libreoffice/l10ntools/source - srclex.l (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 102 78.4 %
Date: 2012-12-27 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : 
       2             : %{
       3             : /*
       4             :  * This file is part of the LibreOffice project.
       5             :  *
       6             :  * This Source Code Form is subject to the terms of the Mozilla Public
       7             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       8             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       9             :  *
      10             :  * This file incorporates work covered by the following license notice:
      11             :  *
      12             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      13             :  *   contributor license agreements. See the NOTICE file distributed
      14             :  *   with this work for additional information regarding copyright
      15             :  *   ownership. The ASF licenses this file to you under the Apache
      16             :  *   License, Version 2.0 (the "License"); you may not use this file
      17             :  *   except in compliance with the License. You may obtain a copy of
      18             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      19             :  */
      20             : 
      21             : /*
      22             :  * lexer for parsing resource source files (*.src)
      23             :  */
      24             : 
      25             : /* enlarge token buffer to tokenize whole strings */
      26             : #undef YYLMAX
      27             : #define YYLMAX 64000
      28             : 
      29             : /* to enable debug output define LEXDEBUG */
      30             : #define LEXDEBUG                1
      31             : #ifdef LEXDEBUG
      32             : #define OUTPUT  fprintf
      33             : #else
      34             : #define OUTPUT(Par1,Par2);
      35             : #endif
      36             : 
      37             : /* table of possible token ids */
      38             : #include "tokens.h"
      39             : #include <stdlib.h>
      40             : #include <stdio.h>
      41             : 
      42             : #include "sal/main.h"
      43             : 
      44             : #if defined __GNUC__
      45             : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
      46             : #pragma GCC diagnostic ignored "-Wunused-function"
      47             : #pragma GCC diagnostic ignored "-Wunused-label"
      48             : #endif
      49             : #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
      50             : #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
      51             : #endif
      52             : #elif defined __SINPRO_CC
      53             : #pragma disable_warn
      54             : #elif defined _MSC_VER
      55             : #pragma warning(push, 1)
      56             : #endif
      57             : 
      58             : /* external functions (C++ code, declared as extern "C" */
      59             : extern "C" int WorkOnTokenSet( int, char* );
      60             : extern "C" FILE * init(int, char **);
      61             : extern "C" int SetError();
      62             : extern "C" int GetError();
      63             : extern "C" void Close();
      64             : 
      65             : /* forwards */
      66             : void YYWarning();
      67             : %}
      68             : 
      69             : %option yylineno
      70             : %option never-interactive
      71             : 
      72             : %p 24000
      73             : %e 1200
      74             : %n 500
      75             : 
      76             : %%
      77             : 
      78             : ^[\t ]*"#pragma".*    {
      79           0 :         WorkOnTokenSet( PRAGMA, yytext );
      80             : }
      81           0 : 
      82             : ^[ \t]*\n {
      83         541 :         WorkOnTokenSet( EMPTYLINE, yytext );
      84         541 : }
      85         541 : 
      86             : [\t ]+                          |
      87             : ^[\t ]*"#include".*   |
      88             : ^[\t ]*"#undef".*     |
      89             : "//".*                                |
      90             : ";"                           |
      91             : "<"                                        |
      92             : ">"                                        |
      93             : \n      {
      94        6797 :         WorkOnTokenSet( IGNOREDTOKENS, yytext );
      95        6797 : }
      96        6797 : "/*"  {
      97          18 :         char c1 = 0;
      98          36 :         int c2 = yyinput();
      99             :         char pChar[2];
     100          18 :         pChar[1] = 0x00;
     101          18 :         pChar[0] = c2;
     102             : 
     103          18 :         WorkOnTokenSet( COMMENT, yytext );
     104          18 :         WorkOnTokenSet( COMMENT, pChar );
     105       11959 :         for(;;) {
     106       11977 :                 if ( c2 == EOF )
     107           0 :                         break;
     108       11977 :                 if ( c1 == '*' && c2 == '/' )
     109          18 :                         break;
     110       11959 :                 c1 = c2;
     111       11959 :                 c2 = yyinput();
     112       11959 :                 pChar[0] = c2;
     113       11959 :                 WorkOnTokenSet( COMMENT, pChar );
     114             :         }
     115             : }
     116          18 : 
     117             : ^[\t ]*"#ifndef".+$   |
     118          12 : ^[\t ]*"#ifdef".+$    |
     119          12 : ^[\t ]*"#if".+$               |
     120          12 : ^[\t ]*"#elif".*$     |
     121          12 : ^[\t ]*"#else".*$     |
     122             : ^[\t ]*"#endif".*$    {
     123         137 :         WorkOnTokenSet( CONDITION, yytext );
     124             : }
     125         137 : 
     126             : [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
     127          11 : /* defined Res */
     128          11 :         WorkOnTokenSet( DEFINEDRES, yytext );
     129             : }
     130          11 : 
     131             : [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{"    |
     132             : [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{"       {
     133             : /* RESOURCE // String TTT_XX ... */
     134         143 :         WorkOnTokenSet( RESOURCE, yytext );
     135             : }
     136         143 : 
     137             : ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
     138             : /* SMALRESOURCE // String ... */
     139         385 :         WorkOnTokenSet( SMALRESOURCE, yytext );
     140             : }
     141         385 : 
     142             : [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n?   {
     143             : /* TEXTLINE // TextTyp = "A Text" */
     144         432 :         WorkOnTokenSet( TEXTLINE, yytext );
     145             : }
     146         432 : 
     147             : [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?(\n[ \t]*)?=([ \t]*\n)?(([a-zA-Z0-9_]+)|(\".*\")|([ \t\n]*))*\".*\"(([a-zA-Z0-9_]+)|(\".*\")|([ \t\n]*))*; {
     148             : /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
     149           0 :         WorkOnTokenSet( LONGTEXTLINE, yytext );
     150             : }
     151           0 : 
     152             : \".*\" {
     153          19 : /* TEXT // "A Text" */
     154          19 :         WorkOnTokenSet( TEXT, yytext );
     155             : }
     156          19 : 
     157             : "{"[ \t]*\\?  {
     158          59 : /* LEVELUP */
     159          59 :         WorkOnTokenSet( LEVELUP, yytext );
     160             : }
     161          59 : 
     162             : "}"[ \t]*;([ \t]*\\)? {
     163         591 : /* LEVELDOWN */
     164         591 :         WorkOnTokenSet( LEVELDOWN, yytext );
     165             : }
     166         591 : 
     167             : [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".*       {
     168         233 : /* APPFONTMAPPING  Typ = MAP_APPFONT( ... ) */
     169         233 :         WorkOnTokenSet( APPFONTMAPPING, yytext );
     170             : }
     171         233 : 
     172             : [ \t]*[a-zA-Z0-9_]+[ \t]*=[ \t]*[0123456789]{1,5}[ \t]*";"?\\? {
     173          12 : /* TEXTREFID // TextTyp = 12345 */
     174          12 :         WorkOnTokenSet( TEXTREFID, yytext );
     175             : }
     176          12 : 
     177             : [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.*     |
     178             : [a-zA-Z0-9_]+[ \t]*"=".*      {
     179             : /* ASSIGNMENT  Typ = ...  */
     180        1115 :  WorkOnTokenSet( ASSIGNMENT, yytext );
     181             : }
     182        1115 : 
     183             : 
     184             : 
     185           1 : [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
     186             : /* LISTASSIGNMENT  Typ [ ... ] = ... */
     187           1 :         WorkOnTokenSet( LISTASSIGNMENT, yytext );
     188             : }
     189           1 : 
     190             : "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*       {
     191             : /* LISTASSIGNMENT  Typ [ ... ] = ... */
     192           3 :         WorkOnTokenSet( LISTASSIGNMENT, yytext );
     193             : }
     194           3 : 
     195             : "UIEntries"[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"   {
     196             : /* UIENTRIES */
     197           0 :         WorkOnTokenSet( UIENTRIES, yytext );
     198             : }
     199           0 : 
     200             : "<"?[ \t]*L?\".*\".*">" {
     201           4 : /* LISTTEXT */
     202           4 :         WorkOnTokenSet( LISTTEXT, yytext );
     203             : }
     204           4 : 
     205             : [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\"    {
     206         274 : /* RSCDEFINE  #define ... */
     207         274 :         WorkOnTokenSet( RSCDEFINE, yytext );
     208             : }
     209         274 : 
     210             : [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
     211          73 : /* #define ... */
     212          73 :         WorkOnTokenSet( NORMDEFINE, yytext );
     213             : }
     214          73 : 
     215             : "\\" {
     216         240 : /* RSCDEFINELEND */
     217         240 :         WorkOnTokenSet( RSCDEFINELEND, yytext );
     218             : }
     219         240 : 
     220             : [a-zA-Z0-9_]+[ \t]*; {
     221           0 : /* allowed other tokens like "49 ;" or "SFX_... ;" */
     222           0 :         WorkOnTokenSet( ANYTOKEN, yytext );
     223             : }
     224           0 : 
     225             : .       {
     226        8868 :         WorkOnTokenSet( UNKNOWNCHAR, yytext );
     227             : /*      YYWarning( "Unknown Char" ); */
     228             : }
     229        8868 : 
     230             : "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
     231           0 : /* _LISTTEXT */
     232           0 :         WorkOnTokenSet( _LISTTEXT, yytext );
     233             : }
     234           0 : 
     235           0 : %%
     236           0 : 
     237             : /*****************************************************************************/
     238             : int     yywrap(void)
     239          14 : /*****************************************************************************/
     240             : {
     241             :         return 1;
     242          14 : }
     243             : 
     244             : /*****************************************************************************/
     245             : void YYWarning( const char *s )
     246           0 : /*****************************************************************************/
     247             : {
     248             :         /* write warning to stderr */
     249             :         fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
     250           0 : }
     251           0 : 
     252             : /*****************************************************************************/
     253             : void yyerror( const char *s )
     254           0 : /*****************************************************************************/
     255             : {
     256             :         /* write error to stderr */
     257             :         fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
     258           0 :         SetError();
     259           0 : }
     260           0 : 
     261             : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
     262          28 :     int e;
     263             :     yyin = init(argc, argv);
     264          14 :     yylex();
     265          14 :     e = GetError();
     266          14 :     Close();
     267          14 :     return EXIT_SUCCESS;
     268          14 : }

Generated by: LCOV version 1.10