LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/comphelper - syntaxhighlight.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 3 0.0 %
Date: 2013-07-09 Functions: 0 3 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef _COMPHELPER_SYNTAXHIGHLIGHT_HXX
      20             : #define _COMPHELPER_SYNTAXHIGHLIGHT_HXX
      21             : 
      22             : #include <vector>
      23             : #include <rtl/ustring.hxx>
      24             : 
      25             : #include <comphelper/comphelperdllapi.h>
      26             : 
      27             : 
      28             : #if defined CDECL
      29             : #undef CDECL
      30             : #endif
      31             : 
      32             : // for the bsearch
      33             : #ifdef WNT
      34             : #define CDECL _cdecl
      35             : #endif
      36             : #if defined(UNX)
      37             : #define CDECL
      38             : #endif
      39             : #ifdef UNX
      40             : #include <sys/resource.h>
      41             : #endif
      42             : 
      43             : 
      44             : // Token-Typen TT_...
      45             : enum TokenTypes
      46             : {
      47             :     TT_UNKNOWN,
      48             :     TT_IDENTIFIER,
      49             :     TT_WHITESPACE,
      50             :     TT_NUMBER,
      51             :     TT_STRING,
      52             :     TT_EOL,
      53             :     TT_COMMENT,
      54             :     TT_ERROR,
      55             :     TT_OPERATOR,
      56             :     TT_KEYWORDS,
      57             :     TT_PARAMETER
      58             : };
      59             : 
      60             : struct HighlightPortion { sal_uInt16 nBegin; sal_uInt16 nEnd; TokenTypes tokenType; };
      61             : 
      62             : 
      63             : typedef std::vector<HighlightPortion> HighlightPortions;
      64             : 
      65             : /////////////////////////////////////////////////////////////////////////
      66             : // Auxiliary class to support JavaScript modules, next to find functions which
      67             : // will later will be used for syntax highlighting
      68             : 
      69             : // Flags for character properties
      70             : #define CHAR_START_IDENTIFIER   0x0001
      71             : #define CHAR_IN_IDENTIFIER      0x0002
      72             : #define CHAR_START_NUMBER       0x0004
      73             : #define CHAR_IN_NUMBER          0x0008
      74             : #define CHAR_IN_HEX_NUMBER      0x0010
      75             : #define CHAR_IN_OCT_NUMBER      0x0020
      76             : #define CHAR_START_STRING       0x0040
      77             : #define CHAR_OPERATOR           0x0080
      78             : #define CHAR_SPACE              0x0100
      79             : #define CHAR_EOL                0x0200
      80             : 
      81             : #define CHAR_EOF                0x00
      82             : 
      83             : 
      84             : // Language mode of the Highlighter (possibly to be refined later with keyword
      85             : // lists, C comment flags)
      86             : enum HighlighterLanguage
      87             : {
      88             :     HIGHLIGHT_BASIC,
      89             :     HIGHLIGHT_SQL
      90             : };
      91             : 
      92             : class SimpleTokenizer_Impl
      93             : {
      94             :     HighlighterLanguage aLanguage;
      95             :     // Character information tables
      96             :     sal_uInt16 aCharTypeTab[256];
      97             : 
      98             :     const sal_Unicode* mpStringBegin;
      99             :     const sal_Unicode* mpActualPos;
     100             : 
     101             :     // Lines and columns
     102             :     sal_uInt32 nLine;
     103             :     sal_uInt32 nCol;
     104             : 
     105           0 :     sal_Unicode peekChar( void )    { return *mpActualPos; }
     106           0 :     sal_Unicode getChar( void )     { nCol++; return *mpActualPos++; }
     107             : 
     108             :     // Auxiliary function: testing of the character flags
     109             :     sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags );
     110             : 
     111             :     // Get new token, EmptyString == nothing more over there
     112             :     sal_Bool getNextToken( /*out*/TokenTypes& reType,
     113             :         /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos );
     114             : 
     115             :     const char** ppListKeyWords;
     116             :     sal_uInt16 nKeyWordCount;
     117             : 
     118             : public:
     119             :     SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC );
     120             :     ~SimpleTokenizer_Impl( void );
     121             : 
     122             :     sal_uInt16 parseLine( sal_uInt32 nLine, const OUString* aSource );
     123             :     void getHighlightPortions( sal_uInt32 nParseLine, const OUString& rLine,
     124             :                                                     /*out*/HighlightPortions& portions );
     125             :     void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount );
     126             : };
     127             : 
     128             : 
     129             : //*** SyntaxHighlighter Class ***
     130             : // Concept: the Highlighter will be notified of all changes in the source
     131             : // (notifyChange) and returns the caller the range of lines, which based on the
     132             : // changes, need to be highlighted again. For this the Highlighter marks all
     133             : // lines internally whether or not C comments begin or end.
     134             : class COMPHELPER_DLLPUBLIC SyntaxHighlighter
     135             : {
     136             :     HighlighterLanguage eLanguage;
     137             :     SimpleTokenizer_Impl* m_pSimpleTokenizer;
     138             :     char* m_pKeyWords;
     139             :     sal_uInt16 m_nKeyWordCount;
     140             : 
     141             : //  void initializeKeyWords( HighlighterLanguage eLanguage );
     142             : 
     143             : public:
     144             :     SyntaxHighlighter( void );
     145             :     ~SyntaxHighlighter( void );
     146             : 
     147             :     // (Re-)initialize Highlighter. The line-table will be completely erased,
     148             :     // meaning that on completion an empty Source is assumed.
     149             :     // notifyChange() can only be given line 0
     150             :     void initialize( HighlighterLanguage eLanguage_ );
     151             : 
     152             :     void notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference,
     153             :                                 const OUString* pChangedLines, sal_uInt32 nArrayLength);
     154             : 
     155             :     void getHighlightPortions( sal_uInt32 nLine, const OUString& rLine,
     156             :                                             HighlightPortions& pPortions );
     157             : 
     158           0 :     HighlighterLanguage GetLanguage() { return eLanguage;}
     159             : };
     160             : #endif
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10