1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
23 #include <rtl/ustring.hxx>
25 #include <comphelper/comphelperdllapi.h>
40 #include <sys/resource.h>
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
84 // Language mode of the Highlighter (possibly to be refined later with keyword
85 // lists, C comment flags)
86 enum HighlighterLanguage
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
;
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
;
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
;
139 sal_uInt16 m_nKeyWordCount
;
141 // void initializeKeyWords( HighlighterLanguage eLanguage );
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
;}
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */