void CBPythonStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kID || token.type == kReservedKeyword || token.type == kString || token.type == kComment) { SaveTokenStart(TokenExtra()); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if (token.type == kComment || token.type == kString) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else if (token.type > kError) // misc { if (!GetWordStyle(text.GetSubstring(token.range), &style)) { style = GetDefaultFontStyle(); } } else { style = GetStyle(typeIndex, text.GetSubstring(token.range)); } } while (SetStyle(token.range, style)); }
JTEStyler::TokenExtra JTEStyler::GetFirstTokenExtraData() const { return TokenExtra(); }
void JTEStyler::UpdateStyles ( const JTextEditor* te, const JString& text, JRunArray<JTextEditor::Font>* styles, JIndexRange* recalcRange, JIndexRange* redrawRange, const JBoolean deletion, JArray<TokenData>* tokenStartList ) { if (!itsActiveFlag) { tokenStartList->RemoveAll(); return; } const JSize textLength = text.GetLength(); if (textLength == 0) { tokenStartList->RemoveAll(); return; } te->GetDefaultFont(&itsDefFontID, &itsFontSize, &itsDefFontStyle, &itsDefFontAlign); itsFontName = te->GetDefaultFontName(); TokenData tokenData; if (recalcRange->first == 1 && recalcRange->last >= text.GetLength()) { itsRedoAllFlag = kJTrue; itsCheckRange.Set(1, text.GetLength()); tokenStartList->RemoveAll(); tokenData = TokenData(1, GetFirstTokenExtraData()); tokenStartList->AppendElement(tokenData); styles->RemoveAll(); } else { itsRedoAllFlag = kJFalse; // calculate the range that needs to be checked JIndex firstIndex = recalcRange->first; JIndex lastIndex = recalcRange->last; if ((deletion && firstIndex > 1) || firstIndex > textLength) { // This fixes the case when the last character of the token is deleted. firstIndex--; // This fixes the case when the style run and the token both // end at the inserted text. (e.g. "x [ y ]" <- "x // y ]") lastIndex++; } if (lastIndex > textLength) { // We can't decrease recalcRange's end index, and we can't find // textLength+1 in *styles. lastIndex = textLength; } JIndex runIndex1, firstIndexInRun1; JBoolean ok = styles->FindRun(firstIndex, &runIndex1, &firstIndexInRun1); assert( ok ); JIndex runIndex2 = runIndex1; JIndex firstIndexInRun2 = firstIndexInRun1; ok = styles->FindRun(firstIndex, lastIndex, &runIndex2, &firstIndexInRun2); assert( ok ); run_assert(styles, lastIndex, runIndex2, firstIndexInRun2); itsCheckRange.Set(firstIndexInRun1, firstIndexInRun2 + styles->GetRunLength(runIndex2)-1); // let derived class expand the range JIndexRange savedRange = itsCheckRange; PreexpandCheckRange(text, *styles, *recalcRange, deletion, &itsCheckRange); assert( itsCheckRange.Contains(savedRange) && itsCheckRange.last <= styles->GetElementCount() ); // find nearest token in front of itsCheckRange if (tokenStartList->IsEmpty()) { tokenData = TokenData(1, GetFirstTokenExtraData()); tokenStartList->AppendElement(tokenData); } else { JBoolean foundTokenStart; TokenData target(itsCheckRange.first, TokenExtra()); JIndex tokenStartIndex = tokenStartList->SearchSorted1(target, JOrderedSetT::kAnyMatch, &foundTokenStart); if (!foundTokenStart) { tokenStartIndex--; // wants to insert -after- the value } tokenData = tokenStartList->GetElement(tokenStartIndex); // the rest of the token starts are invalid const JSize tokenStartCount = tokenStartList->GetElementCount(); if (tokenStartIndex < tokenStartCount) { tokenStartList->RemoveNextElements(tokenStartIndex+1, tokenStartCount - tokenStartIndex); } } // While typing in one place, it is much faster to back up from itsCheckRange // than to start from the top. itsTokenRunIndex = runIndex1; itsTokenFirstInRun = firstIndexInRun1; ok = styles->FindRun(firstIndex, tokenData.startIndex, &itsTokenRunIndex, &itsTokenFirstInRun); assert( ok ); run_assert(styles, tokenData.startIndex, itsTokenRunIndex, itsTokenFirstInRun); } // prepare to accumulate new token starts itsTokenStartList = tokenStartList; itsTokenStartCount = 0; itsTokenStart = tokenData.startIndex; // scan the text and adjust the styles std::istrstream input(text.GetCString(), text.GetLength()); JSeekg(input, itsTokenStart-1); itsTE = te; itsFontMgr = te->TEGetFontManager(); itsText = &text; itsStyles = styles; itsRecalcRange = recalcRange; itsRedrawRange = redrawRange; #if DEBUG_TIMING_INFO JStopWatch timer; timer.StartTimer(); #endif Scan(input, tokenData.data); #if DEBUG_TIMING_INFO timer.StopTimer(); cout << "JTEStyler: " << timer.PrintTimeInterval() << endl; #endif itsTE = NULL; itsFontMgr = NULL; itsText = NULL; itsStyles = NULL; itsRecalcRange = NULL; itsRedrawRange = NULL; itsTokenStartList = NULL; }
void CBJavaStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kID || token.type == kReservedKeyword || token.type == kBuiltInDataType || token.type == kString) { SaveTokenStart(TokenExtra()); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if (token.type == kComment || token.type == kString) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else { if (token.type == kDocCommentHTMLTag || token.type == kDocCommentSpecialTag) { if (!(token.docCommentRange).IsEmpty()) { SetStyle(token.docCommentRange, GetTypeStyle(kComment - kWhitespace)); } ExtendCheckRange(token.range.last+1); } style = GetStyle(typeIndex, text.GetSubstring(token.range)); } } while (SetStyle(token.range, style)); }
void CBTCLStyler::Scan ( std::istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); JBoolean keepGoing; Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kPredefinedWord || token.type == kOtherWord || token.type == kVariable || token.type == kString || token.type == kComment) { SaveTokenStart(TokenExtra()); } // handle special cases if (token.type == kString || token.type == kUnterminatedString) { ExtendCheckRangeForString(token.range); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFont().GetStyle(); } else if (token.type == kComment || token.type == kString || token.type == kBrace || token.type == kSquareBracket || token.type == kParenthesis) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else { style = GetStyle(typeIndex, text.GetSubstring(token.range)); } keepGoing = SetStyle(token.range, style); if (token.type == kString) { StyleEmbeddedVariables(token); } } while (keepGoing); }
void CBCShellStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input); const JString& text = GetText(); JBoolean keepGoing; Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if (token.type == kID || token.type == kVariable || token.type == kReservedWord || token.type == kSingleQuoteString || token.type == kDoubleQuoteString || token.type == kExecString || token.type == kComment) { SaveTokenStart(TokenExtra()); } // handle special cases if (token.type == kDoubleQuoteString || token.type == kExecString) { ExtendCheckRangeForString(token.range); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if (token.type == kSingleQuoteString || token.type == kDoubleQuoteString || token.type == kExecString || token.type == kComment) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else if (token.type > kError) // misc { if (!GetWordStyle(text.GetSubstring(token.range), &style)) { style = GetDefaultFontStyle(); } } else { style = GetStyle(typeIndex, text.GetSubstring(token.range)); } keepGoing = SetStyle(token.range, style); if (token.type == kDoubleQuoteString || token.type == kExecString) { StyleEmbeddedVariables(token); } } while (keepGoing); }