LCOV - code coverage report
Current view: top level - l10ntools/source - srclex.l (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 97 64.9 %
Date: 2014-11-03 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             : #include "sal/config.h"
      26             : 
      27             : /* enlarge token buffer to tokenize whole strings */
      28             : #undef YYLMAX
      29             : #define YYLMAX 64000
      30             : 
      31             : /* to enable debug output define LEXDEBUG */
      32             : #define LEXDEBUG                1
      33             : #ifdef LEXDEBUG
      34             : #define OUTPUT  fprintf
      35             : #else
      36             : #define OUTPUT(Par1,Par2);
      37             : #endif
      38             : 
      39             : /* table of possible token ids */
      40             : #include "tokens.h"
      41             : #include <stdlib.h>
      42             : #include <stdio.h>
      43             : 
      44             : #include "sal/main.h"
      45             : 
      46             : #include "srclex.hxx"
      47             : 
      48             : #ifdef __GNUC__
      49             : #pragma GCC diagnostic ignored "-Wunused-function"
      50             : #pragma GCC diagnostic ignored "-Wunused-label"
      51             : #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
      52             : #elif defined _MSC_VER
      53             : #pragma warning(push, 1)
      54             : #endif
      55             : #define YY_NO_UNISTD_H
      56             : 
      57             : /* forwards */
      58             : void YYWarning();
      59             : %}
      60             : 
      61             : %option yylineno
      62             : %option never-interactive
      63             : 
      64             : %p 24000
      65             : %e 1200
      66             : %n 500
      67             : 
      68             : %%
      69             : 
      70             : ^[\t ]*"#pragma".*    {
      71           0 :         WorkOnTokenSet( PRAGMA, yytext );
      72             : }
      73           0 : 
      74             : ^[ \t]*\n {
      75         386 :         WorkOnTokenSet( EMPTYLINE, yytext );
      76         386 : }
      77         386 : 
      78             : [\t ]+                          |
      79             : ^[\t ]*"#include".*   |
      80             : ^[\t ]*"#undef".*     |
      81             : "//".*                                |
      82             : ";"                           |
      83             : "<"                                        |
      84             : ">"                                        |
      85             : \n      {
      86        4830 :         WorkOnTokenSet( IGNOREDTOKENS, yytext );
      87        4830 : }
      88        4830 : "/*"  {
      89          28 :         char c1 = 0;
      90          56 :         int c2 = yyinput();
      91             :         char pChar[2];
      92          28 :         pChar[1] = 0x00;
      93          28 :         pChar[0] = c2;
      94             : 
      95          28 :         WorkOnTokenSet( COMMENT, yytext );
      96          28 :         WorkOnTokenSet( COMMENT, pChar );
      97             :         for(;;) {
      98        7548 :                 if ( c2 == EOF )
      99           0 :                         break;
     100        7548 :                 if ( c1 == '*' && c2 == '/' )
     101          28 :                         break;
     102        7520 :                 c1 = c2;
     103        7520 :                 c2 = yyinput();
     104        7520 :                 pChar[0] = c2;
     105        7520 :                 WorkOnTokenSet( COMMENT, pChar );
     106        7520 :         }
     107             : }
     108          28 : 
     109             : ^[\t ]*"#ifndef".+$   |
     110           4 : ^[\t ]*"#ifdef".+$    |
     111           4 : ^[\t ]*"#if".+$               |
     112           4 : ^[\t ]*"#elif".*$     |
     113           4 : ^[\t ]*"#else".*$     |
     114             : ^[\t ]*"#endif".*$    {
     115          86 :         WorkOnTokenSet( CONDITION, yytext );
     116             : }
     117          86 : 
     118             : [a-zA-Z]+[\t ]+[^={\n]+[\t ] {
     119           0 : /* defined Res */
     120           0 :         WorkOnTokenSet( DEFINEDRES, yytext );
     121             : }
     122           0 : 
     123             : [a-zA-Z]+[ \t]+[^={;\n]+\n[ \t]*"#".*\n[ \t]*"{"    |
     124             : [a-zA-Z]+[ \t]+[^={;\n]+\n?([ \t]*"//".*\n)*[ \t]*"{"       {
     125             : /* RESOURCE // String TTT_XX ... */
     126          23 :         WorkOnTokenSet( RESOURCE, yytext );
     127             : }
     128          23 : 
     129             : ^[\t ]*[a-zA-Z_]+[\t ]*"\\"?[\t ]*\n?[ \t]*"{"[\t ]*"\\"? {
     130             : /* SMALRESOURCE // String ... */
     131         364 :         WorkOnTokenSet( SMALRESOURCE, yytext );
     132             : }
     133         364 : 
     134             : [\t ]*[a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?=[ \t]*L?\".*\".*\n?   {
     135             : /* TEXTLINE // TextTyp = "A Text" */
     136         333 :         WorkOnTokenSet( TEXTLINE, yytext );
     137             : }
     138         333 : 
     139             : [\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]*))*; {
     140             : /* LONGTEXTLINE // TextTyp = "A Text" HHH_XXX "A Text" ZZZ_TTT ... */
     141           0 :         WorkOnTokenSet( LONGTEXTLINE, yytext );
     142             : }
     143           0 : 
     144             : \".*\" {
     145           0 : /* TEXT // "A Text" */
     146           0 :         WorkOnTokenSet( TEXT, yytext );
     147             : }
     148           0 : 
     149             : "{"[ \t]*\\?  {
     150          59 : /* LEVELUP */
     151          59 :         WorkOnTokenSet( LEVELUP, yytext );
     152             : }
     153          59 : 
     154             : "}"[ \t]*;([ \t]*\\)? {
     155         446 : /* LEVELDOWN */
     156         446 :         WorkOnTokenSet( LEVELDOWN, yytext );
     157             : }
     158         446 : 
     159             : [a-zA-Z0-9_]+[ \t]*"="[ \t]*"MAP_APPFONT"[ \t]*"(".+")".*       {
     160           4 : /* APPFONTMAPPING  Typ = MAP_APPFONT( ... ) */
     161           4 :         WorkOnTokenSet( APPFONTMAPPING, yytext );
     162             : }
     163           4 : 
     164             : [a-zA-Z0-9_]+[ \t]*"="[\t ]*([ \t]*"//".*\n)*.*     |
     165             : [a-zA-Z0-9_]+[ \t]*"=".*      {
     166             : /* ASSIGNMENT  Typ = ...  */
     167         888 :  WorkOnTokenSet( ASSIGNMENT, yytext );
     168             : }
     169         888 : 
     170             : 
     171             : 
     172           0 : [a-zA-Z0-9_]+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*"<" {
     173             : /* LISTASSIGNMENT  Typ [ ... ] = ... */
     174           0 :         WorkOnTokenSet( LISTASSIGNMENT, yytext );
     175             : }
     176           0 : 
     177             : "StringList"+[ \t]*("["[ \t]*[a-zA-Z0-9_\-]+[ \t]*"]"[ \t]*)?"="[ \t]*(\\[ \t]*)?\n?[ \t]*"{"[ \t]*(\\[ \t]*)?\n?[ \t]*       {
     178             : /* LISTASSIGNMENT  Typ [ ... ] = ... */
     179           0 :         WorkOnTokenSet( LISTASSIGNMENT, yytext );
     180             : }
     181           0 : 
     182             : "<"?[ \t]*L?\".*\".*">" {
     183           0 : /* LISTTEXT */
     184           0 :         WorkOnTokenSet( LISTTEXT, yytext );
     185             : }
     186           0 : 
     187             : [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.*"\\"    {
     188         230 : /* RSCDEFINE  #define ... */
     189         230 :         WorkOnTokenSet( RSCDEFINE, yytext );
     190             : }
     191         230 : 
     192             : [ \t]*"#define"[ \t]+[a-zA-Z0-9_]+.+ {
     193           7 : /* #define ... */
     194           7 :         WorkOnTokenSet( NORMDEFINE, yytext );
     195             : }
     196           7 : 
     197             : "\\" {
     198          48 : /* RSCDEFINELEND */
     199          48 :         WorkOnTokenSet( RSCDEFINELEND, yytext );
     200             : }
     201          48 : 
     202             : [a-zA-Z0-9_]+[ \t]*; {
     203           0 : /* allowed other tokens like "49 ;" or "SFX_... ;" */
     204           0 :         WorkOnTokenSet( ANYTOKEN, yytext );
     205             : }
     206           0 : 
     207             : .       {
     208        8313 :         WorkOnTokenSet( UNKNOWNCHAR, yytext );
     209             : /*      YYWarning( "Unknown Char" ); */
     210             : }
     211        8313 : 
     212             : "{"?[ \t]*\".*\"[ \t]*";"[ \t]*"}" {
     213           0 : /* _LISTTEXT */
     214           0 :         WorkOnTokenSet( _LISTTEXT, yytext );
     215             : }
     216           0 : 
     217           0 : %%
     218           0 : 
     219             : /*****************************************************************************/
     220             : int     yywrap(void)
     221           8 : /*****************************************************************************/
     222             : {
     223             :         return 1;
     224           8 : }
     225             : 
     226             : /*****************************************************************************/
     227             : void YYWarning( const char *s )
     228           0 : /*****************************************************************************/
     229             : {
     230             :         /* write warning to stderr */
     231             :         fprintf( stderr, "Warning: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
     232           0 : }
     233           0 : 
     234             : /*****************************************************************************/
     235             : void yyerror( const char *s )
     236           0 : /*****************************************************************************/
     237             : {
     238             :         /* write error to stderr */
     239             :         fprintf( stderr, "Error: \"%s\" in line %d: \"%s\"\n", s, yylineno, yytext  );
     240           0 :         SetError();
     241           0 : }
     242           0 : 
     243             : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
     244          16 :     int e;
     245             :     yyin = init(argc, argv);
     246           8 :     yylex();
     247           8 :     e = GetError();
     248           8 :     Close();
     249           8 :     return EXIT_SUCCESS;
     250           8 : }

Generated by: LCOV version 1.10