|
@@ -21,6 +21,13 @@ ColorParser::ColorParser( Text *zTxt )
|
|
// Destructor
|
|
// Destructor
|
|
ColorParser::~ColorParser()
|
|
ColorParser::~ColorParser()
|
|
{
|
|
{
|
|
|
|
+ for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
|
|
+ {
|
|
|
|
+ if( i.var.zFunktion )
|
|
|
|
+ i.var.zFunktion->release();
|
|
|
|
+ if( i.var.zKlasse )
|
|
|
|
+ i.var.zKlasse->release();
|
|
|
|
+ }
|
|
txt->release();
|
|
txt->release();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -29,30 +36,43 @@ void ColorParser::handleError( int begin, int ende )
|
|
{
|
|
{
|
|
if( errorIgnore )
|
|
if( errorIgnore )
|
|
return;
|
|
return;
|
|
- Error err;
|
|
|
|
|
|
+ TextAbschnitt err;
|
|
err.anfang = begin;
|
|
err.anfang = begin;
|
|
err.ende = ende;
|
|
err.ende = ende;
|
|
error.add( err );
|
|
error.add( err );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void ColorParser::handleKommentar( int beginn, int ende )
|
|
|
|
+{
|
|
|
|
+ TextAbschnitt kom;
|
|
|
|
+ kom.anfang = beginn;
|
|
|
|
+ kom.ende = ende;
|
|
|
|
+ kommentar.add( kom );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void ColorParser::handleString( int beginn, int ende )
|
|
|
|
+{
|
|
|
|
+ TextAbschnitt str;
|
|
|
|
+ str.anfang = beginn;
|
|
|
|
+ str.ende = ende;
|
|
|
|
+ string.add( str );
|
|
|
|
+}
|
|
|
|
+
|
|
// Setzt den Parsevorgang zum Beginn zurück
|
|
// Setzt den Parsevorgang zum Beginn zurück
|
|
void ColorParser::reset()
|
|
void ColorParser::reset()
|
|
{
|
|
{
|
|
- pos.pos = 0;
|
|
|
|
pos.inKeyword = 0;
|
|
pos.inKeyword = 0;
|
|
pos.inTypename = 0;
|
|
pos.inTypename = 0;
|
|
pos.inParameter = 0;
|
|
pos.inParameter = 0;
|
|
pos.inInstanzVar = 0;
|
|
pos.inInstanzVar = 0;
|
|
- pos.inString = 0;
|
|
|
|
- pos.inChar = 0;
|
|
|
|
- pos.lastLehr = 1;
|
|
|
|
- pos.lastTrenner = 1;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// Lädt das Script neu
|
|
// Lädt das Script neu
|
|
void ColorParser::reload()
|
|
void ColorParser::reload()
|
|
{
|
|
{
|
|
error.leeren();
|
|
error.leeren();
|
|
|
|
+ string.leeren();
|
|
|
|
+ kommentar.leeren();
|
|
for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
{
|
|
{
|
|
if( i.var.zFunktion )
|
|
if( i.var.zFunktion )
|
|
@@ -215,47 +235,55 @@ KSGSLeseFunktion *ColorParser::leseFunktion()
|
|
}
|
|
}
|
|
|
|
|
|
// Gibt den Farbtyp des nächsten Zeichens zurück
|
|
// Gibt den Farbtyp des nächsten Zeichens zurück
|
|
-KSGScriptEditor::ColorType ColorParser::getNextColor( int &underlineC )
|
|
|
|
|
|
+KSGScriptEditor::ColorType ColorParser::getNextColor( int p, int &underlineC )
|
|
{
|
|
{
|
|
KSGScriptEditor::ColorType color = KSGScriptEditor::ColorType::NORMAL_TEXT;
|
|
KSGScriptEditor::ColorType color = KSGScriptEditor::ColorType::NORMAL_TEXT;
|
|
int scriptL = txt->getLength();
|
|
int scriptL = txt->getLength();
|
|
- char c = txt->getText()[ pos.pos++ ];
|
|
|
|
- bool inString = pos.inChar || pos.inString;
|
|
|
|
- if( c == '\'' && txt->getText()[ pos.pos - 2 ] != '\\' )
|
|
|
|
- pos.inChar = !pos.inChar;
|
|
|
|
- if( c == '"' && txt->getText()[ pos.pos - 2 ] != '\\' )
|
|
|
|
- pos.inString = !pos.inString;
|
|
|
|
- if( istLehr( c ) || istTrenner( c ) )
|
|
|
|
|
|
+ char c = txt->getText()[ p ];
|
|
|
|
+ char cm1 = txt->getText()[ p - 1 ];
|
|
|
|
+ if( istLehr( cm1 ) || istTrenner( cm1 ) )
|
|
{
|
|
{
|
|
pos.inKeyword = 0;
|
|
pos.inKeyword = 0;
|
|
pos.inTypename = 0;
|
|
pos.inTypename = 0;
|
|
pos.inInstanzVar = 0;
|
|
pos.inInstanzVar = 0;
|
|
pos.inParameter = 0;
|
|
pos.inParameter = 0;
|
|
}
|
|
}
|
|
- else if( !pos.inChar && !pos.inString )
|
|
|
|
|
|
+ bool inString = 0;
|
|
|
|
+ bool inKommentar = 0;
|
|
|
|
+ for( auto i = string.getArray(); i.set; i++ )
|
|
|
|
+ {
|
|
|
|
+ if( i.var.anfang <= p && i.var.ende >= p )
|
|
|
|
+ inString = 1;
|
|
|
|
+ }
|
|
|
|
+ for( auto i = kommentar.getArray(); i.set; i++ )
|
|
|
|
+ {
|
|
|
|
+ if( i.var.anfang <= p && i.var.ende >= p )
|
|
|
|
+ inKommentar = 1;
|
|
|
|
+ }
|
|
|
|
+ if( !inString && !inKommentar )
|
|
{
|
|
{
|
|
- if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && pos.lastLehr )
|
|
|
|
|
|
+ if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && istLehr( cm1 ) )
|
|
{
|
|
{
|
|
for( int i = 0; i < keywordAnz; i++ )
|
|
for( int i = 0; i < keywordAnz; i++ )
|
|
{
|
|
{
|
|
int kl = textLength( keyword[ i ] );
|
|
int kl = textLength( keyword[ i ] );
|
|
pos.inKeyword = 1;
|
|
pos.inKeyword = 1;
|
|
- for( int j = 0; j < kl && j + pos.pos <= scriptL && pos.inKeyword; j++ )
|
|
|
|
- pos.inKeyword &= txt->getText()[ j + pos.pos - 1 ] == keyword[ i ][ j ];
|
|
|
|
- if( pos.inKeyword && ( kl - 1 + pos.pos == scriptL || istTrenner( txt->getText()[ kl - 1 + pos.pos ] ) ) )
|
|
|
|
|
|
+ for( int j = 0; j < kl && j + p < scriptL && pos.inKeyword; j++ )
|
|
|
|
+ pos.inKeyword &= txt->getText()[ j + p ] == keyword[ i ][ j ];
|
|
|
|
+ if( pos.inKeyword && ( kl + p == scriptL || istTrenner( txt->getText()[ kl + p ] ) ) )
|
|
break;
|
|
break;
|
|
pos.inKeyword = 0;
|
|
pos.inKeyword = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && pos.lastLehr )
|
|
|
|
|
|
+ if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && istLehr( cm1 ) )
|
|
{
|
|
{
|
|
for( int i = 0; i < typeAnz; i++ )
|
|
for( int i = 0; i < typeAnz; i++ )
|
|
{
|
|
{
|
|
int tl = textLength( type[ i ] );
|
|
int tl = textLength( type[ i ] );
|
|
pos.inTypename = 1;
|
|
pos.inTypename = 1;
|
|
- for( int j = 0; j < tl && j + pos.pos <= scriptL && pos.inTypename; j++ )
|
|
|
|
- pos.inTypename &= txt->getText()[ j + pos.pos - 1 ] == type[ i ][ j ];
|
|
|
|
- if( pos.inTypename && ( tl - 1 + pos.pos == scriptL || istTrenner( txt->getText()[ tl - 1 + pos.pos ] ) ) )
|
|
|
|
|
|
+ for( int j = 0; j < tl && j + p < scriptL && pos.inTypename; j++ )
|
|
|
|
+ pos.inTypename &= txt->getText()[ j + p ] == type[ i ][ j ];
|
|
|
|
+ if( pos.inTypename && ( tl + p == scriptL || istTrenner( txt->getText()[ tl + p ] ) ) )
|
|
break;
|
|
break;
|
|
pos.inTypename = 0;
|
|
pos.inTypename = 0;
|
|
}
|
|
}
|
|
@@ -266,19 +294,19 @@ KSGScriptEditor::ColorType ColorParser::getNextColor( int &underlineC )
|
|
{
|
|
{
|
|
int tl = dat->klassen.get( i )->name.getLength();
|
|
int tl = dat->klassen.get( i )->name.getLength();
|
|
pos.inTypename = 1;
|
|
pos.inTypename = 1;
|
|
- for( int j = 0; j < tl && j + pos.pos <= scriptL && pos.inTypename; j++ )
|
|
|
|
- pos.inTypename &= txt->getText()[ j + pos.pos - 1 ] == dat->klassen.get( i )->name.getText()[ j ];
|
|
|
|
- if( pos.inTypename && ( tl - 1 + pos.pos == scriptL || istTrenner( txt->getText()[ tl - 1 + pos.pos ] ) ) )
|
|
|
|
|
|
+ for( int j = 0; j < tl && j + p < scriptL && pos.inTypename; j++ )
|
|
|
|
+ pos.inTypename &= txt->getText()[ j + p ] == dat->klassen.get( i )->name.getText()[ j ];
|
|
|
|
+ if( pos.inTypename && ( tl + p == scriptL || istTrenner( txt->getText()[ tl + p ] ) ) )
|
|
break;
|
|
break;
|
|
pos.inTypename = 0;
|
|
pos.inTypename = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && pos.lastLehr )
|
|
|
|
|
|
+ if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && istLehr( cm1 ) )
|
|
{
|
|
{
|
|
for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
{
|
|
{
|
|
- if( i.var.anfang <= pos.pos - 1 && i.var.ende >= pos.pos - 1 )
|
|
|
|
|
|
+ if( i.var.anfang <= p && i.var.ende >= p )
|
|
{
|
|
{
|
|
if( i.var.zFunktion )
|
|
if( i.var.zFunktion )
|
|
{
|
|
{
|
|
@@ -287,9 +315,9 @@ KSGScriptEditor::ColorType ColorParser::getNextColor( int &underlineC )
|
|
{
|
|
{
|
|
int nl = i.var.zFunktion->parameter.get( j )->name.getLength();
|
|
int nl = i.var.zFunktion->parameter.get( j )->name.getLength();
|
|
pos.inParameter = 1;
|
|
pos.inParameter = 1;
|
|
- for( int k = 0; k < nl && k + pos.pos <= scriptL && pos.inParameter; k++ )
|
|
|
|
- pos.inParameter &= txt->getText()[ k + pos.pos - 1 ] == i.var.zFunktion->parameter.get( j )->name.getText()[ k ];
|
|
|
|
- if( pos.inParameter && ( nl - 1 + pos.pos == scriptL || istTrenner( txt->getText()[ nl - 1 + pos.pos ] ) ) )
|
|
|
|
|
|
+ for( int k = 0; k < nl && k + p < scriptL && pos.inParameter; k++ )
|
|
|
|
+ pos.inParameter &= txt->getText()[ k + p ] == i.var.zFunktion->parameter.get( j )->name.getText()[ k ];
|
|
|
|
+ if( pos.inParameter && ( nl + p == scriptL || istTrenner( txt->getText()[ nl + p ] ) ) )
|
|
break;
|
|
break;
|
|
pos.inParameter = 0;
|
|
pos.inParameter = 0;
|
|
}
|
|
}
|
|
@@ -297,11 +325,11 @@ KSGScriptEditor::ColorType ColorParser::getNextColor( int &underlineC )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && pos.lastLehr )
|
|
|
|
|
|
+ if( !pos.inInstanzVar && !pos.inParameter && !pos.inKeyword && !pos.inTypename && istLehr( cm1 ) )
|
|
{
|
|
{
|
|
for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
for( auto i = abschnitt.getArray(); i.set; i++ )
|
|
{
|
|
{
|
|
- if( i.var.anfang <= pos.pos - 1 && i.var.ende >= pos.pos - 1 )
|
|
|
|
|
|
+ if( i.var.anfang <= p && i.var.ende >= p )
|
|
{
|
|
{
|
|
if( i.var.zKlasse )
|
|
if( i.var.zKlasse )
|
|
{
|
|
{
|
|
@@ -310,9 +338,9 @@ KSGScriptEditor::ColorType ColorParser::getNextColor( int &underlineC )
|
|
{
|
|
{
|
|
int nl = i.var.zKlasse->variablen.get( j )->name.getLength();
|
|
int nl = i.var.zKlasse->variablen.get( j )->name.getLength();
|
|
pos.inInstanzVar = 1;
|
|
pos.inInstanzVar = 1;
|
|
- for( int k = 0; k < nl && k + pos.pos <= scriptL && pos.inInstanzVar; k++ )
|
|
|
|
- pos.inInstanzVar &= txt->getText()[ k + pos.pos - 1 ] == i.var.zKlasse->variablen.get( j )->name.getText()[ k ];
|
|
|
|
- if( pos.inInstanzVar && ( nl - 1 + pos.pos == scriptL || istTrenner( txt->getText()[ nl - 1 + pos.pos ] ) ) )
|
|
|
|
|
|
+ for( int k = 0; k < nl && k + p < scriptL && pos.inInstanzVar; k++ )
|
|
|
|
+ pos.inInstanzVar &= txt->getText()[ k + p ] == i.var.zKlasse->variablen.get( j )->name.getText()[ k ];
|
|
|
|
+ if( pos.inInstanzVar && ( nl + p == scriptL || istTrenner( txt->getText()[ nl + p ] ) ) )
|
|
break;
|
|
break;
|
|
pos.inInstanzVar = 0;
|
|
pos.inInstanzVar = 0;
|
|
}
|
|
}
|
|
@@ -329,15 +357,15 @@ KSGScriptEditor::ColorType ColorParser::getNextColor( int &underlineC )
|
|
color = KSGScriptEditor::ColorType::PARAMETER_VARIABLE;
|
|
color = KSGScriptEditor::ColorType::PARAMETER_VARIABLE;
|
|
if( pos.inInstanzVar )
|
|
if( pos.inInstanzVar )
|
|
color = KSGScriptEditor::ColorType::INSTANCE_VARIABLE;
|
|
color = KSGScriptEditor::ColorType::INSTANCE_VARIABLE;
|
|
- if( pos.inChar || pos.inString || inString )
|
|
|
|
|
|
+ if( inString )
|
|
color = KSGScriptEditor::ColorType::STRING;
|
|
color = KSGScriptEditor::ColorType::STRING;
|
|
|
|
+ if( inKommentar )
|
|
|
|
+ color = KSGScriptEditor::ColorType::KOMMENTAR;
|
|
for( auto i = error.getArray(); i.set; i++ )
|
|
for( auto i = error.getArray(); i.set; i++ )
|
|
{
|
|
{
|
|
- if( i.var.anfang <= pos.pos && i.var.ende >= pos.pos )
|
|
|
|
|
|
+ if( i.var.anfang <= p && i.var.ende >= p )
|
|
underlineC = KSGScriptEditor::ColorType::ERROR_UNDERLINE;
|
|
underlineC = KSGScriptEditor::ColorType::ERROR_UNDERLINE;
|
|
}
|
|
}
|
|
- pos.lastLehr = istLehr( c );
|
|
|
|
- pos.lastTrenner = istTrenner( c );
|
|
|
|
return color;
|
|
return color;
|
|
}
|
|
}
|
|
|
|
|