convert TokenTypes to scoped enum

Change-Id: I17c0a616dd6cf48a22896b6cd6b0df157d1f9a9f
This commit is contained in:
Noel Grandin
2016-02-24 10:11:43 +02:00
parent 2f9d53df89
commit a5e53f9ffd
10 changed files with 111 additions and 105 deletions

View File

@@ -1512,9 +1512,9 @@ ModulWindowLayout::SyntaxColors::SyntaxColors () :
{ {
aConfig.AddListener(this); aConfig.AddListener(this);
aColors[TT_UNKNOWN] = aColors[TokenType::Unknown] =
aColors[TT_WHITESPACE] = aColors[TokenType::Whitespace] =
aColors[TT_EOL] = aColors[TokenType::EOL] =
Application::GetSettings().GetStyleSettings().GetFieldTextColor(); Application::GetSettings().GetStyleSettings().GetFieldTextColor();
NewConfig(true); NewConfig(true);
@@ -1528,11 +1528,11 @@ ModulWindowLayout::SyntaxColors::~SyntaxColors ()
void ModulWindowLayout::SyntaxColors::SettingsChanged () void ModulWindowLayout::SyntaxColors::SettingsChanged ()
{ {
Color const aColor = Application::GetSettings().GetStyleSettings().GetFieldTextColor(); Color const aColor = Application::GetSettings().GetStyleSettings().GetFieldTextColor();
if (aColor != aColors[TT_UNKNOWN]) if (aColor != aColors[TokenType::Unknown])
{ {
aColors[TT_UNKNOWN] = aColors[TokenType::Unknown] =
aColors[TT_WHITESPACE] = aColors[TokenType::Whitespace] =
aColors[TT_EOL] = aColors[TokenType::EOL] =
aColor; aColor;
if (pEditor) if (pEditor)
pEditor->UpdateSyntaxHighlighting(); pEditor->UpdateSyntaxHighlighting();
@@ -1550,18 +1550,18 @@ void ModulWindowLayout::SyntaxColors::NewConfig (bool bFirst)
{ {
static struct static struct
{ {
TokenTypes eTokenType; TokenType eTokenType;
svtools::ColorConfigEntry eEntry; svtools::ColorConfigEntry eEntry;
} }
const vIds[] = const vIds[] =
{ {
{ TT_IDENTIFIER, svtools::BASICIDENTIFIER }, { TokenType::Identifier, svtools::BASICIDENTIFIER },
{ TT_NUMBER, svtools::BASICNUMBER }, { TokenType::Number, svtools::BASICNUMBER },
{ TT_STRING, svtools::BASICSTRING }, { TokenType::String, svtools::BASICSTRING },
{ TT_COMMENT, svtools::BASICCOMMENT }, { TokenType::Comment, svtools::BASICCOMMENT },
{ TT_ERROR, svtools::BASICERROR }, { TokenType::Error, svtools::BASICERROR },
{ TT_OPERATOR, svtools::BASICOPERATOR }, { TokenType::Operator, svtools::BASICOPERATOR },
{ TT_KEYWORDS, svtools::BASICKEYWORD }, { TokenType::Keywords, svtools::BASICKEYWORD },
}; };
bool bChanged = false; bool bChanged = false;

View File

@@ -38,6 +38,7 @@ class SvxSearchItem;
#include <vcl/idle.hxx> #include <vcl/idle.hxx>
#include <sfx2/progress.hxx> #include <sfx2/progress.hxx>
#include <o3tl/enumarray.hxx>
#include <set> #include <set>
@@ -428,7 +429,7 @@ public:
public: public:
void BasicAddWatch (OUString const&); void BasicAddWatch (OUString const&);
void BasicRemoveWatch (); void BasicRemoveWatch ();
Color GetSyntaxColor (TokenTypes eType) const { return aSyntaxColors.GetColor(eType); } Color GetSyntaxColor (TokenType eType) const { return aSyntaxColors.GetColor(eType); }
protected: protected:
// Window: // Window:
@@ -456,15 +457,15 @@ private:
void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; } void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; }
void SettingsChanged (); void SettingsChanged ();
public: public:
Color GetColor (TokenTypes eType) const { return aColors[eType]; } Color GetColor (TokenType eType) const { return aColors[eType]; }
private: private:
virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, sal_uInt32) override; virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, sal_uInt32) override;
void NewConfig (bool bFirst); void NewConfig (bool bFirst);
private: private:
// the color values (the indexes are TokenTypes, see comphelper/syntaxhighlight.hxx) // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
Color aColors[TT_KEYWORDS + 1]; o3tl::enumarray<TokenType, Color> aColors;
// the configuration // the configuration
svtools::ColorConfig aConfig; svtools::ColorConfig aConfig;
// the active editor // the active editor

View File

@@ -622,7 +622,7 @@ void EditorWindow::HandleAutoCorrect()
OUString sStr = aLine.copy( r.nBegin, r.nEnd - r.nBegin ); OUString sStr = aLine.copy( r.nBegin, r.nEnd - r.nBegin );
//if WS or empty string: stop, nothing to do //if WS or empty string: stop, nothing to do
if( ( r.tokenType == TT_WHITESPACE ) || sStr.isEmpty() ) if( ( r.tokenType == TokenType::Whitespace ) || sStr.isEmpty() )
return; return;
//create the appropriate TextSelection, and update the cache //create the appropriate TextSelection, and update the cache
TextPaM aStart( nLine, r.nBegin ); TextPaM aStart( nLine, r.nBegin );
@@ -631,7 +631,7 @@ void EditorWindow::HandleAutoCorrect()
rModulWindow.UpdateModule(); rModulWindow.UpdateModule();
rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse( aCodeCompleteCache ); rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse( aCodeCompleteCache );
// correct the last entered keyword // correct the last entered keyword
if( r.tokenType == TT_KEYWORDS ) if( r.tokenType == TokenType::Keywords )
{ {
sStr = sStr.toAsciiLowerCase(); sStr = sStr.toAsciiLowerCase();
if( !SbModule::GetKeywordCase(sStr).isEmpty() ) if( !SbModule::GetKeywordCase(sStr).isEmpty() )
@@ -644,7 +644,7 @@ void EditorWindow::HandleAutoCorrect()
pEditEngine->ReplaceText( sTextSelection, sStr ); pEditEngine->ReplaceText( sTextSelection, sStr );
pEditView->SetSelection( aSel ); pEditView->SetSelection( aSel );
} }
if( r.tokenType == TT_IDENTIFIER ) if( r.tokenType == TokenType::Identifier )
{// correct variables {// correct variables
if( !aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName ).isEmpty() ) if( !aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName ).isEmpty() )
{ {
@@ -729,7 +729,7 @@ void EditorWindow::HandleAutoCloseDoubleQuotes()
if( aPortions.empty() ) if( aPortions.empty() )
return; return;
if( aLine.getLength() > 0 && !aLine.endsWith("\"") && (aPortions.back().tokenType != TT_STRING) ) if( aLine.getLength() > 0 && !aLine.endsWith("\"") && (aPortions.back().tokenType != TokenType::String) )
{ {
GetEditView()->InsertText("\""); GetEditView()->InsertText("\"");
//leave the cursor on its place: inside the two double quotes //leave the cursor on its place: inside the two double quotes
@@ -776,7 +776,7 @@ void EditorWindow::HandleProcedureCompletion()
HighlightPortion& r = aCurrPortions.front(); HighlightPortion& r = aCurrPortions.front();
OUString sStr = aCurrLine.copy(r.nBegin, r.nEnd - r.nBegin); OUString sStr = aCurrLine.copy(r.nBegin, r.nEnd - r.nBegin);
if( r.tokenType == 9 ) if( r.tokenType == TokenType::Keywords )
{ {
if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") ) if( sStr.equalsIgnoreAsciiCase("sub") || sStr.equalsIgnoreAsciiCase("function") )
{ {
@@ -808,13 +808,13 @@ bool EditorWindow::GetProcedureName(OUString& rLine, OUString& rProcType, OUStri
{ {
OUString sTokStr = rLine.copy(i->nBegin, i->nEnd - i->nBegin); OUString sTokStr = rLine.copy(i->nBegin, i->nEnd - i->nBegin);
if( i->tokenType == 9 && ( sTokStr.equalsIgnoreAsciiCase("sub") if( i->tokenType == TokenType::Keywords && ( sTokStr.equalsIgnoreAsciiCase("sub")
|| sTokStr.equalsIgnoreAsciiCase("function")) ) || sTokStr.equalsIgnoreAsciiCase("function")) )
{ {
rProcType = sTokStr; rProcType = sTokStr;
bFoundType = true; bFoundType = true;
} }
if( i->tokenType == 1 && bFoundType ) if( i->tokenType == TokenType::Identifier && bFoundType )
{ {
rProcName = sTokStr; rProcName = sTokStr;
bFoundName = true; bFoundName = true;
@@ -847,9 +847,9 @@ void EditorWindow::HandleCodeCompletion()
aPortions.rbegin()); aPortions.rbegin());
i != aPortions.rend(); ++i) i != aPortions.rend(); ++i)
{ {
if( i->tokenType == TT_WHITESPACE ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line if( i->tokenType == TokenType::Whitespace ) // a whitespace: stop; if there is no ws, it goes to the beginning of the line
break; break;
if( i->tokenType == TT_IDENTIFIER || i->tokenType == TT_KEYWORDS ) // extract the identifiers(methods, base variable) if( i->tokenType == TokenType::Identifier || i->tokenType == TokenType::Keywords ) // extract the identifiers(methods, base variable)
/* an example: Dim aLocVar2 as com.sun.star.beans.PropertyValue /* an example: Dim aLocVar2 as com.sun.star.beans.PropertyValue
* here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!) * here, aLocVar2.Name, and PropertyValue's Name field is treated as a keyword(?!)
* */ * */

View File

@@ -37,6 +37,11 @@ public:
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
std::ostream& operator<<(std::ostream& rStrm, const TokenType& tt)
{
return rStrm << (int)tt;
}
void SyntaxHighlightTest::testBasicString() { void SyntaxHighlightTest::testBasicString() {
OUString s("\"foo\""); OUString s("\"foo\"");
std::vector<HighlightPortion> ps; std::vector<HighlightPortion> ps;
@@ -45,7 +50,7 @@ void SyntaxHighlightTest::testBasicString() {
static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_STRING, ps[0].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::String, ps[0].tokenType);
} }
void SyntaxHighlightTest::testBasicComment() { void SyntaxHighlightTest::testBasicComment() {
@@ -56,7 +61,7 @@ void SyntaxHighlightTest::testBasicComment() {
static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
} }
void SyntaxHighlightTest::testBasicCommentNewline() { void SyntaxHighlightTest::testBasicCommentNewline() {
@@ -67,10 +72,10 @@ void SyntaxHighlightTest::testBasicCommentNewline() {
static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[0].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[1].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(5), ps[1].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ps[1].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(6), ps[1].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_EOL, ps[1].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::EOL, ps[1].tokenType);
} }
void SyntaxHighlightTest::testBasicEmptyComment() { void SyntaxHighlightTest::testBasicEmptyComment() {
@@ -81,7 +86,7 @@ void SyntaxHighlightTest::testBasicEmptyComment() {
static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size()); static_cast<std::vector<HighlightPortion>::size_type>(1), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
} }
void SyntaxHighlightTest::testBasicEmptyCommentNewline() { void SyntaxHighlightTest::testBasicEmptyCommentNewline() {
@@ -92,10 +97,10 @@ void SyntaxHighlightTest::testBasicEmptyCommentNewline() {
static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size()); static_cast<std::vector<HighlightPortion>::size_type>(2), ps.size());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ps[0].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[0].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_COMMENT, ps[0].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::Comment, ps[0].tokenType);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[1].nBegin); CPPUNIT_ASSERT_EQUAL(sal_Int32(1), ps[1].nBegin);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), ps[1].nEnd); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), ps[1].nEnd);
CPPUNIT_ASSERT_EQUAL(TT_EOL, ps[1].tokenType); CPPUNIT_ASSERT_EQUAL(TokenType::EOL, ps[1].tokenType);
} }
void SyntaxHighlightTest::testBasic() void SyntaxHighlightTest::testBasic()

View File

@@ -265,7 +265,7 @@ class SyntaxHighlighter::Tokenizer
bool testCharFlags(sal_Unicode c, sal_uInt16 nTestFlags) const; bool testCharFlags(sal_Unicode c, sal_uInt16 nTestFlags) const;
// Get new token, EmptyString == nothing more over there // Get new token, EmptyString == nothing more over there
bool getNextToken(const sal_Unicode*& pos, /*out*/TokenTypes& reType, bool getNextToken(const sal_Unicode*& pos, /*out*/TokenType& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos) const; /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos) const;
const char** ppListKeyWords; const char** ppListKeyWords;
@@ -304,10 +304,10 @@ void SyntaxHighlighter::Tokenizer::setKeyWords( const char** ppKeyWords, sal_uIn
nKeyWordCount = nCount; nKeyWordCount = nCount;
} }
bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/TokenTypes& reType, bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/TokenType& reType,
/*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos) const /*out*/const sal_Unicode*& rpStartPos, /*out*/const sal_Unicode*& rpEndPos) const
{ {
reType = TT_UNKNOWN; reType = TokenType::Unknown;
rpStartPos = pos; rpStartPos = pos;
@@ -324,7 +324,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
while( testCharFlags( *pos, CHAR_SPACE ) ) while( testCharFlags( *pos, CHAR_SPACE ) )
++pos; ++pos;
reType = TT_WHITESPACE; reType = TokenType::Whitespace;
} }
// Identifier? // Identifier?
@@ -341,7 +341,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
} }
while( bIdentifierChar ); while( bIdentifierChar );
reType = TT_IDENTIFIER; reType = TokenType::Identifier;
// Keyword table // Keyword table
if (ppListKeyWords != nullptr) if (ppListKeyWords != nullptr)
@@ -367,7 +367,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
if ( bsearch( aByteStr.getStr(), ppListKeyWords, nKeyWordCount, sizeof( char* ), if ( bsearch( aByteStr.getStr(), ppListKeyWords, nKeyWordCount, sizeof( char* ),
compare_strings ) ) compare_strings ) )
{ {
reType = TT_KEYWORDS; reType = TokenType::Keywords;
if( aByteStr == "rem" ) if( aByteStr == "rem" )
{ {
@@ -378,7 +378,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
cPeek = *++pos; cPeek = *++pos;
} }
reType = TT_COMMENT; reType = TokenType::Comment;
} }
} }
} }
@@ -405,7 +405,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
} }
while( bIdentifierChar ); while( bIdentifierChar );
} }
reType = TT_PARAMETER; reType = TokenType::Parameter;
} }
else if (c=='-') else if (c=='-')
{ {
@@ -418,7 +418,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
++pos; ++pos;
cPeekNext = *pos; cPeekNext = *pos;
} }
reType = TT_COMMENT; reType = TokenType::Comment;
} }
} }
else if (c=='/') else if (c=='/')
@@ -432,7 +432,7 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
++pos; ++pos;
cPeekNext = *pos; cPeekNext = *pos;
} }
reType = TT_COMMENT; reType = TokenType::Comment;
} }
} }
else else
@@ -449,14 +449,14 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
++pos; ++pos;
} }
reType = TT_COMMENT; reType = TokenType::Comment;
} }
// The real operator; can be easily used since not the actual // The real operator; can be easily used since not the actual
// operator (e.g. +=) is concerned, but the fact that it is one // operator (e.g. +=) is concerned, but the fact that it is one
if( reType != TT_COMMENT ) if( reType != TokenType::Comment )
{ {
reType = TT_OPERATOR; reType = TokenType::Operator;
} }
} }
@@ -465,13 +465,13 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
// Object separator? Must be handled before Number // Object separator? Must be handled before Number
else if( c == '.' && ( *pos < '0' || *pos > '9' ) ) else if( c == '.' && ( *pos < '0' || *pos > '9' ) )
{ {
reType = TT_OPERATOR; reType = TokenType::Operator;
} }
// Number? // Number?
else if( testCharFlags( c, CHAR_START_NUMBER ) ) else if( testCharFlags( c, CHAR_START_NUMBER ) )
{ {
reType = TT_NUMBER; reType = TokenType::Number;
// Number system, 10 = normal, it is changed for Oct/Hex // Number system, 10 = normal, it is changed for Oct/Hex
int nRadix = 10; int nRadix = 10;
@@ -503,12 +503,12 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
} }
else else
{ {
reType = TT_OPERATOR; reType = TokenType::Operator;
} }
} }
// When it is not Oct or Hex, then it is double // When it is not Oct or Hex, then it is double
if( reType == TT_NUMBER && nRadix == 10 ) if( reType == TokenType::Number && nRadix == 10 )
{ {
// Flag if the last character is an exponent // Flag if the last character is an exponent
bool bAfterExpChar = false; bool bAfterExpChar = false;
@@ -540,25 +540,25 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
if( *pos == 0 ) if( *pos == 0 )
{ {
// ERROR: unterminated string literal // ERROR: unterminated string literal
reType = TT_ERROR; reType = TokenType::Error;
break; break;
} }
c = *pos++; c = *pos++;
if( testCharFlags( c, CHAR_EOL ) ) if( testCharFlags( c, CHAR_EOL ) )
{ {
// ERROR: unterminated string literal // ERROR: unterminated string literal
reType = TT_ERROR; reType = TokenType::Error;
break; break;
} }
} }
if( reType != TT_ERROR ) if( reType != TokenType::Error )
{ {
++pos; ++pos;
if( cEndString == ']' ) if( cEndString == ']' )
reType = TT_IDENTIFIER; reType = TokenType::Identifier;
else else
reType = TT_STRING; reType = TokenType::String;
} }
} }
@@ -570,10 +570,10 @@ bool SyntaxHighlighter::Tokenizer::getNextToken(const sal_Unicode*& pos, /*out*/
if( cNext != c && testCharFlags( cNext, CHAR_EOL ) ) if( cNext != c && testCharFlags( cNext, CHAR_EOL ) )
++pos; ++pos;
reType = TT_EOL; reType = TokenType::EOL;
} }
// All other will remain TT_UNKNOWN // All other will remain TokenType::Unknown
// Save end position // Save end position
rpEndPos = pos; rpEndPos = pos;
@@ -672,7 +672,7 @@ void SyntaxHighlighter::Tokenizer::getHighlightPortions(const OUString& rLine,
const sal_Unicode* pos = rLine.getStr(); const sal_Unicode* pos = rLine.getStr();
// Variables for the out parameter // Variables for the out parameter
TokenTypes eType; TokenType eType;
const sal_Unicode* pStartPos; const sal_Unicode* pStartPos;
const sal_Unicode* pEndPos; const sal_Unicode* pEndPos;

View File

@@ -33,7 +33,7 @@ class L10N_DLLPUBLIC BasicCodeTagger
SyntaxHighlighter m_Highlighter; SyntaxHighlighter m_Highlighter;
bool m_bTaggingCompleted; bool m_bTaggingCompleted;
void tagParagraph( xmlNodePtr paragraph ); void tagParagraph( xmlNodePtr paragraph );
static xmlChar* getTypeString( TokenTypes tokenType ); static xmlChar* getTypeString( TokenType tokenType );
void getBasicCodeContainerNodes(); void getBasicCodeContainerNodes();
void tagBasCodeParagraphs(); void tagBasCodeParagraphs();

View File

@@ -150,7 +150,7 @@ void BasicCodeTagger::tagParagraph( xmlNodePtr paragraph )
{ {
OString sToken(OUStringToOString(strLine.copy(i->nBegin, i->nEnd-i->nBegin), RTL_TEXTENCODING_UTF8)); OString sToken(OUStringToOString(strLine.copy(i->nBegin, i->nEnd-i->nBegin), RTL_TEXTENCODING_UTF8));
xmlNodePtr text = xmlNewText(reinterpret_cast<const xmlChar*>(sToken.getStr())); xmlNodePtr text = xmlNewText(reinterpret_cast<const xmlChar*>(sToken.getStr()));
if ( i->tokenType != TT_WHITESPACE ) if ( i->tokenType != TokenType::Whitespace )
{ {
xmlChar* typeStr = getTypeString( i->tokenType ); xmlChar* typeStr = getTypeString( i->tokenType );
curNode = xmlNewTextChild( paragraph, nullptr, reinterpret_cast<xmlChar const *>("item"), nullptr ); curNode = xmlNewTextChild( paragraph, nullptr, reinterpret_cast<xmlChar const *>("item"), nullptr );
@@ -188,42 +188,42 @@ void BasicCodeTagger::tagBasicCodes()
} }
//! Converts SyntaxHighlighter's TokenTypes enum to a type string for <item type=... > //! Converts SyntaxHighlighter's TokenTypes enum to a type string for <item type=... >
xmlChar* BasicCodeTagger::getTypeString( TokenTypes tokenType ) xmlChar* BasicCodeTagger::getTypeString( TokenType tokenType )
{ {
const char* str; const char* str;
switch ( tokenType ) switch ( tokenType )
{ {
case TT_UNKNOWN : case TokenType::Unknown :
str = "unknown"; str = "unknown";
break; break;
case TT_IDENTIFIER : case TokenType::Identifier :
str = "identifier"; str = "identifier";
break; break;
case TT_WHITESPACE : case TokenType::Whitespace :
str = "whitespace"; str = "whitespace";
break; break;
case TT_NUMBER : case TokenType::Number :
str = "number"; str = "number";
break; break;
case TT_STRING : case TokenType::String :
str = "string"; str = "string";
break; break;
case TT_EOL : case TokenType::EOL :
str = "eol"; str = "eol";
break; break;
case TT_COMMENT : case TokenType::Comment :
str = "comment"; str = "comment";
break; break;
case TT_ERROR : case TokenType::Error :
str = "error"; str = "error";
break; break;
case TT_OPERATOR : case TokenType::Operator :
str = "operator"; str = "operator";
break; break;
case TT_KEYWORDS : case TokenType::Keywords :
str = "keyword"; str = "keyword";
break; break;
case TT_PARAMETER : case TokenType::Parameter :
str = "parameter"; str = "parameter";
break; break;
default : default :

View File

@@ -30,29 +30,29 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
// Token-Typen TT_... enum class TokenType
enum TokenTypes
{ {
TT_UNKNOWN, Unknown,
TT_IDENTIFIER, Identifier,
TT_WHITESPACE, Whitespace,
TT_NUMBER, Number,
TT_STRING, String,
TT_EOL, EOL,
TT_COMMENT, Comment,
TT_ERROR, Error,
TT_OPERATOR, Operator,
TT_KEYWORDS, Keywords,
TT_PARAMETER Parameter,
LAST = Parameter
}; };
struct HighlightPortion { struct HighlightPortion {
sal_Int32 nBegin; sal_Int32 nBegin;
sal_Int32 nEnd; sal_Int32 nEnd;
TokenTypes tokenType; TokenType tokenType;
HighlightPortion( HighlightPortion(
sal_Int32 theBegin, sal_Int32 theEnd, TokenTypes theTokenType): sal_Int32 theBegin, sal_Int32 theEnd, TokenType theTokenType):
nBegin(theBegin), nEnd(theEnd), tokenType(theTokenType) nBegin(theBegin), nEnd(theEnd), tokenType(theTokenType)
{} {}
}; };

View File

@@ -46,7 +46,7 @@ class SVT_DLLPUBLIC MultiLineEditSyntaxHighlight : public MultiLineEdit
virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override virtual void SetText( const OUString& rStr, const Selection& rNewSelection ) override
{ SetText( rStr ); SetSelection( rNewSelection ); } { SetText( rStr ); SetSelection( rNewSelection ); }
Color GetColorValue(TokenTypes aToken); Color GetColorValue(TokenType aToken);
}; };
#endif #endif

View File

@@ -115,7 +115,7 @@ bool MultiLineEditSyntaxHighlight::PreNotify( NotifyEvent& rNEvt )
return MultiLineEdit::PreNotify(rNEvt); return MultiLineEdit::PreNotify(rNEvt);
} }
Color MultiLineEditSyntaxHighlight::GetColorValue(TokenTypes aToken) Color MultiLineEditSyntaxHighlight::GetColorValue(TokenType aToken)
{ {
Color aColor; Color aColor;
switch (aHighlighter.GetLanguage()) switch (aHighlighter.GetLanguage())
@@ -124,13 +124,13 @@ Color MultiLineEditSyntaxHighlight::GetColorValue(TokenTypes aToken)
{ {
switch (aToken) switch (aToken)
{ {
case TT_IDENTIFIER: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLIDENTIFIER).nColor; break; case TokenType::Identifier: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLIDENTIFIER).nColor; break;
case TT_NUMBER: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLNUMBER).nColor; break; case TokenType::Number: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLNUMBER).nColor; break;
case TT_STRING: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLSTRING).nColor; break; case TokenType::String: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLSTRING).nColor; break;
case TT_OPERATOR: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLOPERATOR).nColor; break; case TokenType::Operator: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLOPERATOR).nColor; break;
case TT_KEYWORDS: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLKEYWORD).nColor; break; case TokenType::Keywords: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLKEYWORD).nColor; break;
case TT_PARAMETER: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLPARAMETER).nColor; break; case TokenType::Parameter: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLPARAMETER).nColor; break;
case TT_COMMENT: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLCOMMENT).nColor; break; case TokenType::Comment: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLCOMMENT).nColor; break;
default: aColor = Color(0,0,0); default: aColor = Color(0,0,0);
} }
break; break;
@@ -139,13 +139,13 @@ Color MultiLineEditSyntaxHighlight::GetColorValue(TokenTypes aToken)
{ {
switch (aToken) switch (aToken)
{ {
case TT_IDENTIFIER: aColor = Color(255,0,0); break; case TokenType::Identifier: aColor = Color(255,0,0); break;
case TT_COMMENT: aColor = Color(0,0,45); break; case TokenType::Comment: aColor = Color(0,0,45); break;
case TT_NUMBER: aColor = Color(204,102,204); break; case TokenType::Number: aColor = Color(204,102,204); break;
case TT_STRING: aColor = Color(0,255,45); break; case TokenType::String: aColor = Color(0,255,45); break;
case TT_OPERATOR: aColor = Color(0,0,100); break; case TokenType::Operator: aColor = Color(0,0,100); break;
case TT_KEYWORDS: aColor = Color(0,0,255); break; case TokenType::Keywords: aColor = Color(0,0,255); break;
case TT_ERROR : aColor = Color(0,255,255); break; case TokenType::Error : aColor = Color(0,255,255); break;
default: aColor = Color(0,0,0); default: aColor = Color(0,0,0);
} }
break; break;