Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _SVTOOLS_SYNTAXHIGHLIGHT_HXX
29 : : #define _SVTOOLS_SYNTAXHIGHLIGHT_HXX
30 : :
31 : : #include <list>
32 : :
33 : : #include <osl/mutex.hxx>
34 : :
35 : : #include <vcl/svapp.hxx>
36 : :
37 : : #include <tools/stream.hxx>
38 : : #include <tools/shl.hxx>
39 : :
40 : : #include <svl/brdcst.hxx>
41 : : #include <svtools/svtdllapi.h>
42 : :
43 : :
44 : : #if defined CDECL
45 : : #undef CDECL
46 : : #endif
47 : :
48 : : // for the bsearch
49 : : #ifdef WNT
50 : : #define CDECL _cdecl
51 : : #endif
52 : : #if defined(UNX)
53 : : #define CDECL
54 : : #endif
55 : : #ifdef UNX
56 : : #include <sys/resource.h>
57 : : #endif
58 : :
59 : : #include <stdio.h>
60 : :
61 : : #include <tools/string.hxx>
62 : : #include <tools/gen.hxx>
63 : :
64 : :
65 : : // Token-Typen TT_...
66 : : enum TokenTypes
67 : : {
68 : : TT_UNKNOWN,
69 : : TT_IDENTIFIER,
70 : : TT_WHITESPACE,
71 : : TT_NUMBER,
72 : : TT_STRING,
73 : : TT_EOL,
74 : : TT_COMMENT,
75 : : TT_ERROR,
76 : : TT_OPERATOR,
77 : : TT_KEYWORDS,
78 : : TT_PARAMETER
79 : : };
80 : :
81 : : struct HighlightPortion { sal_uInt16 nBegin; sal_uInt16 nEnd; TokenTypes tokenType; };
82 : :
83 : :
84 : : typedef std::vector<HighlightPortion> HighlightPortions;
85 : :
86 : : /////////////////////////////////////////////////////////////////////////
87 : : // Hilfsklasse zur Untersuchung von JavaScript-Modulen, zunaechst zum
88 : : // Heraussuchen der Funktionen, spaeter auch zum Syntax-Highlighting verwenden
89 : :
90 : : // Flags fuer Zeichen-Eigenschaften
91 : : #define CHAR_START_IDENTIFIER 0x0001
92 : : #define CHAR_IN_IDENTIFIER 0x0002
93 : : #define CHAR_START_NUMBER 0x0004
94 : : #define CHAR_IN_NUMBER 0x0008
95 : : #define CHAR_IN_HEX_NUMBER 0x0010
96 : : #define CHAR_IN_OCT_NUMBER 0x0020
97 : : #define CHAR_START_STRING 0x0040
98 : : #define CHAR_OPERATOR 0x0080
99 : : #define CHAR_SPACE 0x0100
100 : : #define CHAR_EOL 0x0200
101 : :
102 : : #define CHAR_EOF 0x00
103 : :
104 : :
105 : : // Sprachmodus des HighLighters (spaeter eventuell feiner
106 : : // differenzieren mit Keyword-Liste, C-Kommentar-Flag)
107 : : enum HighlighterLanguage
108 : : {
109 : : HIGHLIGHT_BASIC,
110 : : HIGHLIGHT_SQL
111 : : };
112 : :
113 : : class SimpleTokenizer_Impl
114 : : {
115 : : HighlighterLanguage aLanguage;
116 : : // Zeichen-Info-Tabelle
117 : : sal_uInt16 aCharTypeTab[256];
118 : :
119 : : const sal_Unicode* mpStringBegin;
120 : : const sal_Unicode* mpActualPos;
121 : :
122 : : // Zeile und Spalte
123 : : sal_uInt32 nLine;
124 : : sal_uInt32 nCol;
125 : :
126 : 0 : sal_Unicode peekChar( void ) { return *mpActualPos; }
127 : 0 : sal_Unicode getChar( void ) { nCol++; return *mpActualPos++; }
128 : :
129 : : // Hilfsfunktion: Zeichen-Flag Testen
130 : : sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags );
131 : :
132 : : // Neues Token holen, Leerstring == nix mehr da
133 : : sal_Bool getNextToken( /*out*/TokenTypes& reType,
134 : : /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos );
135 : :
136 : : const char** ppListKeyWords;
137 : : sal_uInt16 nKeyWordCount;
138 : :
139 : : public:
140 : : SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC );
141 : : ~SimpleTokenizer_Impl( void );
142 : :
143 : : sal_uInt16 parseLine( sal_uInt32 nLine, const String* aSource );
144 : : void getHighlightPortions( sal_uInt32 nParseLine, const String& rLine,
145 : : /*out*/HighlightPortions& portions );
146 : : void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount );
147 : : };
148 : :
149 : :
150 : : //*** SyntaxHighlighter-Klasse ***
151 : : // Konzept: Der Highlighter wird ueber alle Aenderungen im Source
152 : : // informiert (notifyChange) und liefert dem Aufrufer jeweils die
153 : : // Information zurueck, welcher Zeilen-Bereich des Source-Codes
154 : : // aufgrund dieser Aenderung neu gehighlighted werden muss.
155 : : // Dazu merkt sich Highlighter intern fuer jede Zeile, ob dort
156 : : // C-Kommentare beginnen oder enden.
157 : : class SVT_DLLPUBLIC SyntaxHighlighter
158 : : {
159 : : HighlighterLanguage eLanguage;
160 : : SimpleTokenizer_Impl* m_pSimpleTokenizer;
161 : : char* m_pKeyWords;
162 : : sal_uInt16 m_nKeyWordCount;
163 : :
164 : : // void initializeKeyWords( HighlighterLanguage eLanguage );
165 : :
166 : : public:
167 : : SyntaxHighlighter( void );
168 : : ~SyntaxHighlighter( void );
169 : :
170 : : // HighLighter (neu) initialisieren, die Zeilen-Tabelle wird
171 : : // dabei komplett geloescht, d.h. im Abschluss wird von einem
172 : : // leeren Source ausgegangen. In notifyChange() kann dann
173 : : // nur Zeile 0 angegeben werden.
174 : : void initialize( HighlighterLanguage eLanguage_ );
175 : :
176 : : const Range notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference,
177 : : const String* pChangedLines, sal_uInt32 nArrayLength);
178 : :
179 : : void getHighlightPortions( sal_uInt32 nLine, const String& rLine,
180 : : HighlightPortions& pPortions );
181 : :
182 : 0 : HighlighterLanguage GetLanguage() { return eLanguage;}
183 : : };
184 : : #endif
185 : :
186 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|