Kaydet (Commit) 6aa24e75 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Move implementation details to syntaxhighlight.cxx

(and clean up a little)

Change-Id: I6e660708d8ca1509b89b306cd428dc38c8b03f2c
üst f5e8be8b
...@@ -56,6 +56,7 @@ class SvxSearchItem; ...@@ -56,6 +56,7 @@ class SvxSearchItem;
#include "com/sun/star/reflection/XIdlClass.hpp" #include "com/sun/star/reflection/XIdlClass.hpp"
#include <comphelper/namedvaluecollection.hxx> #include <comphelper/namedvaluecollection.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <comphelper/syntaxhighlight.hxx>
#include <comphelper/configurationhelper.hxx> #include <comphelper/configurationhelper.hxx>
#include "com/sun/star/reflection/XIdlReflection.hpp" #include "com/sun/star/reflection/XIdlReflection.hpp"
......
...@@ -22,6 +22,18 @@ ...@@ -22,6 +22,18 @@
#include <comphelper/syntaxhighlight.hxx> #include <comphelper/syntaxhighlight.hxx>
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
// Flags for character properties
#define CHAR_START_IDENTIFIER 0x0001
#define CHAR_IN_IDENTIFIER 0x0002
#define CHAR_START_NUMBER 0x0004
#define CHAR_IN_NUMBER 0x0008
#define CHAR_IN_HEX_NUMBER 0x0010
#define CHAR_IN_OCT_NUMBER 0x0020
#define CHAR_START_STRING 0x0040
#define CHAR_OPERATOR 0x0080
#define CHAR_SPACE 0x0100
#define CHAR_EOL 0x0200
// ########################################################################## // ##########################################################################
// ATTENTION: all these words need to be in lower case // ATTENTION: all these words need to be in lower case
// ########################################################################## // ##########################################################################
...@@ -232,7 +244,7 @@ extern "C" int compare_strings( const void *arg1, const void *arg2 ) ...@@ -232,7 +244,7 @@ extern "C" int compare_strings( const void *arg1, const void *arg2 )
namespace namespace
{ {
static bool isAlpha(sal_Unicode c) bool isAlpha(sal_Unicode c)
{ {
if (comphelper::string::isalphaAscii(c)) if (comphelper::string::isalphaAscii(c))
return true; return true;
...@@ -240,8 +252,40 @@ namespace ...@@ -240,8 +252,40 @@ namespace
} }
} }
class SyntaxHighlighter::Tokenizer
{
HighlighterLanguage aLanguage;
// Character information tables
sal_uInt16 aCharTypeTab[256];
const sal_Unicode* mpStringBegin;
const sal_Unicode* mpActualPos;
sal_Unicode peekChar( void ) { return *mpActualPos; }
sal_Unicode getChar( void ) { return *mpActualPos++; }
// Auxiliary function: testing of the character flags
sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags );
// Get new token, EmptyString == nothing more over there
sal_Bool getNextToken( /*out*/TokenTypes& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos );
const char** ppListKeyWords;
sal_uInt16 nKeyWordCount;
public:
Tokenizer( HighlighterLanguage aLang = HIGHLIGHT_BASIC );
~Tokenizer( void );
sal_uInt16 parseLine( const OUString* aSource );
void getHighlightPortions( const OUString& rLine,
/*out*/std::vector<HighlightPortion>& portions );
void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount );
};
// Helper function: test character flag // Helper function: test character flag
sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags ) sal_Bool SyntaxHighlighter::Tokenizer::testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags )
{ {
bool bRet = false; bool bRet = false;
if( c != 0 && c <= 255 ) if( c != 0 && c <= 255 )
...@@ -256,13 +300,13 @@ sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFla ...@@ -256,13 +300,13 @@ sal_Bool SimpleTokenizer_Impl::testCharFlags( sal_Unicode c, sal_uInt16 nTestFla
return bRet; return bRet;
} }
void SimpleTokenizer_Impl::setKeyWords( const char** ppKeyWords, sal_uInt16 nCount ) void SyntaxHighlighter::Tokenizer::setKeyWords( const char** ppKeyWords, sal_uInt16 nCount )
{ {
ppListKeyWords = ppKeyWords; ppListKeyWords = ppKeyWords;
nKeyWordCount = nCount; nKeyWordCount = nCount;
} }
sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, sal_Bool SyntaxHighlighter::Tokenizer::getNextToken( /*out*/TokenTypes& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos ) /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos )
{ {
reType = TT_UNKNOWN; reType = TT_UNKNOWN;
...@@ -539,7 +583,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType, ...@@ -539,7 +583,7 @@ sal_Bool SimpleTokenizer_Impl::getNextToken( /*out*/TokenTypes& reType,
return sal_True; return sal_True;
} }
SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLanguage(aLang) SyntaxHighlighter::Tokenizer::Tokenizer( HighlighterLanguage aLang ): aLanguage(aLang)
{ {
memset( aCharTypeTab, 0, sizeof( aCharTypeTab ) ); memset( aCharTypeTab, 0, sizeof( aCharTypeTab ) );
...@@ -619,19 +663,11 @@ SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLangua ...@@ -619,19 +663,11 @@ SimpleTokenizer_Impl::SimpleTokenizer_Impl( HighlighterLanguage aLang ): aLangua
ppListKeyWords = NULL; ppListKeyWords = NULL;
} }
SimpleTokenizer_Impl::~SimpleTokenizer_Impl( void ) SyntaxHighlighter::Tokenizer::~Tokenizer( void )
{
}
SimpleTokenizer_Impl* getSimpleTokenizer( void )
{ {
static SimpleTokenizer_Impl* pSimpleTokenizer = NULL;
if( !pSimpleTokenizer )
pSimpleTokenizer = new SimpleTokenizer_Impl();
return pSimpleTokenizer;
} }
sal_uInt16 SimpleTokenizer_Impl::parseLine( const OUString* aSource ) sal_uInt16 SyntaxHighlighter::Tokenizer::parseLine( const OUString* aSource )
{ {
// Set the position to the beginning of the source string // Set the position to the beginning of the source string
mpStringBegin = mpActualPos = aSource->getStr(); mpStringBegin = mpActualPos = aSource->getStr();
...@@ -649,7 +685,7 @@ sal_uInt16 SimpleTokenizer_Impl::parseLine( const OUString* aSource ) ...@@ -649,7 +685,7 @@ sal_uInt16 SimpleTokenizer_Impl::parseLine( const OUString* aSource )
return nTokenCount; return nTokenCount;
} }
void SimpleTokenizer_Impl::getHighlightPortions( const OUString& rLine, void SyntaxHighlighter::Tokenizer::getHighlightPortions( const OUString& rLine,
/*out*/std::vector<HighlightPortion>& portions ) /*out*/std::vector<HighlightPortion>& portions )
{ {
// Set the position to the beginning of the source string // Set the position to the beginning of the source string
...@@ -672,35 +708,32 @@ void SimpleTokenizer_Impl::getHighlightPortions( const OUString& rLine, ...@@ -672,35 +708,32 @@ void SimpleTokenizer_Impl::getHighlightPortions( const OUString& rLine,
SyntaxHighlighter::SyntaxHighlighter() SyntaxHighlighter::SyntaxHighlighter()
{ {
m_pSimpleTokenizer = 0;
m_pKeyWords = NULL; m_pKeyWords = NULL;
m_nKeyWordCount = 0; m_nKeyWordCount = 0;
} }
SyntaxHighlighter::~SyntaxHighlighter() SyntaxHighlighter::~SyntaxHighlighter()
{ {
delete m_pSimpleTokenizer;
delete m_pKeyWords; delete m_pKeyWords;
} }
void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ ) void SyntaxHighlighter::initialize( HighlighterLanguage eLanguage_ )
{ {
eLanguage = eLanguage_; eLanguage = eLanguage_;
delete m_pSimpleTokenizer; m_tokenizer.reset(new SyntaxHighlighter::Tokenizer(eLanguage));
m_pSimpleTokenizer = new SimpleTokenizer_Impl(eLanguage);
switch (eLanguage) switch (eLanguage)
{ {
case HIGHLIGHT_BASIC: case HIGHLIGHT_BASIC:
m_pSimpleTokenizer->setKeyWords( strListBasicKeyWords, m_tokenizer->setKeyWords( strListBasicKeyWords,
sizeof( strListBasicKeyWords ) / sizeof( char* )); sizeof( strListBasicKeyWords ) / sizeof( char* ));
break; break;
case HIGHLIGHT_SQL: case HIGHLIGHT_SQL:
m_pSimpleTokenizer->setKeyWords( strListSqlKeyWords, m_tokenizer->setKeyWords( strListSqlKeyWords,
sizeof( strListSqlKeyWords ) / sizeof( char* )); sizeof( strListSqlKeyWords ) / sizeof( char* ));
break; break;
default: default:
m_pSimpleTokenizer->setKeyWords( NULL, 0 ); m_tokenizer->setKeyWords( NULL, 0 );
} }
} }
...@@ -708,13 +741,13 @@ void SyntaxHighlighter::notifyChange( ...@@ -708,13 +741,13 @@ void SyntaxHighlighter::notifyChange(
const OUString* pChangedLines, sal_uInt32 nArrayLength) const OUString* pChangedLines, sal_uInt32 nArrayLength)
{ {
for( sal_uInt32 i=0 ; i < nArrayLength ; i++ ) for( sal_uInt32 i=0 ; i < nArrayLength ; i++ )
m_pSimpleTokenizer->parseLine(&pChangedLines[i]); m_tokenizer->parseLine(&pChangedLines[i]);
} }
void SyntaxHighlighter::getHighlightPortions( const OUString& rLine, void SyntaxHighlighter::getHighlightPortions( const OUString& rLine,
/*out*/std::vector<HighlightPortion>& portions ) /*out*/std::vector<HighlightPortion>& portions )
{ {
m_pSimpleTokenizer->getHighlightPortions( rLine, portions ); m_tokenizer->getHighlightPortions( rLine, portions );
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#define INCLUDED_COMPHELPER_SYNTAXHIGHLIGHT_HXX #define INCLUDED_COMPHELPER_SYNTAXHIGHLIGHT_HXX
#include <vector> #include <vector>
#include <boost/scoped_ptr.hpp>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <comphelper/comphelperdllapi.h> #include <comphelper/comphelperdllapi.h>
...@@ -55,22 +57,6 @@ struct HighlightPortion { ...@@ -55,22 +57,6 @@ struct HighlightPortion {
{} {}
}; };
/////////////////////////////////////////////////////////////////////////
// Auxiliary class to support JavaScript modules, next to find functions which
// will later will be used for syntax highlighting
// Flags for character properties
#define CHAR_START_IDENTIFIER 0x0001
#define CHAR_IN_IDENTIFIER 0x0002
#define CHAR_START_NUMBER 0x0004
#define CHAR_IN_NUMBER 0x0008
#define CHAR_IN_HEX_NUMBER 0x0010
#define CHAR_IN_OCT_NUMBER 0x0020
#define CHAR_START_STRING 0x0040
#define CHAR_OPERATOR 0x0080
#define CHAR_SPACE 0x0100
#define CHAR_EOL 0x0200
// Language mode of the Highlighter (possibly to be refined later with keyword // Language mode of the Highlighter (possibly to be refined later with keyword
// lists, C comment flags) // lists, C comment flags)
enum HighlighterLanguage enum HighlighterLanguage
...@@ -79,39 +65,6 @@ enum HighlighterLanguage ...@@ -79,39 +65,6 @@ enum HighlighterLanguage
HIGHLIGHT_SQL HIGHLIGHT_SQL
}; };
class SimpleTokenizer_Impl
{
HighlighterLanguage aLanguage;
// Character information tables
sal_uInt16 aCharTypeTab[256];
const sal_Unicode* mpStringBegin;
const sal_Unicode* mpActualPos;
sal_Unicode peekChar( void ) { return *mpActualPos; }
sal_Unicode getChar( void ) { return *mpActualPos++; }
// Auxiliary function: testing of the character flags
sal_Bool testCharFlags( sal_Unicode c, sal_uInt16 nTestFlags );
// Get new token, EmptyString == nothing more over there
sal_Bool getNextToken( /*out*/TokenTypes& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos );
const char** ppListKeyWords;
sal_uInt16 nKeyWordCount;
public:
SimpleTokenizer_Impl( HighlighterLanguage aLang = HIGHLIGHT_BASIC );
~SimpleTokenizer_Impl( void );
sal_uInt16 parseLine( const OUString* aSource );
void getHighlightPortions( const OUString& rLine,
/*out*/std::vector<HighlightPortion>& portions );
void setKeyWords( const char** ppKeyWords, sal_uInt16 nCount );
};
//*** SyntaxHighlighter Class *** //*** SyntaxHighlighter Class ***
// Concept: the Highlighter will be notified of all changes in the source // Concept: the Highlighter will be notified of all changes in the source
// (notifyChange) and returns the caller the range of lines, which based on the // (notifyChange) and returns the caller the range of lines, which based on the
...@@ -119,8 +72,10 @@ public: ...@@ -119,8 +72,10 @@ public:
// lines internally whether or not C comments begin or end. // lines internally whether or not C comments begin or end.
class COMPHELPER_DLLPUBLIC SyntaxHighlighter class COMPHELPER_DLLPUBLIC SyntaxHighlighter
{ {
class Tokenizer;
HighlighterLanguage eLanguage; HighlighterLanguage eLanguage;
SimpleTokenizer_Impl* m_pSimpleTokenizer; boost::scoped_ptr<Tokenizer> m_tokenizer;
char* m_pKeyWords; char* m_pKeyWords;
sal_uInt16 m_nKeyWordCount; sal_uInt16 m_nKeyWordCount;
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/vclmedit.hxx> #include <vcl/vclmedit.hxx>
#include <comphelper/syntaxhighlight.hxx>
#include <svtools/svtdllapi.h> #include <svtools/svtdllapi.h>
#include <svtools/colorcfg.hxx> #include <svtools/colorcfg.hxx>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment