JFontStyle CBHTMLStyler::GetTagStyle ( const JIndexRange& tokenRange, const JIndex typeIndex ) { const JString& text = GetText(); JFontStyle style; JArray<JIndexRange> matchList; if (tagNamePattern.MatchWithin(text, tokenRange, &matchList)) { itsLatestTagName = text.GetSubstring(matchList.GetElement(2)); itsLatestTagName.ToLower(); JString openTag; if (itsLatestTagName.GetFirstCharacter() == '/' && itsLatestTagName.GetLength() > 1) { openTag = itsLatestTagName.GetSubstring(2, itsLatestTagName.GetLength()); } JBoolean found = GetWordStyle(itsLatestTagName, &style); if (!found && !openTag.IsEmpty()) { found = GetWordStyle(openTag, &style); } if (!found) { found = GetXMLStyle(itsLatestTagName, &style); } if (!found && !openTag.IsEmpty()) { found = GetXMLStyle(openTag, &style); } if (!found) { style = GetTypeStyle(typeIndex); } } else if (text.GetCharacter(tokenRange.first) == '<') { itsLatestTagName.Clear(); style = GetTypeStyle(typeIndex); } else { style = GetStyle(typeIndex, itsLatestTagName); } return style; }
void CBTCLStyler::StyleEmbeddedVariables ( const Token& token ) { emptyVariablePattern.SetSingleLine(); variablePattern.SetSingleLine(); const JString& text = GetText(); JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace); varStyle.underlineCount++; if (varStyle == GetTypeStyle(kVariable - kWhitespace)) { varStyle.underlineCount++; } JFontStyle errStyle = GetTypeStyle(kError - kWhitespace); errStyle.underlineCount++; if (errStyle == GetTypeStyle(kVariable - kWhitespace)) { errStyle.underlineCount++; } JIndexRange r = token.range, r1, r2; while (!r.IsEmpty()) { const JCharacter c = text.GetCharacter(r.first); if (c == '\\') { r.first++; } else if (c == '$') { r1 = r - (r.first-1); if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; AdjustStyle(r2, errStyle); r.first = r2.last; } else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; AdjustStyle(r2, varStyle); r.first = r2.last; } } r.first++; } }
void CBHTMLStyler::ExtendCheckRangeForJSPStartEnd ( const JIndexRange& tokenRange ) { const JFontStyle& style = GetTypeStyle(kJSPStartEnd - kWhitespace); if ((GetStyles()).IndexValid(tokenRange.last) && // avoid crash if redoing all (style != (GetStyles()).GetElement(tokenRange.first).style || style != (GetStyles()).GetElement(tokenRange.last).style)) { ExtendCheckRange((GetText()).GetLength()); } }
JFontStyle CBStylerBase::GetStyle ( const JIndex typeIndex, const JString& word ) { JFontStyle style; if (!GetWordStyle(word, &style)) { style = GetTypeStyle(typeIndex); } return style; }
void CBHTMLStyler::StyleEmbeddedVariables ( const Token& token ) { emptyVariablePattern.SetSingleLine(); variablePattern.SetSingleLine(); const JString& text = GetText(); JFontStyle varStyle = GetTypeStyle(token.type - kWhitespace); varStyle.underlineCount++; if (varStyle == GetTypeStyle(kPHPVariable - kWhitespace)) { varStyle.underlineCount++; } JFontStyle errStyle = GetTypeStyle(kError - kWhitespace); errStyle.underlineCount++; if (errStyle == GetTypeStyle(kPHPVariable - kWhitespace)) { errStyle.underlineCount++; } JIndexRange r = token.range, r1, r2; while (!r.IsEmpty()) { const JCharacter c = text.GetCharacter(r.first); if (c == '\\') { r.first++; } else if (c == '$') { r1 = r - (r.first-1); if (emptyVariablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; const JCharacter c1 = text.GetCharacter(r2.last); if (c1 != '}' && c1 != ']') { r2.last--; } AdjustStyle(r2, errStyle); r.first = r2.last; } else if (variablePattern.MatchWithin(text.GetCString() + r.first-1, r1, &r2)) { r2 += r.first-1; if (r2.first > 1 && text.GetCharacter(r2.first-1) == '{') { r2.first--; } AdjustStyle(r2, varStyle); r.first = r2.last; } } else if (c == '{' && r.first < r.last - 1 && text.GetCharacter(r.first+1) == '$' && text.GetCharacter(r.first+2) == '}') { r1.SetFirstAndLength(r.first, 3); AdjustStyle(r1, errStyle); r.first = r1.last; } r.first++; } }
void CBHTMLStyler::Scan ( istream& input, const TokenExtra& initData ) { BeginScan(input, initData.lexerState); itsLatestTagName.Clear(); const JString& text = GetText(); JBoolean keepGoing; Token token; JFontStyle style; do { token = NextToken(); if (token.type == kEOF) { break; } // save token starts if ((yy_start_stack_ptr == 0 && (token.type == kHTMLText || token.type == kHTMLComment || token.type == kJSPComment || (token.type == kHTMLTag && text.GetCharacter(token.range.first) == '<'))) || (yy_start_stack_ptr > 0 && yy_top_state() == 0 && (token.type == kPHPID || token.type == kPHPVariable || token.type == kPHPReservedKeyword || token.type == kPHPBuiltInDataType || token.type == kPHPSingleQuoteString || token.type == kPHPDoubleQuoteString || token.type == kPHPHereDocString || token.type == kPHPExecString || token.type == kJavaID || token.type == kJavaReservedKeyword || token.type == kJavaBuiltInDataType || token.type == kJavaString || token.type == kJSID || token.type == kJSReservedKeyword || token.type == kComment))) { TokenExtra data; data.lexerState = GetCurrentLexerState(); SaveTokenStart(data); // const JString s = text.GetSubstring(token.range); // cout << yy_top_state() << ' ' << yy_start_stack_ptr << ": " << s << endl; } // handle special cases if (token.type == kPHPDoubleQuoteString || token.type == kPHPExecString) { ExtendCheckRangeForString(token.range); } else if (token.type == kPHPStartEnd) { ExtendCheckRangeForPHPStartEnd(token.range); } else if (token.type == kJSPStartEnd) { ExtendCheckRangeForJSPStartEnd(token.range); } // set the style const JIndex typeIndex = token.type - kWhitespace; if (token.type == kWhitespace) { style = GetDefaultFontStyle(); } else if ((token.type == kHTMLNamedCharacter || token.type == kHTMLInvalidNamedCharacter) && GetCurrentLexerState() != 0) { style = GetStyle(kHTMLTag - kWhitespace, itsLatestTagName); if (token.type == kHTMLInvalidNamedCharacter) { style.strike = !style.strike; } else { style.underlineCount++; } } else if (token.type == kHTMLText || token.type == kHTMLComment || token.type == kCDATABlock || token.type == kMustacheCommand || token.type == kPHPStartEnd || token.type == kPHPSingleQuoteString || token.type == kPHPDoubleQuoteString || token.type == kPHPHereDocString || token.type == kPHPExecString || token.type == kJSPStartEnd || token.type == kJSPComment || token.type == kJavaString || token.type == kJSString || token.type == kJSRegexSearch || token.type == kComment) { style = GetTypeStyle(typeIndex); } else if (token.type < kWhitespace) { style = GetTypeStyle(kError - kWhitespace); } else if (token.type == kHTMLTag) { style = GetTagStyle(token.range, typeIndex); } else if (token.type == kHTMLScript) { style = GetStyle(typeIndex, *(token.language)); } else if (token.type == kHTMLNamedCharacter) { JIndexRange r = token.range; r.first++; if (text.GetCharacter(r.last) == ';') { r.last--; } style = GetStyle(typeIndex, text.GetSubstring(r)); } 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)); } keepGoing = SetStyle(token.range, style); if (token.type == kPHPDoubleQuoteString || token.type == kPHPHereDocString || token.type == kPHPExecString) { StyleEmbeddedVariables(token); } } while (keepGoing); }
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)); }
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); }