update credits
[LibreOffice.git] / include / comphelper / syntaxhighlight.hxx
blobef1a9486a6bf7c0d6bf908517bb5c54bae09600c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _COMPHELPER_SYNTAXHIGHLIGHT_HXX
20 #define _COMPHELPER_SYNTAXHIGHLIGHT_HXX
22 #include <vector>
23 #include <rtl/ustring.hxx>
25 #include <comphelper/comphelperdllapi.h>
28 #if defined CDECL
29 #undef CDECL
30 #endif
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
44 // Token-Typen TT_...
45 enum TokenTypes
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
60 struct HighlightPortion { sal_uInt16 nBegin; sal_uInt16 nEnd; TokenTypes tokenType; };
63 typedef std::vector<HighlightPortion> HighlightPortions;
65 /////////////////////////////////////////////////////////////////////////
66 // Auxiliary class to support JavaScript modules, next to find functions which
67 // will later will be used for syntax highlighting
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
81 #define CHAR_EOF 0x00
84 // Language mode of the Highlighter (possibly to be refined later with keyword
85 // lists, C comment flags)
86 enum HighlighterLanguage
88 HIGHLIGHT_BASIC,
89 HIGHLIGHT_SQL
92 class SimpleTokenizer_Impl
94 HighlighterLanguage aLanguage;
95 // Character information tables
96 sal_uInt16 aCharTypeTab[256];
98 const sal_Unicode* mpStringBegin;
99 const sal_Unicode* mpActualPos;
101 // Lines and columns
102 sal_uInt32 nLine;
103 sal_uInt32 nCol;
105 sal_Unicode peekChar( void ) { return *mpActualPos; }
106 sal_Unicode getChar( void ) { nCol++; return *mpActualPos++; }
108 // Auxiliary function: testing of the character flags
109 sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags );
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 );
115 const char** ppListKeyWords;
116 sal_uInt16 nKeyWordCount;
118 public:
119 SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC );
120 ~SimpleTokenizer_Impl( void );
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 );
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
136 HighlighterLanguage eLanguage;
137 SimpleTokenizer_Impl* m_pSimpleTokenizer;
138 char* m_pKeyWords;
139 sal_uInt16 m_nKeyWordCount;
141 // void initializeKeyWords( HighlighterLanguage eLanguage );
143 public:
144 SyntaxHighlighter( void );
145 ~SyntaxHighlighter( void );
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_ );
152 void notifyChange( sal_uInt32 nLine, sal_Int32 nLineCountDifference,
153 const OUString* pChangedLines, sal_uInt32 nArrayLength);
155 void getHighlightPortions( sal_uInt32 nLine, const OUString& rLine,
156 HighlightPortions& pPortions );
158 HighlighterLanguage GetLanguage() { return eLanguage;}
160 #endif
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */