@@ -125,8 +125,9 @@ constexpr bool IsIdentifierStyle(int style) noexcept {
125
125
|| style == SCE_RB_BUILTIN_FUNCTION;
126
126
}
127
127
128
- int ClassifyWordRb (Sci_PositionU start, Sci_PositionU end, char ch, char chNext, LexerWordList keywordLists, LexAccessor &styler, char *prevWord) {
128
+ int ClassifyWordRb (Sci_PositionU end, char ch, char chNext, LexerWordList keywordLists, LexAccessor &styler, char *prevWord) {
129
129
char s[MAX_KEYWORD_LENGTH + 1 ];
130
+ const Sci_PositionU start = styler.GetStartSegment ();
130
131
styler.GetRange (start, end, s, sizeof (s));
131
132
int chAttr = SCE_RB_IDENTIFIER;
132
133
int style = SCE_RB_DEFAULT;
@@ -622,7 +623,7 @@ bool sureThisIsNotHeredoc(Sci_Position lt2StartPos, LexAccessor &styler) {
622
623
// move to the start of the first line that is not in a
623
624
// multi-line construct
624
625
625
- void synchronizeDocStart (Sci_PositionU & startPos, Sci_Position &length, int &initStyle, LexAccessor &styler, bool skipWhiteSpace = false ) {
626
+ void synchronizeDocStart (Sci_PositionU &startPos, Sci_Position &length, int &initStyle, LexAccessor &styler, bool skipWhiteSpace = false ) {
626
627
#if 0
627
628
styler.Flush();
628
629
const int style = styler.StyleAt(startPos);
@@ -794,8 +795,7 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
794
795
// Begin of here-doc (the line after the here-doc delimiter):
795
796
HereDoc.State = 2 ;
796
797
if (state == SCE_RB_WORD) {
797
- const Sci_Position wordStartPos = styler.GetStartSegment ();
798
- ClassifyWordRb (wordStartPos, i, ch, chNext, keywordLists, styler, prevWord);
798
+ ClassifyWordRb (i, ch, chNext, keywordLists, styler, prevWord);
799
799
} else {
800
800
styler.ColorTo (i, state);
801
801
}
@@ -1158,8 +1158,7 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
1158
1158
// No need to handle this state -- we'll just move to the end
1159
1159
preferRE = false ;
1160
1160
} else {
1161
- const Sci_Position wordStartPos = styler.GetStartSegment ();
1162
- const int word_style = ClassifyWordRb (wordStartPos, i, ch, chNext, keywordLists, styler, prevWord);
1161
+ const int word_style = ClassifyWordRb (i, ch, chNext, keywordLists, styler, prevWord);
1163
1162
preferRE = false ;
1164
1163
switch (word_style) {
1165
1164
case SCE_RB_WORD:
@@ -1494,7 +1493,7 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
1494
1493
if (state == SCE_RB_WORD) {
1495
1494
// We've ended on a word, possibly at EOF, and need to
1496
1495
// classify it.
1497
- ClassifyWordRb (styler. GetStartSegment (), lengthDoc, ' \0 ' , ' \0 ' , keywordLists, styler, prevWord);
1496
+ ClassifyWordRb (lengthDoc, ' \0 ' , ' \0 ' , keywordLists, styler, prevWord);
1498
1497
} else {
1499
1498
styler.ColorTo (lengthDoc, state);
1500
1499
}
@@ -1503,24 +1502,6 @@ void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
1503
1502
// Helper functions for folding, disambiguation keywords
1504
1503
// Assert that there are no high-bit chars
1505
1504
1506
- void getPrevWord (Sci_Position pos, char *prevWord, LexAccessor &styler, int word_state) {
1507
- Sci_Position i;
1508
- styler.Flush ();
1509
- for (i = pos - 1 ; i > 0 ; i--) {
1510
- if (styler.StyleAt (i) != word_state) {
1511
- i++;
1512
- break ;
1513
- }
1514
- }
1515
- if (i < pos - MAX_KEYWORD_LENGTH) // overflow
1516
- i = pos - MAX_KEYWORD_LENGTH;
1517
- char *dst = prevWord;
1518
- for (; i <= pos; i++) {
1519
- *dst++ = styler[i];
1520
- }
1521
- *dst = 0 ;
1522
- }
1523
-
1524
1505
bool keywordIsAmbiguous (const char *prevWord) noexcept {
1525
1506
// Order from most likely used to least likely
1526
1507
// Lots of ways to do a loop in Ruby besides 'while/until'
@@ -1608,9 +1589,9 @@ bool keywordIsModifier(const char *word, Sci_Position pos, LexAccessor &styler)
1608
1589
// XXX: Make a list of other keywords where 'if' isn't a modifier
1609
1590
// and can appear legitimately
1610
1591
// Formulate this to avoid warnings from most compilers
1611
- if (StrEqual (word, " if" )) {
1592
+ if (StrEqual (word, " if" ) && pos - 3 >= lineStartPosn ) {
1612
1593
char prevWord[MAX_KEYWORD_LENGTH + 1 ];
1613
- getPrevWord (pos, prevWord, styler, SCE_RB_WORD );
1594
+ styler. GetRange (pos - 3 , pos + 1 , prevWord, sizeof (prevWord) );
1614
1595
return !StrEqual (prevWord, " else" );
1615
1596
}
1616
1597
return true ;
@@ -1756,6 +1737,8 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer
1756
1737
};
1757
1738
MethodDefinition method_definition = MethodDefinition::None;
1758
1739
int argument_paren_count = 0 ;
1740
+ char word[MAX_KEYWORD_LENGTH + 1 ];
1741
+ int wordLen = 0 ;
1759
1742
bool heredocOpen = false ;
1760
1743
1761
1744
while (startPos < endPos) {
@@ -1778,18 +1761,21 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer
1778
1761
} else if (ch == ' )' || ch == ' }' || ch == ' ]' ) {
1779
1762
levelCurrent--;
1780
1763
}
1781
- } else if (style == SCE_RB_WORD && styleNext != SCE_RB_WORD) {
1782
- // Look at the keyword on the left and decide what to do
1783
- char prevWord[MAX_KEYWORD_LENGTH + 1 ]; // 1 byte for zero
1784
- prevWord[0 ] = 0 ;
1785
- getPrevWord (startPos - 1 , prevWord, styler, SCE_RB_WORD);
1786
- if (StrEqual (prevWord, " end" )) {
1787
- levelCurrent--;
1788
- } else if (StrEqual (prevWord, " def" )) {
1789
- levelCurrent++;
1790
- method_definition = MethodDefinition::Define;
1791
- } else if (keywordLists[KeywordIndex_CodeFolding].InList (prevWord)) {
1792
- levelCurrent++;
1764
+ } else if (style == SCE_RB_WORD) {
1765
+ if (wordLen < MAX_KEYWORD_LENGTH) {
1766
+ word[wordLen++] = static_cast <char >(ch);
1767
+ }
1768
+ if (styleNext != SCE_RB_WORD) {
1769
+ word[wordLen] = ' \0 ' ;
1770
+ wordLen = 0 ;
1771
+ if (StrEqual (word, " end" )) {
1772
+ levelCurrent--;
1773
+ } else if (StrEqual (word, " def" )) {
1774
+ levelCurrent++;
1775
+ method_definition = MethodDefinition::Define;
1776
+ } else if (keywordLists[KeywordIndex_CodeFolding].InList (word)) {
1777
+ levelCurrent++;
1778
+ }
1793
1779
}
1794
1780
} else if (style == SCE_RB_HERE_DELIM && !heredocOpen) {
1795
1781
if (stylePrev == SCE_RB_OPERATOR && chPrev == ' <' && styler.SafeGetCharAt (startPos - 3 ) == ' <' ) {
0 commit comments