| 1 |
// Scintilla source code edit control |
| 2 |
/** @file LexHTML.cxx |
| 3 |
** Lexer for HTML. |
| 4 |
**/ |
| 5 |
// Copyright 1998-2005 by Neil Hodgson <[email protected]> |
| 6 |
// The License.txt file describes the conditions under which this software may be distributed. |
| 7 |
|
| 8 |
#include <cstdlib> |
| 9 |
#include <cassert> |
| 10 |
#include <cstring> |
| 11 |
#include <cctype> |
| 12 |
#include <cstdio> |
| 13 |
#include <cstdarg> |
| 14 |
|
| 15 |
#include <string> |
| 16 |
#include <string_view> |
| 17 |
#include <vector> |
| 18 |
#include <map> |
| 19 |
#include <set> |
| 20 |
#include <functional> |
| 21 |
|
| 22 |
#include "ILexer.h" |
| 23 |
#include "Scintilla.h" |
| 24 |
#include "SciLexer.h" |
| 25 |
#include "InList.h" |
| 26 |
#include "WordList.h" |
| 27 |
#include "LexAccessor.h" |
| 28 |
#include "Accessor.h" |
| 29 |
#include "StyleContext.h" |
| 30 |
#include "CharacterSet.h" |
| 31 |
#include "LexerModule.h" |
| 32 |
#include "OptionSet.h" |
| 33 |
#include "SubStyles.h" |
| 34 |
#include "DefaultLexer.h" |
| 35 |
|
| 36 |
using namespace Scintilla; |
| 37 |
using namespace Lexilla; |
| 38 |
|
| 39 |
namespace { |
| 40 |
|
| 41 |
#define SCE_HA_JS (SCE_HJA_START - SCE_HJ_START) |
| 42 |
#define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START) |
| 43 |
#define SCE_HA_PYTHON (SCE_HPA_START - SCE_HP_START) |
| 44 |
|
| 45 |
enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML, eScriptSGMLblock, eScriptComment }; |
| 46 |
enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc }; |
| 47 |
|
| 48 |
constexpr bool IsAWordChar(int ch) noexcept { |
| 49 |
return IsAlphaNumeric(ch) || ch == '.' || ch == '_'; |
| 50 |
} |
| 51 |
|
| 52 |
constexpr bool IsAWordStart(int ch) noexcept { |
| 53 |
return IsAlphaNumeric(ch) || ch == '_'; |
| 54 |
} |
| 55 |
|
| 56 |
bool IsOperator(int ch) noexcept { |
| 57 |
if (IsAlphaNumeric(ch)) |
| 58 |
return false; |
| 59 |
// '.' left out as it is used to make up numbers |
| 60 |
if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || |
| 61 |
ch == '(' || ch == ')' || ch == '-' || ch == '+' || |
| 62 |
ch == '=' || ch == '|' || ch == '{' || ch == '}' || |
| 63 |
ch == '[' || ch == ']' || ch == ':' || ch == ';' || |
| 64 |
ch == '<' || ch == '>' || ch == ',' || ch == '/' || |
| 65 |
ch == '?' || ch == '!' || ch == '.' || ch == '~') |
| 66 |
return true; |
| 67 |
return false; |
| 68 |
} |
| 69 |
|
| 70 |
unsigned char SafeGetUnsignedCharAt(Accessor &styler, Sci_Position position, char chDefault = ' ') { |
| 71 |
return styler.SafeGetCharAt(position, chDefault); |
| 72 |
} |
| 73 |
|
| 74 |
// Put an upper limit to bound time taken for unexpected text. |
| 75 |
constexpr Sci_PositionU maxLengthCheck = 200; |
| 76 |
|
| 77 |
std::string GetNextWord(Accessor &styler, Sci_PositionU start) { |
| 78 |
std::string ret; |
| 79 |
for (Sci_PositionU i = 0; i < maxLengthCheck; i++) { |
| 80 |
const char ch = styler.SafeGetCharAt(start + i); |
| 81 |
if ((i == 0) && !IsAWordStart(ch)) |
| 82 |
break; |
| 83 |
if ((i > 0) && !IsAWordChar(ch)) |
| 84 |
break; |
| 85 |
ret.push_back(ch); |
| 86 |
} |
| 87 |
return ret; |
| 88 |
} |
| 89 |
|
| 90 |
bool Contains(const std::string &s, std::string_view search) noexcept { |
| 91 |
return s.find(search) != std::string::npos; |
| 92 |
} |
| 93 |
|
| 94 |
script_type segIsScriptingIndicator(const Accessor &styler, Sci_PositionU start, Sci_PositionU end, script_type prevValue) { |
| 95 |
const std::string s = styler.GetRangeLowered(start, end+1); |
| 96 |
if (Contains(s, "vbs")) |
| 97 |
return eScriptVBS; |
| 98 |
if (Contains(s, "pyth")) |
| 99 |
return eScriptPython; |
| 100 |
// https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type |
| 101 |
// https://mimesniff.spec.whatwg.org/#javascript-mime-type |
| 102 |
if (Contains(s, "javas") || Contains(s, "ecmas") || Contains(s, "module") || Contains(s, "jscr")) |
| 103 |
return eScriptJS; |
| 104 |
if (Contains(s, "php")) |
| 105 |
return eScriptPHP; |
| 106 |
|
| 107 |
const size_t xml = s.find("xml"); |
| 108 |
if (xml != std::string::npos) { |
| 109 |
for (size_t t = 0; t < xml; t++) { |
| 110 |
if (!IsASpace(s[t])) { |
| 111 |
return prevValue; |
| 112 |
} |
| 113 |
} |
| 114 |
return eScriptXML; |
| 115 |
} |
| 116 |
|
| 117 |
return prevValue; |
| 118 |
} |
| 119 |
|
| 120 |
constexpr bool IsPHPScriptState(int state) noexcept { |
| 121 |
return (state >= SCE_HPHP_DEFAULT && state <= SCE_HPHP_OPERATOR) || (state == SCE_HPHP_COMPLEX_VARIABLE); |
| 122 |
} |
| 123 |
|
| 124 |
script_type ScriptOfState(int state) noexcept { |
| 125 |
if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) { |
| 126 |
return eScriptPython; |
| 127 |
} else if ((state >= SCE_HB_START && state <= SCE_HB_STRINGEOL) || (state == SCE_H_ASPAT || state == SCE_H_XCCOMMENT)) { |
| 128 |
return eScriptVBS; |
| 129 |
} else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_TEMPLATELITERAL)) { |
| 130 |
return eScriptJS; |
| 131 |
} else if (IsPHPScriptState(state)) { |
| 132 |
return eScriptPHP; |
| 133 |
} else if ((state >= SCE_H_SGML_DEFAULT) && (state < SCE_H_SGML_BLOCK_DEFAULT)) { |
| 134 |
return eScriptSGML; |
| 135 |
} else if (state == SCE_H_SGML_BLOCK_DEFAULT) { |
| 136 |
return eScriptSGMLblock; |
| 137 |
} else { |
| 138 |
return eScriptNone; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
constexpr int statePrintForState(int state, script_mode inScriptType) noexcept { |
| 143 |
int StateToPrint = state; |
| 144 |
|
| 145 |
if (state >= SCE_HJ_START) { |
| 146 |
if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) { |
| 147 |
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_PYTHON); |
| 148 |
} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) { |
| 149 |
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_VBS); |
| 150 |
} else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_TEMPLATELITERAL)) { |
| 151 |
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_JS); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
return StateToPrint; |
| 156 |
} |
| 157 |
|
| 158 |
constexpr int stateForPrintState(int StateToPrint) noexcept { |
| 159 |
int state = StateToPrint; |
| 160 |
|
| 161 |
if ((StateToPrint >= SCE_HPA_START) && (StateToPrint <= SCE_HPA_IDENTIFIER)) { |
| 162 |
state = StateToPrint - SCE_HA_PYTHON; |
| 163 |
} else if ((StateToPrint >= SCE_HBA_START) && (StateToPrint <= SCE_HBA_STRINGEOL)) { |
| 164 |
state = StateToPrint - SCE_HA_VBS; |
| 165 |
} else if ((StateToPrint >= SCE_HJA_START) && (StateToPrint <= SCE_HJA_TEMPLATELITERAL)) { |
| 166 |
state = StateToPrint - SCE_HA_JS; |
| 167 |
} |
| 168 |
|
| 169 |
return state; |
| 170 |
} |
| 171 |
|
| 172 |
constexpr bool IsNumberChar(char ch) noexcept { |
| 173 |
return IsADigit(ch) || ch == '.' || ch == '-' || ch == '#'; |
| 174 |
} |
| 175 |
|
| 176 |
constexpr bool isStringState(int state) noexcept { |
| 177 |
bool bResult = false; |
| 178 |
|
| 179 |
switch (state) { |
| 180 |
case SCE_HJ_DOUBLESTRING: |
| 181 |
case SCE_HJ_SINGLESTRING: |
| 182 |
case SCE_HJ_REGEX: |
| 183 |
case SCE_HJ_TEMPLATELITERAL: |
| 184 |
case SCE_HJA_DOUBLESTRING: |
| 185 |
case SCE_HJA_SINGLESTRING: |
| 186 |
case SCE_HJA_REGEX: |
| 187 |
case SCE_HJA_TEMPLATELITERAL: |
| 188 |
case SCE_HB_STRING: |
| 189 |
case SCE_HBA_STRING: |
| 190 |
case SCE_HP_STRING: |
| 191 |
case SCE_HP_CHARACTER: |
| 192 |
case SCE_HP_TRIPLE: |
| 193 |
case SCE_HP_TRIPLEDOUBLE: |
| 194 |
case SCE_HPA_STRING: |
| 195 |
case SCE_HPA_CHARACTER: |
| 196 |
case SCE_HPA_TRIPLE: |
| 197 |
case SCE_HPA_TRIPLEDOUBLE: |
| 198 |
case SCE_HPHP_HSTRING: |
| 199 |
case SCE_HPHP_SIMPLESTRING: |
| 200 |
case SCE_HPHP_HSTRING_VARIABLE: |
| 201 |
case SCE_HPHP_COMPLEX_VARIABLE: |
| 202 |
bResult = true; |
| 203 |
break; |
| 204 |
default : |
| 205 |
break; |
| 206 |
} |
| 207 |
return bResult; |
| 208 |
} |
| 209 |
|
| 210 |
constexpr bool stateAllowsTermination(int state) noexcept { |
| 211 |
bool allowTermination = !isStringState(state); |
| 212 |
if (allowTermination) { |
| 213 |
switch (state) { |
| 214 |
case SCE_HPHP_COMMENT: |
| 215 |
case SCE_HP_COMMENTLINE: |
| 216 |
case SCE_HPA_COMMENTLINE: |
| 217 |
allowTermination = false; |
| 218 |
break; |
| 219 |
default: |
| 220 |
break; |
| 221 |
} |
| 222 |
} |
| 223 |
return allowTermination; |
| 224 |
} |
| 225 |
|
| 226 |
bool isPreProcessorEndTag(int state, int ch) noexcept { |
| 227 |
const script_type type = ScriptOfState(state); |
| 228 |
if (state == SCE_H_ASP || AnyOf(type, eScriptVBS, eScriptJS, eScriptPython)) { |
| 229 |
return ch == '%'; |
| 230 |
} |
| 231 |
if (type == eScriptPHP) { |
| 232 |
return ch == '%' || ch == '?'; |
| 233 |
} |
| 234 |
return ch == '?'; |
| 235 |
} |
| 236 |
|
| 237 |
// not really well done, since it's only comments that should lex the %> and <% |
| 238 |
constexpr bool isCommentASPState(int state) noexcept { |
| 239 |
bool bResult = false; |
| 240 |
|
| 241 |
switch (state) { |
| 242 |
case SCE_HJ_COMMENT: |
| 243 |
case SCE_HJ_COMMENTLINE: |
| 244 |
case SCE_HJ_COMMENTDOC: |
| 245 |
case SCE_HB_COMMENTLINE: |
| 246 |
case SCE_HP_COMMENTLINE: |
| 247 |
case SCE_HPHP_COMMENT: |
| 248 |
case SCE_HPHP_COMMENTLINE: |
| 249 |
bResult = true; |
| 250 |
break; |
| 251 |
default : |
| 252 |
break; |
| 253 |
} |
| 254 |
return bResult; |
| 255 |
} |
| 256 |
|
| 257 |
bool classifyAttribHTML(script_mode inScriptType, Sci_PositionU start, Sci_PositionU end, const WordList &keywords, const WordClassifier &classifier, Accessor &styler, const std::string &tag) { |
| 258 |
int chAttr = SCE_H_ATTRIBUTEUNKNOWN; |
| 259 |
bool isLanguageType = false; |
| 260 |
if (IsNumberChar(styler[start])) { |
| 261 |
chAttr = SCE_H_NUMBER; |
| 262 |
} else { |
| 263 |
const std::string s = styler.GetRangeLowered(start, end+1); |
| 264 |
if (keywords.InList(s)) { |
| 265 |
chAttr = SCE_H_ATTRIBUTE; |
| 266 |
} else { |
| 267 |
int subStyle = classifier.ValueFor(s); |
| 268 |
if (subStyle < 0) { |
| 269 |
// Didn't find attribute, check for tag.attribute |
| 270 |
const std::string tagAttribute = tag + "." + s; |
| 271 |
subStyle = classifier.ValueFor(tagAttribute); |
| 272 |
} |
| 273 |
if (subStyle >= 0) { |
| 274 |
chAttr = subStyle; |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
if (inScriptType == eNonHtmlScript) { |
| 279 |
// see https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model |
| 280 |
if (s == "type" || s == "language") { |
| 281 |
isLanguageType = true; |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
if ((chAttr == SCE_H_ATTRIBUTEUNKNOWN) && !keywords) |
| 286 |
// No keywords -> all are known |
| 287 |
chAttr = SCE_H_ATTRIBUTE; |
| 288 |
styler.ColourTo(end, chAttr); |
| 289 |
return isLanguageType; |
| 290 |
} |
| 291 |
|
| 292 |
// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-core-concepts |
| 293 |
bool isHTMLCustomElement(const std::string &tag) noexcept { |
| 294 |
// check valid HTML custom element name: starts with an ASCII lower alpha and contains hyphen. |
| 295 |
// IsUpperOrLowerCase() is used for `html.tags.case.sensitive=1`. |
| 296 |
if (tag.length() < 2 || !IsUpperOrLowerCase(tag[0])) { |
| 297 |
return false; |
| 298 |
} |
| 299 |
if (tag.find('-') == std::string::npos) { |
| 300 |
return false; |
| 301 |
} |
| 302 |
return true; |
| 303 |
} |
| 304 |
|
| 305 |
int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, |
| 306 |
const WordList &keywords, const WordClassifier &classifier, Accessor &styler, bool &tagDontFold, |
| 307 |
bool caseSensitive, bool isXml, bool allowScripts, |
| 308 |
const std::set<std::string> &nonFoldingTags, |
| 309 |
std::string &tag) { |
| 310 |
tag.clear(); |
| 311 |
// Copy after the '<' and stop before ' ' |
| 312 |
for (Sci_PositionU cPos = start; cPos <= end; cPos++) { |
| 313 |
const char ch = styler[cPos]; |
| 314 |
if (IsASpace(ch)) { |
| 315 |
break; |
| 316 |
} |
| 317 |
if ((ch != '<') && (ch != '/')) { |
| 318 |
tag.push_back(caseSensitive ? ch : MakeLowerCase(ch)); |
| 319 |
} |
| 320 |
} |
| 321 |
// if the current language is XML, I can fold any tag |
| 322 |
// if the current language is HTML, I don't want to fold certain tags (input, meta, etc.) |
| 323 |
//...to find it in the list of no-container-tags |
| 324 |
tagDontFold = (!isXml) && (nonFoldingTags.count(tag) > 0); |
| 325 |
// No keywords -> all are known |
| 326 |
int chAttr = SCE_H_TAGUNKNOWN; |
| 327 |
if (!tag.empty() && (tag[0] == '!')) { |
| 328 |
chAttr = SCE_H_SGML_DEFAULT; |
| 329 |
} else if (!keywords || keywords.InList(tag)) { |
| 330 |
chAttr = SCE_H_TAG; |
| 331 |
} else if (!isXml && isHTMLCustomElement(tag)) { |
| 332 |
chAttr = SCE_H_TAG; |
| 333 |
} else { |
| 334 |
const int subStyle = classifier.ValueFor(tag); |
| 335 |
if (subStyle >= 0) { |
| 336 |
chAttr = subStyle; |
| 337 |
} |
| 338 |
} |
| 339 |
if (chAttr != SCE_H_TAGUNKNOWN) { |
| 340 |
styler.ColourTo(end, chAttr); |
| 341 |
} |
| 342 |
if (chAttr == SCE_H_TAG) { |
| 343 |
if (allowScripts && (tag == "script")) { |
| 344 |
// check to see if this is a self-closing tag by sniffing ahead |
| 345 |
bool isSelfClose = false; |
| 346 |
for (Sci_PositionU cPos = end; cPos <= end + maxLengthCheck; cPos++) { |
| 347 |
const char ch = styler.SafeGetCharAt(cPos, '\0'); |
| 348 |
if (ch == '\0' || ch == '>') |
| 349 |
break; |
| 350 |
if (ch == '/' && styler.SafeGetCharAt(cPos + 1, '\0') == '>') { |
| 351 |
isSelfClose = true; |
| 352 |
break; |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
// do not enter a script state if the tag self-closed |
| 357 |
if (!isSelfClose) |
| 358 |
chAttr = SCE_H_SCRIPT; |
| 359 |
} else if (!isXml && (tag == "comment")) { |
| 360 |
chAttr = SCE_H_COMMENT; |
| 361 |
} |
| 362 |
} |
| 363 |
return chAttr; |
| 364 |
} |
| 365 |
|
| 366 |
void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, |
| 367 |
const WordList &keywords, const WordClassifier &classifier, const WordClassifier &classifierServer, Accessor &styler, script_mode inScriptType) { |
| 368 |
const std::string s = styler.GetRange(start, end+1); |
| 369 |
int chAttr = SCE_HJ_WORD; |
| 370 |
const bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1])); |
| 371 |
if (wordIsNumber) { |
| 372 |
chAttr = SCE_HJ_NUMBER; |
| 373 |
} else if (keywords.InList(s)) { |
| 374 |
chAttr = SCE_HJ_KEYWORD; |
| 375 |
} else { |
| 376 |
const int subStyle = (inScriptType == eNonHtmlScript) ? classifier.ValueFor(s) : classifierServer.ValueFor(s); |
| 377 |
if (subStyle >= 0) { |
| 378 |
chAttr = subStyle; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); |
| 383 |
} |
| 384 |
|
| 385 |
int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, const WordClassifier &classifier, Accessor &styler, script_mode inScriptType) { |
| 386 |
int chAttr = SCE_HB_IDENTIFIER; |
| 387 |
const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.'); |
| 388 |
if (wordIsNumber) { |
| 389 |
chAttr = SCE_HB_NUMBER; |
| 390 |
} else { |
| 391 |
const std::string s = styler.GetRangeLowered(start, end+1); |
| 392 |
if (keywords.InList(s)) { |
| 393 |
chAttr = SCE_HB_WORD; |
| 394 |
if (s == "rem") |
| 395 |
chAttr = SCE_HB_COMMENTLINE; |
| 396 |
} else { |
| 397 |
const int subStyle = classifier.ValueFor(s); |
| 398 |
if (subStyle >= 0) { |
| 399 |
chAttr = subStyle; |
| 400 |
} |
| 401 |
} |
| 402 |
} |
| 403 |
styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); |
| 404 |
if (chAttr == SCE_HB_COMMENTLINE) |
| 405 |
return SCE_HB_COMMENTLINE; |
| 406 |
else |
| 407 |
return SCE_HB_DEFAULT; |
| 408 |
} |
| 409 |
|
| 410 |
void classifyWordHTPy(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, const WordClassifier &classifier, Accessor &styler, std::string &prevWord, script_mode inScriptType, bool isMako) { |
| 411 |
const bool wordIsNumber = IsADigit(styler[start]); |
| 412 |
const std::string s = styler.GetRange(start, end + 1); |
| 413 |
int chAttr = SCE_HP_IDENTIFIER; |
| 414 |
if (prevWord == "class") |
| 415 |
chAttr = SCE_HP_CLASSNAME; |
| 416 |
else if (prevWord == "def") |
| 417 |
chAttr = SCE_HP_DEFNAME; |
| 418 |
else if (wordIsNumber) |
| 419 |
chAttr = SCE_HP_NUMBER; |
| 420 |
else if (keywords.InList(s)) |
| 421 |
chAttr = SCE_HP_WORD; |
| 422 |
else if (isMako && (s == "block")) |
| 423 |
chAttr = SCE_HP_WORD; |
| 424 |
else { |
| 425 |
const int subStyle = classifier.ValueFor(s); |
| 426 |
if (subStyle >= 0) { |
| 427 |
chAttr = subStyle; |
| 428 |
} |
| 429 |
} |
| 430 |
styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); |
| 431 |
prevWord = s; |
| 432 |
} |
| 433 |
|
| 434 |
// Update the word colour to default or keyword |
| 435 |
// Called when in a PHP word |
| 436 |
void classifyWordHTPHP(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, const WordClassifier &classifier, Accessor &styler) { |
| 437 |
int chAttr = SCE_HPHP_DEFAULT; |
| 438 |
const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1])); |
| 439 |
if (wordIsNumber) { |
| 440 |
chAttr = SCE_HPHP_NUMBER; |
| 441 |
} else { |
| 442 |
const std::string s = styler.GetRangeLowered(start, end+1);; |
| 443 |
if (keywords.InList(s)) { |
| 444 |
chAttr = SCE_HPHP_WORD; |
| 445 |
} else { |
| 446 |
const int subStyle = classifier.ValueFor(s); |
| 447 |
if (subStyle >= 0) { |
| 448 |
chAttr = subStyle; |
| 449 |
} |
| 450 |
} |
| 451 |
} |
| 452 |
styler.ColourTo(end, chAttr); |
| 453 |
} |
| 454 |
|
| 455 |
bool isWordHSGML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, const Accessor &styler) { |
| 456 |
const std::string s = styler.GetRange(start, end + 1); |
| 457 |
return keywords.InList(s); |
| 458 |
} |
| 459 |
|
| 460 |
bool isWordCdata(Sci_PositionU start, Sci_PositionU end, const Accessor &styler) { |
| 461 |
const std::string s = styler.GetRange(start, end + 1); |
| 462 |
return s == "[CDATA["; |
| 463 |
} |
| 464 |
|
| 465 |
// Return the first state to reach when entering a scripting language |
| 466 |
constexpr int StateForScript(script_type scriptLanguage) noexcept { |
| 467 |
int Result = SCE_HJ_START; |
| 468 |
switch (scriptLanguage) { |
| 469 |
case eScriptVBS: |
| 470 |
Result = SCE_HB_START; |
| 471 |
break; |
| 472 |
case eScriptPython: |
| 473 |
Result = SCE_HP_START; |
| 474 |
break; |
| 475 |
case eScriptPHP: |
| 476 |
Result = SCE_HPHP_DEFAULT; |
| 477 |
break; |
| 478 |
case eScriptXML: |
| 479 |
Result = SCE_H_TAGUNKNOWN; |
| 480 |
break; |
| 481 |
case eScriptSGML: |
| 482 |
Result = SCE_H_SGML_DEFAULT; |
| 483 |
break; |
| 484 |
case eScriptComment: |
| 485 |
Result = SCE_H_COMMENT; |
| 486 |
break; |
| 487 |
default : |
| 488 |
break; |
| 489 |
} |
| 490 |
return Result; |
| 491 |
} |
| 492 |
|
| 493 |
constexpr int defaultStateForSGML(script_type scriptLanguage) noexcept { |
| 494 |
return (scriptLanguage == eScriptSGMLblock)? SCE_H_SGML_BLOCK_DEFAULT : SCE_H_SGML_DEFAULT; |
| 495 |
} |
| 496 |
|
| 497 |
constexpr bool issgmlwordchar(int ch) noexcept { |
| 498 |
return !IsASCII(ch) || |
| 499 |
(IsAlphaNumeric(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#'); |
| 500 |
} |
| 501 |
|
| 502 |
constexpr bool IsPhpWordStart(int ch) noexcept { |
| 503 |
return (IsUpperOrLowerCase(ch) || (ch == '_')) || (ch >= 0x7f); |
| 504 |
} |
| 505 |
|
| 506 |
constexpr bool IsPhpWordChar(int ch) noexcept { |
| 507 |
return IsADigit(ch) || IsPhpWordStart(ch); |
| 508 |
} |
| 509 |
|
| 510 |
constexpr bool InTagState(int state) noexcept { |
| 511 |
return AnyOf(state, SCE_H_TAG, SCE_H_TAGUNKNOWN, SCE_H_SCRIPT, |
| 512 |
SCE_H_ATTRIBUTE, SCE_H_ATTRIBUTEUNKNOWN, |
| 513 |
SCE_H_NUMBER, SCE_H_OTHER, |
| 514 |
SCE_H_DOUBLESTRING, SCE_H_SINGLESTRING); |
| 515 |
} |
| 516 |
|
| 517 |
constexpr bool isLineEnd(int ch) noexcept { |
| 518 |
return ch == '\r' || ch == '\n'; |
| 519 |
} |
| 520 |
|
| 521 |
bool isMakoBlockEnd(const int ch, const int chNext, const std::string &blockType) noexcept { |
| 522 |
if (blockType.empty()) { |
| 523 |
return ((ch == '%') && (chNext == '>')); |
| 524 |
} else if (InList(blockType, { "inherit", "namespace", "include", "page" })) { |
| 525 |
return ((ch == '/') && (chNext == '>')); |
| 526 |
} else if (blockType == "%") { |
| 527 |
if (ch == '/' && isLineEnd(chNext)) |
| 528 |
return true; |
| 529 |
else |
| 530 |
return isLineEnd(ch); |
| 531 |
} else if (blockType == "{") { |
| 532 |
return ch == '}'; |
| 533 |
} else { |
| 534 |
return (ch == '>'); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
bool isDjangoBlockEnd(const int ch, const int chNext, const std::string &blockType) noexcept { |
| 539 |
if (blockType.empty()) { |
| 540 |
return false; |
| 541 |
} else if (blockType == "%") { |
| 542 |
return ((ch == '%') && (chNext == '}')); |
| 543 |
} else if (blockType == "{") { |
| 544 |
return ((ch == '}') && (chNext == '}')); |
| 545 |
} else { |
| 546 |
return false; |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
class PhpNumberState { |
| 551 |
enum NumberBase { BASE_10 = 0, BASE_2, BASE_8, BASE_16 }; |
| 552 |
static constexpr const char *const digitList[] = { "_0123456789", "_01", "_01234567", "_0123456789abcdefABCDEF" }; |
| 553 |
|
| 554 |
NumberBase base = BASE_10; |
| 555 |
bool decimalPart = false; |
| 556 |
bool exponentPart = false; |
| 557 |
bool invalid = false; |
| 558 |
bool finished = false; |
| 559 |
|
| 560 |
bool leadingZero = false; |
| 561 |
bool invalidBase8 = false; |
| 562 |
|
| 563 |
bool betweenDigits = false; |
| 564 |
bool decimalChar = false; |
| 565 |
bool exponentChar = false; |
| 566 |
|
| 567 |
public: |
| 568 |
[[nodiscard]] bool isInvalid() const noexcept { return invalid; } |
| 569 |
[[nodiscard]] bool isFinished() const noexcept { return finished; } |
| 570 |
|
| 571 |
bool init(int ch, int chPlus1, int chPlus2) noexcept { |
| 572 |
base = BASE_10; |
| 573 |
decimalPart = false; |
| 574 |
exponentPart = false; |
| 575 |
invalid = false; |
| 576 |
finished = false; |
| 577 |
|
| 578 |
leadingZero = false; |
| 579 |
invalidBase8 = false; |
| 580 |
|
| 581 |
betweenDigits = false; |
| 582 |
decimalChar = false; |
| 583 |
exponentChar = false; |
| 584 |
|
| 585 |
if (ch == '.' && strchr(digitList[BASE_10] + !betweenDigits, chPlus1) != nullptr) { |
| 586 |
decimalPart = true; |
| 587 |
betweenDigits = true; |
| 588 |
} else if (ch == '0' && (chPlus1 == 'b' || chPlus1 == 'B')) { |
| 589 |
base = BASE_2; |
| 590 |
} else if (ch == '0' && (chPlus1 == 'o' || chPlus1 == 'O')) { |
| 591 |
base = BASE_8; |
| 592 |
} else if (ch == '0' && (chPlus1 == 'x' || chPlus1 == 'X')) { |
| 593 |
base = BASE_16; |
| 594 |
} else if (strchr(digitList[BASE_10] + !betweenDigits, ch) != nullptr) { |
| 595 |
leadingZero = ch == '0'; |
| 596 |
betweenDigits = true; |
| 597 |
check(chPlus1, chPlus2); |
| 598 |
if (finished && leadingZero) { |
| 599 |
// single zero should be base 10 |
| 600 |
base = BASE_10; |
| 601 |
} |
| 602 |
} else { |
| 603 |
return false; |
| 604 |
} |
| 605 |
return true; |
| 606 |
} |
| 607 |
|
| 608 |
bool check(int ch, int chPlus1) noexcept { |
| 609 |
if (strchr(digitList[base] + !betweenDigits, ch) != nullptr) { |
| 610 |
if (leadingZero) { |
| 611 |
invalidBase8 = invalidBase8 || strchr(digitList[BASE_8] + !betweenDigits, ch) == nullptr; |
| 612 |
} |
| 613 |
|
| 614 |
betweenDigits = ch != '_'; |
| 615 |
decimalChar = false; |
| 616 |
exponentChar = false; |
| 617 |
} else if (ch == '_') { |
| 618 |
invalid = true; |
| 619 |
|
| 620 |
betweenDigits = false; |
| 621 |
decimalChar = false; |
| 622 |
// exponentChar is unchanged |
| 623 |
} else if (base == BASE_10 && ch == '.' && ( |
| 624 |
!(decimalPart || exponentPart) || strchr(digitList[BASE_10] + !betweenDigits, chPlus1) != nullptr) |
| 625 |
) { |
| 626 |
invalid = invalid || !betweenDigits || decimalPart || exponentPart; |
| 627 |
decimalPart = true; |
| 628 |
|
| 629 |
betweenDigits = false; |
| 630 |
decimalChar = true; |
| 631 |
exponentChar = false; |
| 632 |
} else if (base == BASE_10 && (ch == 'e' || ch == 'E')) { |
| 633 |
invalid = invalid || !(betweenDigits || decimalChar) || exponentPart; |
| 634 |
exponentPart = true; |
| 635 |
|
| 636 |
betweenDigits = false; |
| 637 |
decimalChar = false; |
| 638 |
exponentChar = true; |
| 639 |
} else if (base == BASE_10 && (ch == '-' || ch == '+') && exponentChar) { |
| 640 |
invalid = invalid || strchr(digitList[BASE_10] + !betweenDigits, chPlus1) == nullptr; |
| 641 |
|
| 642 |
betweenDigits = false; |
| 643 |
decimalChar = false; |
| 644 |
// exponentChar is unchanged |
| 645 |
} else if (IsPhpWordChar(ch)) { |
| 646 |
invalid = true; |
| 647 |
|
| 648 |
betweenDigits = false; |
| 649 |
decimalChar = false; |
| 650 |
exponentChar = false; |
| 651 |
} else { |
| 652 |
invalid = invalid || !(betweenDigits || decimalChar); |
| 653 |
finished = true; |
| 654 |
if (base == BASE_10 && leadingZero && !decimalPart && !exponentPart) { |
| 655 |
base = BASE_8; |
| 656 |
invalid = invalid || invalidBase8; |
| 657 |
} |
| 658 |
} |
| 659 |
return finished; |
| 660 |
} |
| 661 |
}; |
| 662 |
|
| 663 |
constexpr bool isPHPStringState(int state) noexcept { |
| 664 |
return |
| 665 |
(state == SCE_HPHP_HSTRING) || |
| 666 |
(state == SCE_HPHP_SIMPLESTRING) || |
| 667 |
(state == SCE_HPHP_HSTRING_VARIABLE) || |
| 668 |
(state == SCE_HPHP_COMPLEX_VARIABLE); |
| 669 |
} |
| 670 |
|
| 671 |
constexpr bool StyleNeedsBacktrack(int state) noexcept { |
| 672 |
return InTagState(state) || isPHPStringState(state); |
| 673 |
} |
| 674 |
|
| 675 |
enum class AllowPHP : int { |
| 676 |
None, // No PHP |
| 677 |
PHP, // <?php and <?= |
| 678 |
Question, // <? |
| 679 |
}; |
| 680 |
|
| 681 |
enum class InstructionTag { |
| 682 |
None, |
| 683 |
XML, |
| 684 |
Open,// <? ?> short open tag |
| 685 |
Echo,// <?= ?> short echo tag |
| 686 |
PHP, // <?php ?> standard tag |
| 687 |
}; |
| 688 |
|
| 689 |
InstructionTag segIsScriptInstruction(AllowPHP allowPHP, int state, const Accessor &styler, Sci_PositionU start, bool isXml) { |
| 690 |
constexpr std::string_view phpTag = "php"; |
| 691 |
constexpr std::string_view xmlTag = "xml"; |
| 692 |
const std::string tag = styler.GetRangeLowered(start, start + phpTag.length()); |
| 693 |
if (allowPHP != AllowPHP::None) { |
| 694 |
// Require <?php or <?= |
| 695 |
if (tag == phpTag) { |
| 696 |
return InstructionTag::PHP; |
| 697 |
} |
| 698 |
if (!tag.empty() && (tag.front() == '=')) { |
| 699 |
return InstructionTag::Echo; |
| 700 |
} |
| 701 |
} |
| 702 |
if (isXml || tag == xmlTag) { |
| 703 |
return AnyOf(state, SCE_H_DEFAULT, SCE_H_SGML_BLOCK_DEFAULT)? InstructionTag::XML : InstructionTag::None; |
| 704 |
} |
| 705 |
return (allowPHP == AllowPHP::Question) ? InstructionTag::Open : InstructionTag::None; |
| 706 |
} |
| 707 |
|
| 708 |
Sci_Position FindPhpStringDelimiter(std::string &phpStringDelimiter, Sci_Position i, const Sci_Position lengthDoc, Accessor &styler, bool &isSimpleString) { |
| 709 |
const Sci_Position beginning = i - 1; |
| 710 |
bool isQuoted = false; |
| 711 |
|
| 712 |
while (i < lengthDoc && (styler[i] == ' ' || styler[i] == '\t')) |
| 713 |
i++; |
| 714 |
char ch = styler.SafeGetCharAt(i); |
| 715 |
const char chNext = styler.SafeGetCharAt(i + 1); |
| 716 |
phpStringDelimiter.clear(); |
| 717 |
if (!IsPhpWordStart(ch)) { |
| 718 |
if ((ch == '\'' || ch == '\"') && IsPhpWordStart(chNext)) { |
| 719 |
isSimpleString = ch == '\''; |
| 720 |
isQuoted = true; |
| 721 |
i++; |
| 722 |
ch = chNext; |
| 723 |
} else { |
| 724 |
return beginning; |
| 725 |
} |
| 726 |
} |
| 727 |
phpStringDelimiter.push_back(ch); |
| 728 |
i++; |
| 729 |
Sci_Position j = i; |
| 730 |
for (; j < lengthDoc && !isLineEnd(styler[j]); j++) { |
| 731 |
if (!IsPhpWordChar(styler[j]) && isQuoted) { |
| 732 |
if (((isSimpleString && styler[j] == '\'') || (!isSimpleString && styler[j] == '\"')) && isLineEnd(styler.SafeGetCharAt(j + 1))) { |
| 733 |
isQuoted = false; |
| 734 |
j++; |
| 735 |
break; |
| 736 |
} else { |
| 737 |
phpStringDelimiter.clear(); |
| 738 |
return beginning; |
| 739 |
} |
| 740 |
} |
| 741 |
phpStringDelimiter.push_back(styler[j]); |
| 742 |
} |
| 743 |
if (isQuoted) { |
| 744 |
phpStringDelimiter.clear(); |
| 745 |
return beginning; |
| 746 |
} |
| 747 |
return j - 1; |
| 748 |
} |
| 749 |
|
| 750 |
// Options used for LexerHTML |
| 751 |
struct OptionsHTML { |
| 752 |
int aspDefaultLanguage = eScriptJS; |
| 753 |
bool caseSensitive = false; |
| 754 |
bool allowScripts = true; |
| 755 |
AllowPHP allowPHPinXML = AllowPHP::Question; |
| 756 |
AllowPHP allowPHPinHTML = AllowPHP::Question; |
| 757 |
bool isMako = false; |
| 758 |
bool isDjango = false; |
| 759 |
bool allowASPinXML = true; |
| 760 |
bool allowASPinHTML = true; |
| 761 |
bool fold = false; |
| 762 |
bool foldHTML = false; |
| 763 |
bool foldHTMLPreprocessor = true; |
| 764 |
bool foldCompact = true; |
| 765 |
bool foldComment = false; |
| 766 |
bool foldHeredoc = false; |
| 767 |
bool foldXmlAtTagOpen = false; |
| 768 |
}; |
| 769 |
|
| 770 |
const char * const htmlWordListDesc[] = { |
| 771 |
"HTML elements and attributes", |
| 772 |
"JavaScript keywords", |
| 773 |
"VBScript keywords", |
| 774 |
"Python keywords", |
| 775 |
"PHP keywords", |
| 776 |
"SGML and DTD keywords", |
| 777 |
nullptr, |
| 778 |
}; |
| 779 |
|
| 780 |
const char * const phpscriptWordListDesc[] = { |
| 781 |
"", //Unused |
| 782 |
"", //Unused |
| 783 |
"", //Unused |
| 784 |
"", //Unused |
| 785 |
"PHP keywords", |
| 786 |
"", //Unused |
| 787 |
nullptr, |
| 788 |
}; |
| 789 |
|
| 790 |
struct OptionSetHTML : public OptionSet<OptionsHTML> { |
| 791 |
explicit OptionSetHTML(bool isPHPScript_) { |
| 792 |
|
| 793 |
DefineProperty("asp.default.language", &OptionsHTML::aspDefaultLanguage, |
| 794 |
"Script in ASP code is initially assumed to be in JavaScript. " |
| 795 |
"To change this to VBScript set asp.default.language to 2. Python is 3."); |
| 796 |
|
| 797 |
DefineProperty("html.tags.case.sensitive", &OptionsHTML::caseSensitive, |
| 798 |
"For XML and HTML, setting this property to 1 will make tags match in a case " |
| 799 |
"sensitive way which is the expected behaviour for XML and XHTML."); |
| 800 |
|
| 801 |
DefineProperty("lexer.xml.allow.scripts", &OptionsHTML::allowScripts, |
| 802 |
"Set to 0 to disable scripts in XML."); |
| 803 |
|
| 804 |
DefineProperty("lexer.xml.allow.php", &OptionsHTML::allowPHPinXML, |
| 805 |
"Set to 0 to disable PHP in XML, 1 to accept <?php and <?=, 2 to also accept <?." |
| 806 |
"The default is 2."); |
| 807 |
|
| 808 |
DefineProperty("lexer.html.allow.php", &OptionsHTML::allowPHPinHTML, |
| 809 |
"Set to 0 to disable PHP in HTML, 1 to accept <?php and <?=, 2 to also accept <?." |
| 810 |
"The default is 2."); |
| 811 |
|
| 812 |
DefineProperty("lexer.html.mako", &OptionsHTML::isMako, |
| 813 |
"Set to 1 to enable the mako template language."); |
| 814 |
|
| 815 |
DefineProperty("lexer.html.django", &OptionsHTML::isDjango, |
| 816 |
"Set to 1 to enable the django template language."); |
| 817 |
|
| 818 |
DefineProperty("lexer.xml.allow.asp", &OptionsHTML::allowASPinXML, |
| 819 |
"Set to 0 to disable ASP in XML."); |
| 820 |
|
| 821 |
DefineProperty("lexer.html.allow.asp", &OptionsHTML::allowASPinHTML, |
| 822 |
"Set to 0 to disable ASP in HTML."); |
| 823 |
|
| 824 |
DefineProperty("fold", &OptionsHTML::fold); |
| 825 |
|
| 826 |
DefineProperty("fold.html", &OptionsHTML::foldHTML, |
| 827 |
"Folding is turned on or off for HTML and XML files with this option. " |
| 828 |
"The fold option must also be on for folding to occur."); |
| 829 |
|
| 830 |
DefineProperty("fold.html.preprocessor", &OptionsHTML::foldHTMLPreprocessor, |
| 831 |
"Folding is turned on or off for scripts embedded in HTML files with this option. " |
| 832 |
"The default is on."); |
| 833 |
|
| 834 |
DefineProperty("fold.compact", &OptionsHTML::foldCompact); |
| 835 |
|
| 836 |
DefineProperty("fold.hypertext.comment", &OptionsHTML::foldComment, |
| 837 |
"Allow folding for comments in scripts embedded in HTML. " |
| 838 |
"The default is off."); |
| 839 |
|
| 840 |
DefineProperty("fold.hypertext.heredoc", &OptionsHTML::foldHeredoc, |
| 841 |
"Allow folding for heredocs in scripts embedded in HTML. " |
| 842 |
"The default is off."); |
| 843 |
|
| 844 |
DefineProperty("fold.xml.at.tag.open", &OptionsHTML::foldXmlAtTagOpen, |
| 845 |
"Enable folding for XML at the start of open tag. " |
| 846 |
"The default is off."); |
| 847 |
|
| 848 |
DefineWordListSets(isPHPScript_ ? phpscriptWordListDesc : htmlWordListDesc); |
| 849 |
} |
| 850 |
}; |
| 851 |
|
| 852 |
constexpr char styleSubable[] = { SCE_H_TAG, SCE_H_ATTRIBUTE, SCE_HJ_WORD, SCE_HJA_WORD, SCE_HB_WORD, SCE_HP_WORD, SCE_HPHP_WORD, 0 }; |
| 853 |
// Allow normal styles to be contiguous using 0x80 to 0xBF by assigning sub-styles from 0xC0 to 0xFF |
| 854 |
constexpr int SubStylesHTML = 0xC0; |
| 855 |
|
| 856 |
const LexicalClass lexicalClassesHTML[] = { |
| 857 |
// Lexer HTML SCLEX_HTML SCE_H_ SCE_HJ_ SCE_HJA_ SCE_HB_ SCE_HBA_ SCE_HP_ SCE_HPHP_ SCE_HPA_: |
| 858 |
0, "SCE_H_DEFAULT", "default", "Text", |
| 859 |
1, "SCE_H_TAG", "tag", "Tags", |
| 860 |
2, "SCE_H_ERRORTAGUNKNOWN", "error tag", "Unknown Tags", |
| 861 |
3, "SCE_H_ATTRIBUTE", "attribute", "Attributes", |
| 862 |
4, "SCE_H_ATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes", |
| 863 |
5, "SCE_H_NUMBER", "literal numeric", "Numbers", |
| 864 |
6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings", |
| 865 |
7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings", |
| 866 |
8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='", |
| 867 |
9, "SCE_H_COMMENT", "comment", "Comment", |
| 868 |
10, "SCE_H_ENTITY", "literal", "Entities", |
| 869 |
11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'", |
| 870 |
12, "SCE_H_XMLSTART", "identifier", "XML identifier start '<?'", |
| 871 |
13, "SCE_H_XMLEND", "identifier", "XML identifier end '?>'", |
| 872 |
14, "SCE_H_SCRIPT", "error", "Internal state which should never be visible", |
| 873 |
15, "SCE_H_ASP", "preprocessor", "ASP <% ... %>", |
| 874 |
16, "SCE_H_ASPAT", "preprocessor", "ASP <% ... %>", |
| 875 |
17, "SCE_H_CDATA", "literal", "CDATA", |
| 876 |
18, "SCE_H_QUESTION", "preprocessor", "PHP", |
| 877 |
19, "SCE_H_VALUE", "literal string", "Unquoted values", |
| 878 |
20, "SCE_H_XCCOMMENT", "comment", "ASP.NET, JSP Comment <%-- ... --%>", |
| 879 |
21, "SCE_H_SGML_DEFAULT", "default", "SGML tags <! ... >", |
| 880 |
22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command", |
| 881 |
23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param", |
| 882 |
24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string", |
| 883 |
25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string", |
| 884 |
26, "SCE_H_SGML_ERROR", "error", "SGML error", |
| 885 |
27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)", |
| 886 |
28, "SCE_H_SGML_ENTITY", "literal", "SGML entity", |
| 887 |
29, "SCE_H_SGML_COMMENT", "comment", "SGML comment", |
| 888 |
30, "SCE_H_SGML_1ST_PARAM_COMMENT", "error comment", "SGML first parameter - lexer internal. It is an error if any text is in this style.", |
| 889 |
31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block", |
| 890 |
32, "", "predefined", "", |
| 891 |
33, "", "predefined", "", |
| 892 |
34, "", "predefined", "", |
| 893 |
35, "", "predefined", "", |
| 894 |
36, "", "predefined", "", |
| 895 |
37, "", "predefined", "", |
| 896 |
38, "", "predefined", "", |
| 897 |
39, "", "predefined", "", |
| 898 |
40, "SCE_HJ_START", "client javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag", |
| 899 |
41, "SCE_HJ_DEFAULT", "client javascript default", "JS Default", |
| 900 |
42, "SCE_HJ_COMMENT", "client javascript comment", "JS Comment", |
| 901 |
43, "SCE_HJ_COMMENTLINE", "client javascript comment line", "JS Line Comment", |
| 902 |
44, "SCE_HJ_COMMENTDOC", "client javascript comment documentation", "JS Doc comment", |
| 903 |
45, "SCE_HJ_NUMBER", "client javascript literal numeric", "JS Number", |
| 904 |
46, "SCE_HJ_WORD", "client javascript identifier", "JS Word", |
| 905 |
47, "SCE_HJ_KEYWORD", "client javascript keyword", "JS Keyword", |
| 906 |
48, "SCE_HJ_DOUBLESTRING", "client javascript literal string", "JS Double quoted string", |
| 907 |
49, "SCE_HJ_SINGLESTRING", "client javascript literal string", "JS Single quoted string", |
| 908 |
50, "SCE_HJ_SYMBOLS", "client javascript operator", "JS Symbols", |
| 909 |
51, "SCE_HJ_STRINGEOL", "client javascript error literal string", "JavaScript EOL", |
| 910 |
52, "SCE_HJ_REGEX", "client javascript literal regex", "JavaScript RegEx", |
| 911 |
53, "SCE_HJ_TEMPLATELITERAL", "client javascript literal template", "JS Template Literal", |
| 912 |
54, "", "unused", "", |
| 913 |
55, "SCE_HJA_START", "server javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag", |
| 914 |
56, "SCE_HJA_DEFAULT", "server javascript default", "JS Default", |
| 915 |
57, "SCE_HJA_COMMENT", "server javascript comment", "JS Comment", |
| 916 |
58, "SCE_HJA_COMMENTLINE", "server javascript comment line", "JS Line Comment", |
| 917 |
59, "SCE_HJA_COMMENTDOC", "server javascript comment documentation", "JS Doc comment", |
| 918 |
60, "SCE_HJA_NUMBER", "server javascript literal numeric", "JS Number", |
| 919 |
61, "SCE_HJA_WORD", "server javascript identifier", "JS Word", |
| 920 |
62, "SCE_HJA_KEYWORD", "server javascript keyword", "JS Keyword", |
| 921 |
63, "SCE_HJA_DOUBLESTRING", "server javascript literal string", "JS Double quoted string", |
| 922 |
64, "SCE_HJA_SINGLESTRING", "server javascript literal string", "JS Single quoted string", |
| 923 |
65, "SCE_HJA_SYMBOLS", "server javascript operator", "JS Symbols", |
| 924 |
66, "SCE_HJA_STRINGEOL", "server javascript error literal string", "JavaScript EOL", |
| 925 |
67, "SCE_HJA_REGEX", "server javascript literal regex", "JavaScript RegEx", |
| 926 |
68, "SCE_HJA_TEMPLATELITERAL", "server javascript literal template", "JS Template Literal", |
| 927 |
69, "", "unused", "", |
| 928 |
70, "SCE_HB_START", "client basic default", "Start", |
| 929 |
71, "SCE_HB_DEFAULT", "client basic default", "Default", |
| 930 |
72, "SCE_HB_COMMENTLINE", "client basic comment line", "Comment", |
| 931 |
73, "SCE_HB_NUMBER", "client basic literal numeric", "Number", |
| 932 |
74, "SCE_HB_WORD", "client basic keyword", "KeyWord", |
| 933 |
75, "SCE_HB_STRING", "client basic literal string", "String", |
| 934 |
76, "SCE_HB_IDENTIFIER", "client basic identifier", "Identifier", |
| 935 |
77, "SCE_HB_STRINGEOL", "client basic literal string", "Unterminated string", |
| 936 |
78, "", "unused", "", |
| 937 |
79, "", "unused", "", |
| 938 |
80, "SCE_HBA_START", "server basic default", "Start", |
| 939 |
81, "SCE_HBA_DEFAULT", "server basic default", "Default", |
| 940 |
82, "SCE_HBA_COMMENTLINE", "server basic comment line", "Comment", |
| 941 |
83, "SCE_HBA_NUMBER", "server basic literal numeric", "Number", |
| 942 |
84, "SCE_HBA_WORD", "server basic keyword", "KeyWord", |
| 943 |
85, "SCE_HBA_STRING", "server basic literal string", "String", |
| 944 |
86, "SCE_HBA_IDENTIFIER", "server basic identifier", "Identifier", |
| 945 |
87, "SCE_HBA_STRINGEOL", "server basic literal string", "Unterminated string", |
| 946 |
88, "", "unused", "", |
| 947 |
89, "", "unused", "", |
| 948 |
90, "SCE_HP_START", "client python default", "Embedded Python", |
| 949 |
91, "SCE_HP_DEFAULT", "client python default", "Embedded Python", |
| 950 |
92, "SCE_HP_COMMENTLINE", "client python comment line", "Comment", |
| 951 |
93, "SCE_HP_NUMBER", "client python literal numeric", "Number", |
| 952 |
94, "SCE_HP_STRING", "client python literal string", "String", |
| 953 |
95, "SCE_HP_CHARACTER", "client python literal string character", "Single quoted string", |
| 954 |
96, "SCE_HP_WORD", "client python keyword", "Keyword", |
| 955 |
97, "SCE_HP_TRIPLE", "client python literal string", "Triple quotes", |
| 956 |
98, "SCE_HP_TRIPLEDOUBLE", "client python literal string", "Triple double quotes", |
| 957 |
99, "SCE_HP_CLASSNAME", "client python identifier", "Class name definition", |
| 958 |
100, "SCE_HP_DEFNAME", "client python identifier", "Function or method name definition", |
| 959 |
101, "SCE_HP_OPERATOR", "client python operator", "Operators", |
| 960 |
102, "SCE_HP_IDENTIFIER", "client python identifier", "Identifiers", |
| 961 |
103, "", "unused", "", |
| 962 |
104, "SCE_HPHP_COMPLEX_VARIABLE", "server php identifier", "PHP complex variable", |
| 963 |
105, "SCE_HPA_START", "server python default", "ASP Python", |
| 964 |
106, "SCE_HPA_DEFAULT", "server python default", "ASP Python", |
| 965 |
107, "SCE_HPA_COMMENTLINE", "server python comment line", "Comment", |
| 966 |
108, "SCE_HPA_NUMBER", "server python literal numeric", "Number", |
| 967 |
109, "SCE_HPA_STRING", "server python literal string", "String", |
| 968 |
110, "SCE_HPA_CHARACTER", "server python literal string character", "Single quoted string", |
| 969 |
111, "SCE_HPA_WORD", "server python keyword", "Keyword", |
| 970 |
112, "SCE_HPA_TRIPLE", "server python literal string", "Triple quotes", |
| 971 |
113, "SCE_HPA_TRIPLEDOUBLE", "server python literal string", "Triple double quotes", |
| 972 |
114, "SCE_HPA_CLASSNAME", "server python identifier", "Class name definition", |
| 973 |
115, "SCE_HPA_DEFNAME", "server python identifier", "Function or method name definition", |
| 974 |
116, "SCE_HPA_OPERATOR", "server python operator", "Operators", |
| 975 |
117, "SCE_HPA_IDENTIFIER", "server python identifier", "Identifiers", |
| 976 |
118, "SCE_HPHP_DEFAULT", "server php default", "Default", |
| 977 |
119, "SCE_HPHP_HSTRING", "server php literal string", "Double quoted String", |
| 978 |
120, "SCE_HPHP_SIMPLESTRING", "server php literal string", "Single quoted string", |
| 979 |
121, "SCE_HPHP_WORD", "server php keyword", "Keyword", |
| 980 |
122, "SCE_HPHP_NUMBER", "server php literal numeric", "Number", |
| 981 |
123, "SCE_HPHP_VARIABLE", "server php identifier", "Variable", |
| 982 |
124, "SCE_HPHP_COMMENT", "server php comment", "Comment", |
| 983 |
125, "SCE_HPHP_COMMENTLINE", "server php comment line", "One line comment", |
| 984 |
126, "SCE_HPHP_HSTRING_VARIABLE", "server php literal string identifier", "PHP variable in double quoted string", |
| 985 |
127, "SCE_HPHP_OPERATOR", "server php operator", "PHP operator", |
| 986 |
}; |
| 987 |
|
| 988 |
const LexicalClass lexicalClassesXML[] = { |
| 989 |
// Lexer.Secondary XML SCLEX_XML SCE_H_: |
| 990 |
0, "SCE_H_DEFAULT", "default", "Default", |
| 991 |
1, "SCE_H_TAG", "tag", "Tags", |
| 992 |
2, "SCE_H_TAGUNKNOWN", "error tag", "Unknown Tags", |
| 993 |
3, "SCE_H_ATTRIBUTE", "attribute", "Attributes", |
| 994 |
4, "SCE_H_ERRORATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes", |
| 995 |
5, "SCE_H_NUMBER", "literal numeric", "Numbers", |
| 996 |
6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings", |
| 997 |
7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings", |
| 998 |
8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='", |
| 999 |
9, "SCE_H_COMMENT", "comment", "Comment", |
| 1000 |
10, "SCE_H_ENTITY", "literal", "Entities", |
| 1001 |
11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'", |
| 1002 |
12, "SCE_H_XMLSTART", "identifier", "XML identifier start '<?'", |
| 1003 |
13, "SCE_H_XMLEND", "identifier", "XML identifier end '?>'", |
| 1004 |
14, "", "unused", "", |
| 1005 |
15, "", "unused", "", |
| 1006 |
16, "", "unused", "", |
| 1007 |
17, "SCE_H_CDATA", "literal", "CDATA", |
| 1008 |
18, "SCE_H_QUESTION", "preprocessor", "Question", |
| 1009 |
19, "SCE_H_VALUE", "literal string", "Unquoted Value", |
| 1010 |
20, "", "unused", "", |
| 1011 |
21, "SCE_H_SGML_DEFAULT", "default", "SGML tags <! ... >", |
| 1012 |
22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command", |
| 1013 |
23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param", |
| 1014 |
24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string", |
| 1015 |
25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string", |
| 1016 |
26, "SCE_H_SGML_ERROR", "error", "SGML error", |
| 1017 |
27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)", |
| 1018 |
28, "SCE_H_SGML_ENTITY", "literal", "SGML entity", |
| 1019 |
29, "SCE_H_SGML_COMMENT", "comment", "SGML comment", |
| 1020 |
30, "", "unused", "", |
| 1021 |
31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block", |
| 1022 |
}; |
| 1023 |
|
| 1024 |
const char * const tagsThatDoNotFold[] = { |
| 1025 |
"area", |
| 1026 |
"base", |
| 1027 |
"basefont", |
| 1028 |
"br", |
| 1029 |
"col", |
| 1030 |
"command", |
| 1031 |
"embed", |
| 1032 |
"frame", |
| 1033 |
"hr", |
| 1034 |
"img", |
| 1035 |
"input", |
| 1036 |
"isindex", |
| 1037 |
"keygen", |
| 1038 |
"link", |
| 1039 |
"meta", |
| 1040 |
"param", |
| 1041 |
"source", |
| 1042 |
"track", |
| 1043 |
"wbr" |
| 1044 |
}; |
| 1045 |
|
| 1046 |
} |
| 1047 |
|
| 1048 |
class LexerHTML : public DefaultLexer { |
| 1049 |
bool isXml; |
| 1050 |
bool isPHPScript; |
| 1051 |
WordList keywordsHTML; |
| 1052 |
WordList keywordsJS; |
| 1053 |
WordList keywordsVB; |
| 1054 |
WordList keywordsPy; |
| 1055 |
WordList keywordsPHP; |
| 1056 |
WordList keywordsSGML; // SGML (DTD) keywords |
| 1057 |
OptionsHTML options; |
| 1058 |
OptionSetHTML osHTML; |
| 1059 |
std::set<std::string> nonFoldingTags; |
| 1060 |
SubStyles subStyles{styleSubable,SubStylesHTML,SubStylesAvailable,0}; |
| 1061 |
public: |
| 1062 |
explicit LexerHTML(bool isXml_, bool isPHPScript_) : |
| 1063 |
DefaultLexer( |
| 1064 |
isXml_ ? "xml" : (isPHPScript_ ? "phpscript" : "hypertext"), |
| 1065 |
isXml_ ? SCLEX_XML : (isPHPScript_ ? SCLEX_PHPSCRIPT : SCLEX_HTML), |
| 1066 |
isXml_ ? lexicalClassesXML : lexicalClassesHTML, |
| 1067 |
isXml_ ? std::size(lexicalClassesXML) : std::size(lexicalClassesHTML)), |
| 1068 |
isXml(isXml_), |
| 1069 |
isPHPScript(isPHPScript_), |
| 1070 |
osHTML(isPHPScript_), |
| 1071 |
nonFoldingTags(std::begin(tagsThatDoNotFold), std::end(tagsThatDoNotFold)) { |
| 1072 |
} |
| 1073 |
~LexerHTML() override { |
| 1074 |
} |
| 1075 |
void SCI_METHOD Release() override { |
| 1076 |
delete this; |
| 1077 |
} |
| 1078 |
const char *SCI_METHOD PropertyNames() override { |
| 1079 |
return osHTML.PropertyNames(); |
| 1080 |
} |
| 1081 |
int SCI_METHOD PropertyType(const char *name) override { |
| 1082 |
return osHTML.PropertyType(name); |
| 1083 |
} |
| 1084 |
const char *SCI_METHOD DescribeProperty(const char *name) override { |
| 1085 |
return osHTML.DescribeProperty(name); |
| 1086 |
} |
| 1087 |
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; |
| 1088 |
const char * SCI_METHOD PropertyGet(const char *key) override { |
| 1089 |
return osHTML.PropertyGet(key); |
| 1090 |
} |
| 1091 |
const char *SCI_METHOD DescribeWordListSets() override { |
| 1092 |
return osHTML.DescribeWordListSets(); |
| 1093 |
} |
| 1094 |
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; |
| 1095 |
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; |
| 1096 |
// No Fold as all folding performs in Lex. |
| 1097 |
|
| 1098 |
int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override { |
| 1099 |
return subStyles.Allocate(styleBase, numberStyles); |
| 1100 |
} |
| 1101 |
int SCI_METHOD SubStylesStart(int styleBase) override { |
| 1102 |
return subStyles.Start(styleBase); |
| 1103 |
} |
| 1104 |
int SCI_METHOD SubStylesLength(int styleBase) override { |
| 1105 |
return subStyles.Length(styleBase); |
| 1106 |
} |
| 1107 |
int SCI_METHOD StyleFromSubStyle(int subStyle) override { |
| 1108 |
const int styleBase = subStyles.BaseStyle(subStyle); |
| 1109 |
return styleBase; |
| 1110 |
} |
| 1111 |
int SCI_METHOD PrimaryStyleFromStyle(int style) override { |
| 1112 |
return style; |
| 1113 |
} |
| 1114 |
void SCI_METHOD FreeSubStyles() override { |
| 1115 |
subStyles.Free(); |
| 1116 |
} |
| 1117 |
void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override { |
| 1118 |
const int styleBase = subStyles.BaseStyle(style); |
| 1119 |
const bool lowerCase = AnyOf(styleBase, SCE_H_TAG, SCE_H_ATTRIBUTE, SCE_HB_WORD); |
| 1120 |
subStyles.SetIdentifiers(style, identifiers, lowerCase); |
| 1121 |
} |
| 1122 |
int SCI_METHOD DistanceToSecondaryStyles() override { |
| 1123 |
return 0; |
| 1124 |
} |
| 1125 |
const char *SCI_METHOD GetSubStyleBases() override { |
| 1126 |
return styleSubable; |
| 1127 |
} |
| 1128 |
|
| 1129 |
static ILexer5 *LexerFactoryHTML() { |
| 1130 |
return new LexerHTML(false, false); |
| 1131 |
} |
| 1132 |
static ILexer5 *LexerFactoryXML() { |
| 1133 |
return new LexerHTML(true, false); |
| 1134 |
} |
| 1135 |
static ILexer5 *LexerFactoryPHPScript() { |
| 1136 |
return new LexerHTML(false, true); |
| 1137 |
} |
| 1138 |
}; |
| 1139 |
|
| 1140 |
Sci_Position SCI_METHOD LexerHTML::PropertySet(const char *key, const char *val) { |
| 1141 |
if (osHTML.PropertySet(&options, key, val)) { |
| 1142 |
return 0; |
| 1143 |
} |
| 1144 |
return -1; |
| 1145 |
} |
| 1146 |
|
| 1147 |
Sci_Position SCI_METHOD LexerHTML::WordListSet(int n, const char *wl) { |
| 1148 |
WordList *wordListN = nullptr; |
| 1149 |
bool lowerCase = false; |
| 1150 |
switch (n) { |
| 1151 |
case 0: |
| 1152 |
wordListN = &keywordsHTML; |
| 1153 |
lowerCase = true; |
| 1154 |
break; |
| 1155 |
case 1: |
| 1156 |
wordListN = &keywordsJS; |
| 1157 |
break; |
| 1158 |
case 2: |
| 1159 |
wordListN = &keywordsVB; |
| 1160 |
lowerCase = true; |
| 1161 |
break; |
| 1162 |
case 3: |
| 1163 |
wordListN = &keywordsPy; |
| 1164 |
break; |
| 1165 |
case 4: |
| 1166 |
wordListN = &keywordsPHP; |
| 1167 |
break; |
| 1168 |
case 5: |
| 1169 |
wordListN = &keywordsSGML; |
| 1170 |
break; |
| 1171 |
default: |
| 1172 |
break; |
| 1173 |
} |
| 1174 |
Sci_Position firstModification = -1; |
| 1175 |
if (wordListN) { |
| 1176 |
if (wordListN->Set(wl, lowerCase)) { |
| 1177 |
firstModification = 0; |
| 1178 |
} |
| 1179 |
} |
| 1180 |
return firstModification; |
| 1181 |
} |
| 1182 |
|
| 1183 |
void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { |
| 1184 |
Accessor styler(pAccess, nullptr); |
| 1185 |
|
| 1186 |
const WordClassifier &classifierTags = subStyles.Classifier(SCE_H_TAG); |
| 1187 |
const WordClassifier &classifierAttributes = subStyles.Classifier(SCE_H_ATTRIBUTE); |
| 1188 |
const WordClassifier &classifierJavaScript = subStyles.Classifier(SCE_HJ_WORD); |
| 1189 |
const WordClassifier &classifierJavaScriptServer = subStyles.Classifier(SCE_HJA_WORD); |
| 1190 |
const WordClassifier &classifierBasic = subStyles.Classifier(SCE_HB_WORD); |
| 1191 |
const WordClassifier &classifierPython = subStyles.Classifier(SCE_HP_WORD); |
| 1192 |
const WordClassifier &classifierPHP = subStyles.Classifier(SCE_HPHP_WORD); |
| 1193 |
|
| 1194 |
if (isPHPScript && (startPos == 0)) { |
| 1195 |
initStyle = SCE_HPHP_DEFAULT; |
| 1196 |
} |
| 1197 |
std::string lastTag; |
| 1198 |
std::string prevWord; |
| 1199 |
PhpNumberState phpNumber; |
| 1200 |
std::string phpStringDelimiter; |
| 1201 |
int StateToPrint = initStyle; |
| 1202 |
int state = stateForPrintState(StateToPrint); |
| 1203 |
std::string makoBlockType; |
| 1204 |
int makoComment = 0; |
| 1205 |
std::string djangoBlockType; |
| 1206 |
// If inside a tag, it may be a script tag, so reread from the start of line starting tag to ensure any language tags are seen |
| 1207 |
// PHP string can be heredoc, must find a delimiter first. Reread from beginning of line containing the string, to get the correct lineState |
| 1208 |
if (StyleNeedsBacktrack(state)) { |
| 1209 |
while ((startPos > 0) && (StyleNeedsBacktrack(styler.StyleIndexAt(startPos - 1)))) { |
| 1210 |
const Sci_Position backLineStart = styler.LineStart(styler.GetLine(startPos-1)); |
| 1211 |
length += startPos - backLineStart; |
| 1212 |
startPos = backLineStart; |
| 1213 |
} |
| 1214 |
if (startPos > 0) { |
| 1215 |
state = styler.StyleIndexAt(startPos - 1); |
| 1216 |
} else { |
| 1217 |
state = isPHPScript ? SCE_HPHP_DEFAULT : SCE_H_DEFAULT; |
| 1218 |
} |
| 1219 |
} |
| 1220 |
styler.StartAt(startPos); |
| 1221 |
|
| 1222 |
/* Nothing handles getting out of these, so we need not start in any of them. |
| 1223 |
* As we're at line start and they can't span lines, we'll re-detect them anyway */ |
| 1224 |
switch (state) { |
| 1225 |
case SCE_H_QUESTION: |
| 1226 |
case SCE_H_XMLSTART: |
| 1227 |
case SCE_H_XMLEND: |
| 1228 |
case SCE_H_ASP: |
| 1229 |
state = SCE_H_DEFAULT; |
| 1230 |
break; |
| 1231 |
default: |
| 1232 |
break; |
| 1233 |
} |
| 1234 |
|
| 1235 |
Sci_Position lineCurrent = styler.GetLine(startPos); |
| 1236 |
int lineState; |
| 1237 |
if (lineCurrent > 0) { |
| 1238 |
lineState = styler.GetLineState(lineCurrent-1); |
| 1239 |
} else { |
| 1240 |
// Default client and ASP scripting language is JavaScript |
| 1241 |
lineState = eScriptJS << 8; |
| 1242 |
lineState |= options.aspDefaultLanguage << 4; |
| 1243 |
} |
| 1244 |
script_mode inScriptType = static_cast<script_mode>((lineState >> 0) & 0x03); // 2 bits of scripting mode |
| 1245 |
|
| 1246 |
bool tagOpened = (lineState >> 2) & 0x01; // 1 bit to know if we are in an opened tag |
| 1247 |
bool tagClosing = (lineState >> 3) & 0x01; // 1 bit to know if we are in a closing tag |
| 1248 |
bool tagDontFold = false; //some HTML tags should not be folded |
| 1249 |
script_type aspScript = static_cast<script_type>((lineState >> 4) & 0x0F); // 4 bits of script name |
| 1250 |
script_type clientScript = static_cast<script_type>((lineState >> 8) & 0x0F); // 4 bits of script name |
| 1251 |
int beforePreProc = (lineState >> 12) & 0xFF; // 8 bits of state |
| 1252 |
bool isLanguageType = (lineState >> 20) & 1; // type or language attribute for script tag |
| 1253 |
int sgmlBlockLevel = (lineState >> 21); |
| 1254 |
|
| 1255 |
script_type scriptLanguage = ScriptOfState(state); |
| 1256 |
// If eNonHtmlScript coincides with SCE_H_COMMENT, assume eScriptComment |
| 1257 |
if (inScriptType == eNonHtmlScript && state == SCE_H_COMMENT) { |
| 1258 |
scriptLanguage = eScriptComment; |
| 1259 |
} |
| 1260 |
script_type beforeLanguage = ScriptOfState(beforePreProc); |
| 1261 |
const bool foldHTML = options.foldHTML; |
| 1262 |
const bool fold = foldHTML && options.fold; |
| 1263 |
const bool foldHTMLPreprocessor = foldHTML && options.foldHTMLPreprocessor; |
| 1264 |
const bool foldCompact = options.foldCompact; |
| 1265 |
const bool foldComment = fold && options.foldComment; |
| 1266 |
const bool foldHeredoc = fold && options.foldHeredoc; |
| 1267 |
const bool foldXmlAtTagOpen = isXml && fold && options.foldXmlAtTagOpen; |
| 1268 |
const bool caseSensitive = options.caseSensitive; |
| 1269 |
const bool allowScripts = options.allowScripts; |
| 1270 |
const AllowPHP allowPHP = isXml ? options.allowPHPinXML : options.allowPHPinHTML; |
| 1271 |
const bool isMako = options.isMako; |
| 1272 |
const bool isDjango = options.isDjango; |
| 1273 |
const bool allowASP = (isXml ? options.allowASPinXML : options.allowASPinHTML) && !isMako && !isDjango; |
| 1274 |
const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", true); |
| 1275 |
const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", true); |
| 1276 |
const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", true); |
| 1277 |
// TODO: also handle + and - (except if they're part of ++ or --) and return keywords |
| 1278 |
const CharacterSet setOKBeforeJSRE(CharacterSet::setNone, "([{=,:;!%^&*|?~> "); |
| 1279 |
// Only allow [A-Za-z0-9.#-_:] in entities |
| 1280 |
const CharacterSet setEntity(CharacterSet::setAlphaNum, ".#-_:"); |
| 1281 |
|
| 1282 |
int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; |
| 1283 |
int levelCurrent = levelPrev; |
| 1284 |
Sci_Position visibleChars = 0; |
| 1285 |
int lineStartVisibleChars = 0; |
| 1286 |
|
| 1287 |
int chPrev = ' '; |
| 1288 |
int ch = ' '; |
| 1289 |
int chPrevNonWhite = ' '; |
| 1290 |
// look back to set chPrevNonWhite properly for better regex colouring |
| 1291 |
if (scriptLanguage == eScriptJS && startPos > 0) { |
| 1292 |
Sci_Position back = startPos; |
| 1293 |
int style = 0; |
| 1294 |
while (--back) { |
| 1295 |
style = styler.StyleIndexAt(back); |
| 1296 |
if (style < SCE_HJ_DEFAULT || style > SCE_HJ_COMMENTDOC) |
| 1297 |
// includes SCE_HJ_COMMENT & SCE_HJ_COMMENTLINE |
| 1298 |
break; |
| 1299 |
} |
| 1300 |
if (style == SCE_HJ_SYMBOLS) { |
| 1301 |
chPrevNonWhite = SafeGetUnsignedCharAt(styler, back); |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
styler.StartSegment(startPos); |
| 1306 |
const Sci_Position lengthDoc = startPos + length; |
| 1307 |
for (Sci_Position i = startPos; i < lengthDoc; i++) { |
| 1308 |
const int chPrev2 = chPrev; |
| 1309 |
chPrev = ch; |
| 1310 |
if (!IsASpace(ch) && state != SCE_HJ_COMMENT && |
| 1311 |
state != SCE_HJ_COMMENTLINE && state != SCE_HJ_COMMENTDOC) |
| 1312 |
chPrevNonWhite = ch; |
| 1313 |
ch = static_cast<unsigned char>(styler[i]); |
| 1314 |
int chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 1315 |
const int chNext2 = SafeGetUnsignedCharAt(styler, i + 2); |
| 1316 |
|
| 1317 |
// Handle DBCS codepages |
| 1318 |
if (styler.IsLeadByte(static_cast<char>(ch))) { |
| 1319 |
chPrev = ' '; |
| 1320 |
i += 1; |
| 1321 |
continue; |
| 1322 |
} |
| 1323 |
|
| 1324 |
if ((!IsASpace(ch) || !foldCompact) && fold) |
| 1325 |
visibleChars++; |
| 1326 |
if (!IsASpace(ch)) |
| 1327 |
lineStartVisibleChars++; |
| 1328 |
|
| 1329 |
// decide what is the current state to print (depending of the script tag) |
| 1330 |
StateToPrint = statePrintForState(state, inScriptType); |
| 1331 |
|
| 1332 |
// handle script folding |
| 1333 |
if (fold) { |
| 1334 |
switch (scriptLanguage) { |
| 1335 |
case eScriptJS: |
| 1336 |
case eScriptPHP: |
| 1337 |
//not currently supported case eScriptVBS: |
| 1338 |
|
| 1339 |
if (!AnyOf(state, SCE_HPHP_COMMENT, SCE_HPHP_COMMENTLINE, SCE_HJ_COMMENT, SCE_HJ_COMMENTLINE, SCE_HJ_COMMENTDOC) && |
| 1340 |
!isStringState(state)) { |
| 1341 |
//Platform::DebugPrintf("state=%d, StateToPrint=%d, initStyle=%d\n", state, StateToPrint, initStyle); |
| 1342 |
//if ((state == SCE_HPHP_OPERATOR) || (state == SCE_HPHP_DEFAULT) || (state == SCE_HJ_SYMBOLS) || (state == SCE_HJ_START) || (state == SCE_HJ_DEFAULT)) { |
| 1343 |
if (ch == '#') { |
| 1344 |
Sci_Position j = i + 1; |
| 1345 |
while ((j < lengthDoc) && IsASpaceOrTab(styler.SafeGetCharAt(j))) { |
| 1346 |
j++; |
| 1347 |
} |
| 1348 |
if (styler.Match(j, "region") || styler.Match(j, "if")) { |
| 1349 |
levelCurrent++; |
| 1350 |
} else if (styler.Match(j, "end")) { |
| 1351 |
levelCurrent--; |
| 1352 |
} |
| 1353 |
} else if ((ch == '{') || (ch == '}') || (foldComment && (ch == '/') && (chNext == '*'))) { |
| 1354 |
levelCurrent += (((ch == '{') || (ch == '/')) ? 1 : -1); |
| 1355 |
} |
| 1356 |
} else if (((state == SCE_HPHP_COMMENT) || (state == SCE_HJ_COMMENT || state == SCE_HJ_COMMENTDOC)) && foldComment && (ch == '*') && (chNext == '/')) { |
| 1357 |
levelCurrent--; |
| 1358 |
} |
| 1359 |
break; |
| 1360 |
case eScriptPython: |
| 1361 |
if (state != SCE_HP_COMMENTLINE && !isMako) { |
| 1362 |
if ((ch == ':') && ((chNext == '\n') || (chNext == '\r' && chNext2 == '\n'))) { |
| 1363 |
levelCurrent++; |
| 1364 |
} else if ((ch == '\n') && !((chNext == '\r') && (chNext2 == '\n')) && (chNext != '\n')) { |
| 1365 |
// check if the number of tabs is lower than the level |
| 1366 |
constexpr int tabWidth = 8; |
| 1367 |
int Findlevel = (levelCurrent & ~SC_FOLDLEVELBASE) * tabWidth; |
| 1368 |
for (Sci_Position j = 0; Findlevel > 0; j++) { |
| 1369 |
const char chTmp = styler.SafeGetCharAt(i + j + 1); |
| 1370 |
if (chTmp == '\t') { |
| 1371 |
Findlevel -= tabWidth; |
| 1372 |
} else if (chTmp == ' ') { |
| 1373 |
Findlevel--; |
| 1374 |
} else { |
| 1375 |
break; |
| 1376 |
} |
| 1377 |
} |
| 1378 |
|
| 1379 |
if (Findlevel > 0) { |
| 1380 |
levelCurrent -= Findlevel / tabWidth; |
| 1381 |
if (Findlevel % tabWidth) |
| 1382 |
levelCurrent--; |
| 1383 |
} |
| 1384 |
} |
| 1385 |
} |
| 1386 |
break; |
| 1387 |
default: |
| 1388 |
break; |
| 1389 |
} |
| 1390 |
} |
| 1391 |
|
| 1392 |
if ((ch == '\r' && chNext != '\n') || (ch == '\n')) { |
| 1393 |
// Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix) |
| 1394 |
// Avoid triggering two times on Dos/Win |
| 1395 |
// New line -> record any line state onto /next/ line |
| 1396 |
if (fold) { |
| 1397 |
int lev = levelPrev; |
| 1398 |
if (visibleChars == 0) |
| 1399 |
lev |= SC_FOLDLEVELWHITEFLAG; |
| 1400 |
if ((levelCurrent > levelPrev) && (visibleChars > 0)) |
| 1401 |
lev |= SC_FOLDLEVELHEADERFLAG; |
| 1402 |
|
| 1403 |
styler.SetLevel(lineCurrent, lev); |
| 1404 |
visibleChars = 0; |
| 1405 |
levelPrev = levelCurrent; |
| 1406 |
} |
| 1407 |
styler.SetLineState(lineCurrent, |
| 1408 |
((inScriptType & 0x03) << 0) | |
| 1409 |
((tagOpened ? 1 : 0) << 2) | |
| 1410 |
((tagClosing ? 1 : 0) << 3) | |
| 1411 |
((aspScript & 0x0F) << 4) | |
| 1412 |
((clientScript & 0x0F) << 8) | |
| 1413 |
((beforePreProc & 0xFF) << 12) | |
| 1414 |
((isLanguageType ? 1 : 0) << 20) | |
| 1415 |
(sgmlBlockLevel << 21)); |
| 1416 |
lineCurrent++; |
| 1417 |
lineStartVisibleChars = 0; |
| 1418 |
} |
| 1419 |
|
| 1420 |
// handle start of Mako comment line |
| 1421 |
if (isMako && ch == '#' && chNext == '#') { |
| 1422 |
makoComment = 1; |
| 1423 |
state = SCE_HP_COMMENTLINE; |
| 1424 |
} |
| 1425 |
|
| 1426 |
// handle end of Mako comment line |
| 1427 |
else if (isMako && makoComment && (ch == '\r' || ch == '\n')) { |
| 1428 |
makoComment = 0; |
| 1429 |
styler.ColourTo(i - 1, StateToPrint); |
| 1430 |
if (scriptLanguage == eScriptPython) { |
| 1431 |
state = SCE_HP_DEFAULT; |
| 1432 |
} else { |
| 1433 |
state = SCE_H_DEFAULT; |
| 1434 |
} |
| 1435 |
} |
| 1436 |
// Allow falling through to mako handling code if newline is going to end a block |
| 1437 |
if (((ch == '\r' && chNext != '\n') || (ch == '\n')) && |
| 1438 |
(!isMako || (makoBlockType != "%"))) { |
| 1439 |
} |
| 1440 |
// Ignore everything in mako comment until the line ends |
| 1441 |
else if (isMako && makoComment) { |
| 1442 |
} |
| 1443 |
|
| 1444 |
// generic end of script processing |
| 1445 |
else if ((inScriptType == eNonHtmlScript) && (ch == '<') && (chNext == '/')) { |
| 1446 |
// Check if it's the end of the script tag (or any other HTML tag) |
| 1447 |
switch (state) { |
| 1448 |
// in these cases, you can embed HTML tags (to confirm !!!!!!!!!!!!!!!!!!!!!!) |
| 1449 |
case SCE_H_DOUBLESTRING: |
| 1450 |
case SCE_H_SINGLESTRING: |
| 1451 |
case SCE_HJ_COMMENT: |
| 1452 |
case SCE_HJ_COMMENTDOC: |
| 1453 |
//case SCE_HJ_COMMENTLINE: // removed as this is a common thing done to hide |
| 1454 |
// the end of script marker from some JS interpreters. |
| 1455 |
//case SCE_HB_COMMENTLINE: |
| 1456 |
case SCE_HBA_COMMENTLINE: |
| 1457 |
case SCE_HJ_DOUBLESTRING: |
| 1458 |
case SCE_HJ_SINGLESTRING: |
| 1459 |
case SCE_HJ_REGEX: |
| 1460 |
case SCE_HJ_TEMPLATELITERAL: |
| 1461 |
case SCE_HB_STRING: |
| 1462 |
case SCE_HBA_STRING: |
| 1463 |
case SCE_HP_STRING: |
| 1464 |
case SCE_HP_TRIPLE: |
| 1465 |
case SCE_HP_TRIPLEDOUBLE: |
| 1466 |
case SCE_HPHP_HSTRING: |
| 1467 |
case SCE_HPHP_SIMPLESTRING: |
| 1468 |
case SCE_HPHP_COMMENT: |
| 1469 |
case SCE_HPHP_COMMENTLINE: |
| 1470 |
break; |
| 1471 |
default : |
| 1472 |
// check if the closing tag is a script tag |
| 1473 |
if (const char *tag = |
| 1474 |
(state == SCE_HJ_COMMENTLINE || state == SCE_HB_COMMENTLINE || isXml) ? "script" : |
| 1475 |
state == SCE_H_COMMENT ? "comment" : nullptr) { |
| 1476 |
Sci_Position j = i + 2; |
| 1477 |
int chr; |
| 1478 |
do { |
| 1479 |
chr = static_cast<int>(*tag++); |
| 1480 |
} while (chr != 0 && chr == MakeLowerCase(styler.SafeGetCharAt(j++))); |
| 1481 |
if (chr != 0) break; |
| 1482 |
} |
| 1483 |
// closing tag of the script (it's a closing HTML tag anyway) |
| 1484 |
styler.ColourTo(i - 1, StateToPrint); |
| 1485 |
state = SCE_H_TAGUNKNOWN; |
| 1486 |
inScriptType = eHtml; |
| 1487 |
scriptLanguage = eScriptNone; |
| 1488 |
clientScript = eScriptJS; |
| 1489 |
isLanguageType = false; |
| 1490 |
i += 2; |
| 1491 |
visibleChars += 2; |
| 1492 |
tagClosing = true; |
| 1493 |
if (foldXmlAtTagOpen) { |
| 1494 |
levelCurrent--; |
| 1495 |
} |
| 1496 |
continue; |
| 1497 |
} |
| 1498 |
} |
| 1499 |
|
| 1500 |
///////////////////////////////////// |
| 1501 |
// handle the start of PHP pre-processor = Non-HTML |
| 1502 |
else if ((ch == '<') && (chNext == '?') && !IsPHPScriptState(state)) { |
| 1503 |
const InstructionTag tag = segIsScriptInstruction(allowPHP, state, styler, i + 2, isXml); |
| 1504 |
if (tag != InstructionTag::None) { |
| 1505 |
beforeLanguage = scriptLanguage; |
| 1506 |
scriptLanguage = (tag == InstructionTag::XML) ? eScriptXML : eScriptPHP; |
| 1507 |
styler.ColourTo(i - 1, StateToPrint); |
| 1508 |
beforePreProc = state; |
| 1509 |
i++; |
| 1510 |
visibleChars++; |
| 1511 |
if (tag >= InstructionTag::Echo) { |
| 1512 |
i += (tag == InstructionTag::Echo) ? 1 : 3; |
| 1513 |
} |
| 1514 |
if (scriptLanguage == eScriptXML) |
| 1515 |
styler.ColourTo(i, SCE_H_XMLSTART); |
| 1516 |
else |
| 1517 |
styler.ColourTo(i, SCE_H_QUESTION); |
| 1518 |
state = StateForScript(scriptLanguage); |
| 1519 |
if (inScriptType == eNonHtmlScript) |
| 1520 |
inScriptType = eNonHtmlScriptPreProc; |
| 1521 |
else |
| 1522 |
inScriptType = eNonHtmlPreProc; |
| 1523 |
// Fold whole script, but not if the XML first tag (all XML-like tags in this case) |
| 1524 |
if (foldHTMLPreprocessor && (scriptLanguage != eScriptXML)) { |
| 1525 |
levelCurrent++; |
| 1526 |
} |
| 1527 |
// should be better |
| 1528 |
ch = SafeGetUnsignedCharAt(styler, i); |
| 1529 |
continue; |
| 1530 |
} |
| 1531 |
} |
| 1532 |
|
| 1533 |
// handle the start Mako template Python code |
| 1534 |
else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') || |
| 1535 |
(lineStartVisibleChars == 1 && ch == '%') || |
| 1536 |
(lineStartVisibleChars == 1 && ch == '/' && chNext == '%') || |
| 1537 |
(ch == '$' && chNext == '{') || |
| 1538 |
(ch == '<' && chNext == '/' && chNext2 == '%'))) { |
| 1539 |
if (ch == '%' || ch == '/') |
| 1540 |
makoBlockType = "%"; |
| 1541 |
else if (ch == '$') |
| 1542 |
makoBlockType = "{"; |
| 1543 |
else if (chNext == '/') |
| 1544 |
makoBlockType = GetNextWord(styler, i+3); // Tag end: </%tag> |
| 1545 |
else |
| 1546 |
makoBlockType = GetNextWord(styler, i+2); // Tag: <%tag...> |
| 1547 |
styler.ColourTo(i - 1, StateToPrint); |
| 1548 |
beforePreProc = state; |
| 1549 |
if (inScriptType == eNonHtmlScript) |
| 1550 |
inScriptType = eNonHtmlScriptPreProc; |
| 1551 |
else |
| 1552 |
inScriptType = eNonHtmlPreProc; |
| 1553 |
|
| 1554 |
if (chNext == '/') { |
| 1555 |
i += 2; |
| 1556 |
visibleChars += 2; |
| 1557 |
} else if (ch != '%') { |
| 1558 |
i++; |
| 1559 |
visibleChars++; |
| 1560 |
} |
| 1561 |
state = SCE_HP_START; |
| 1562 |
scriptLanguage = eScriptPython; |
| 1563 |
styler.ColourTo(i, SCE_H_ASP); |
| 1564 |
if (ch != '%' && ch != '$' && ch != '/') { |
| 1565 |
i += makoBlockType.length(); |
| 1566 |
visibleChars += makoBlockType.length(); |
| 1567 |
if (keywordsPy.InList(makoBlockType)) |
| 1568 |
styler.ColourTo(i, SCE_HP_WORD); |
| 1569 |
else |
| 1570 |
styler.ColourTo(i, SCE_H_TAGUNKNOWN); |
| 1571 |
} |
| 1572 |
|
| 1573 |
ch = SafeGetUnsignedCharAt(styler, i); |
| 1574 |
continue; |
| 1575 |
} |
| 1576 |
|
| 1577 |
// handle the start/end of Django comment |
| 1578 |
else if (isDjango && state != SCE_H_COMMENT && (ch == '{' && chNext == '#')) { |
| 1579 |
styler.ColourTo(i - 1, StateToPrint); |
| 1580 |
beforePreProc = state; |
| 1581 |
beforeLanguage = scriptLanguage; |
| 1582 |
if (inScriptType == eNonHtmlScript) |
| 1583 |
inScriptType = eNonHtmlScriptPreProc; |
| 1584 |
else |
| 1585 |
inScriptType = eNonHtmlPreProc; |
| 1586 |
i += 1; |
| 1587 |
visibleChars += 1; |
| 1588 |
scriptLanguage = eScriptComment; |
| 1589 |
state = SCE_H_COMMENT; |
| 1590 |
styler.ColourTo(i, SCE_H_ASP); |
| 1591 |
ch = SafeGetUnsignedCharAt(styler, i); |
| 1592 |
continue; |
| 1593 |
} else if (isDjango && state == SCE_H_COMMENT && (ch == '#' && chNext == '}')) { |
| 1594 |
styler.ColourTo(i - 1, StateToPrint); |
| 1595 |
i += 1; |
| 1596 |
visibleChars += 1; |
| 1597 |
styler.ColourTo(i, SCE_H_ASP); |
| 1598 |
state = beforePreProc; |
| 1599 |
if (inScriptType == eNonHtmlScriptPreProc) |
| 1600 |
inScriptType = eNonHtmlScript; |
| 1601 |
else |
| 1602 |
inScriptType = eHtml; |
| 1603 |
scriptLanguage = beforeLanguage; |
| 1604 |
continue; |
| 1605 |
} |
| 1606 |
|
| 1607 |
// handle the start Django template code |
| 1608 |
else if (isDjango && scriptLanguage != eScriptPython && scriptLanguage != eScriptComment && (ch == '{' && (chNext == '%' || chNext == '{'))) { |
| 1609 |
if (chNext == '%') |
| 1610 |
djangoBlockType = "%"; |
| 1611 |
else |
| 1612 |
djangoBlockType = "{"; |
| 1613 |
styler.ColourTo(i - 1, StateToPrint); |
| 1614 |
beforePreProc = state; |
| 1615 |
if (inScriptType == eNonHtmlScript) |
| 1616 |
inScriptType = eNonHtmlScriptPreProc; |
| 1617 |
else |
| 1618 |
inScriptType = eNonHtmlPreProc; |
| 1619 |
|
| 1620 |
i += 1; |
| 1621 |
visibleChars += 1; |
| 1622 |
state = SCE_HP_START; |
| 1623 |
beforeLanguage = scriptLanguage; |
| 1624 |
scriptLanguage = eScriptPython; |
| 1625 |
styler.ColourTo(i, SCE_H_ASP); |
| 1626 |
|
| 1627 |
ch = SafeGetUnsignedCharAt(styler, i); |
| 1628 |
continue; |
| 1629 |
} |
| 1630 |
|
| 1631 |
// handle the start of ASP pre-processor = Non-HTML |
| 1632 |
else if ((ch == '<') && (chNext == '%') && allowASP && !isCommentASPState(state) && !isPHPStringState(state)) { |
| 1633 |
styler.ColourTo(i - 1, StateToPrint); |
| 1634 |
beforePreProc = state; |
| 1635 |
if (inScriptType == eNonHtmlScript) |
| 1636 |
inScriptType = eNonHtmlScriptPreProc; |
| 1637 |
else |
| 1638 |
inScriptType = eNonHtmlPreProc; |
| 1639 |
// fold whole script |
| 1640 |
if (foldHTMLPreprocessor) |
| 1641 |
levelCurrent++; |
| 1642 |
if (chNext2 == '@') { |
| 1643 |
i += 2; // place as if it was the second next char treated |
| 1644 |
visibleChars += 2; |
| 1645 |
state = SCE_H_ASPAT; |
| 1646 |
scriptLanguage = eScriptVBS; |
| 1647 |
} else if ((chNext2 == '-') && (styler.SafeGetCharAt(i + 3) == '-')) { |
| 1648 |
styler.ColourTo(i + 3, SCE_H_ASP); |
| 1649 |
state = SCE_H_XCCOMMENT; |
| 1650 |
scriptLanguage = eScriptVBS; |
| 1651 |
continue; |
| 1652 |
} else { |
| 1653 |
if (chNext2 == '=') { |
| 1654 |
i += 2; // place as if it was the second next char treated |
| 1655 |
visibleChars += 2; |
| 1656 |
} else { |
| 1657 |
i++; // place as if it was the next char treated |
| 1658 |
visibleChars++; |
| 1659 |
} |
| 1660 |
|
| 1661 |
state = StateForScript(aspScript); |
| 1662 |
scriptLanguage = aspScript; |
| 1663 |
} |
| 1664 |
styler.ColourTo(i, SCE_H_ASP); |
| 1665 |
// should be better |
| 1666 |
ch = SafeGetUnsignedCharAt(styler, i); |
| 1667 |
continue; |
| 1668 |
} |
| 1669 |
|
| 1670 |
///////////////////////////////////// |
| 1671 |
// handle the start of SGML language (DTD) |
| 1672 |
else if (AnyOf(scriptLanguage, eScriptNone, eScriptXML, eScriptSGMLblock) && |
| 1673 |
(chPrev == '<') && |
| 1674 |
(ch == '!') && |
| 1675 |
AnyOf(state, SCE_H_DEFAULT, SCE_H_SGML_BLOCK_DEFAULT)) { |
| 1676 |
beforePreProc = state; |
| 1677 |
styler.ColourTo(i - 2, StateToPrint); |
| 1678 |
if ((state != SCE_H_SGML_BLOCK_DEFAULT) && (chNext == '-') && (chNext2 == '-')) { |
| 1679 |
state = SCE_H_COMMENT; // wait for a pending command |
| 1680 |
styler.ColourTo(i + 2, SCE_H_COMMENT); |
| 1681 |
i += 2; // follow styling after the -- |
| 1682 |
if (!isXml) { |
| 1683 |
// handle empty comment: <!-->, <!---> |
| 1684 |
// https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment |
| 1685 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 1686 |
if ((chNext == '>') || (chNext == '-' && SafeGetUnsignedCharAt(styler, i + 2) == '>')) { |
| 1687 |
if (chNext == '-') { |
| 1688 |
i += 1; |
| 1689 |
} |
| 1690 |
chPrev = '-'; |
| 1691 |
ch = '-'; |
| 1692 |
} |
| 1693 |
} |
| 1694 |
} else if ((state != SCE_H_SGML_BLOCK_DEFAULT) && isWordCdata(i + 1, i + 7, styler)) { |
| 1695 |
state = SCE_H_CDATA; |
| 1696 |
} else { |
| 1697 |
styler.ColourTo(i, SCE_H_SGML_DEFAULT); // <! is default |
| 1698 |
beforeLanguage = scriptLanguage; |
| 1699 |
scriptLanguage = eScriptSGML; |
| 1700 |
if ((chNext == '-') && (chNext2 == '-')) { |
| 1701 |
i += 2; |
| 1702 |
state = SCE_H_SGML_COMMENT; |
| 1703 |
} else { |
| 1704 |
state = (chNext == '[') ? SCE_H_SGML_DEFAULT : SCE_H_SGML_COMMAND; // wait for a pending command |
| 1705 |
} |
| 1706 |
} |
| 1707 |
// fold whole tag (-- when closing the tag) |
| 1708 |
if (foldHTMLPreprocessor || state == SCE_H_COMMENT || state == SCE_H_CDATA) |
| 1709 |
levelCurrent++; |
| 1710 |
continue; |
| 1711 |
} |
| 1712 |
|
| 1713 |
// handle the end of Mako Python code |
| 1714 |
else if (isMako && |
| 1715 |
((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) && |
| 1716 |
(scriptLanguage != eScriptNone) && stateAllowsTermination(state) && |
| 1717 |
isMakoBlockEnd(ch, chNext, makoBlockType)) { |
| 1718 |
if (state == SCE_H_ASPAT) { |
| 1719 |
aspScript = segIsScriptingIndicator(styler, |
| 1720 |
styler.GetStartSegment(), i - 1, aspScript); |
| 1721 |
} |
| 1722 |
if (state == SCE_HP_WORD) { |
| 1723 |
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywordsPy, classifierPython, styler, prevWord, inScriptType, isMako); |
| 1724 |
} else { |
| 1725 |
styler.ColourTo(i - 1, StateToPrint); |
| 1726 |
} |
| 1727 |
if ((makoBlockType != "%") && (makoBlockType != "{") && ch != '>') { |
| 1728 |
i++; |
| 1729 |
visibleChars++; |
| 1730 |
} else if ((makoBlockType == "%") && ch == '/') { |
| 1731 |
i++; |
| 1732 |
visibleChars++; |
| 1733 |
} |
| 1734 |
if ((makoBlockType != "%") || ch == '/') { |
| 1735 |
styler.ColourTo(i, SCE_H_ASP); |
| 1736 |
} |
| 1737 |
state = beforePreProc; |
| 1738 |
if (inScriptType == eNonHtmlScriptPreProc) |
| 1739 |
inScriptType = eNonHtmlScript; |
| 1740 |
else |
| 1741 |
inScriptType = eHtml; |
| 1742 |
scriptLanguage = eScriptNone; |
| 1743 |
continue; |
| 1744 |
} |
| 1745 |
|
| 1746 |
// handle the end of Django template code |
| 1747 |
else if (isDjango && |
| 1748 |
((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) && |
| 1749 |
(scriptLanguage != eScriptNone) && stateAllowsTermination(state) && |
| 1750 |
isDjangoBlockEnd(ch, chNext, djangoBlockType)) { |
| 1751 |
if (state == SCE_H_ASPAT) { |
| 1752 |
aspScript = segIsScriptingIndicator(styler, |
| 1753 |
styler.GetStartSegment(), i - 1, aspScript); |
| 1754 |
} |
| 1755 |
if (state == SCE_HP_WORD) { |
| 1756 |
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywordsPy, classifierPython, styler, prevWord, inScriptType, isMako); |
| 1757 |
} else { |
| 1758 |
styler.ColourTo(i - 1, StateToPrint); |
| 1759 |
} |
| 1760 |
i += 1; |
| 1761 |
visibleChars += 1; |
| 1762 |
styler.ColourTo(i, SCE_H_ASP); |
| 1763 |
state = beforePreProc; |
| 1764 |
if (inScriptType == eNonHtmlScriptPreProc) |
| 1765 |
inScriptType = eNonHtmlScript; |
| 1766 |
else |
| 1767 |
inScriptType = eHtml; |
| 1768 |
scriptLanguage = beforeLanguage; |
| 1769 |
continue; |
| 1770 |
} |
| 1771 |
|
| 1772 |
// handle the end of a pre-processor = Non-HTML |
| 1773 |
else if ((!isMako && !isDjango && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) && |
| 1774 |
(((scriptLanguage != eScriptNone) && stateAllowsTermination(state))) && |
| 1775 |
((chNext == '>') && isPreProcessorEndTag(state, ch))) || |
| 1776 |
((scriptLanguage == eScriptSGML) && (ch == '>') && !AnyOf(state, SCE_H_SGML_COMMENT, SCE_H_SGML_DOUBLESTRING, SCE_H_SGML_SIMPLESTRING))) { |
| 1777 |
if (state == SCE_H_ASPAT) { |
| 1778 |
aspScript = segIsScriptingIndicator(styler, |
| 1779 |
styler.GetStartSegment(), i - 1, aspScript); |
| 1780 |
} |
| 1781 |
// Bounce out of any ASP mode |
| 1782 |
switch (state) { |
| 1783 |
case SCE_HJ_WORD: |
| 1784 |
classifyWordHTJS(styler.GetStartSegment(), i - 1, keywordsJS, classifierJavaScript, classifierJavaScriptServer, styler, inScriptType); |
| 1785 |
break; |
| 1786 |
case SCE_HB_WORD: |
| 1787 |
classifyWordHTVB(styler.GetStartSegment(), i - 1, keywordsVB, classifierBasic, styler, inScriptType); |
| 1788 |
break; |
| 1789 |
case SCE_HP_WORD: |
| 1790 |
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywordsPy, classifierPython, styler, prevWord, inScriptType, isMako); |
| 1791 |
break; |
| 1792 |
case SCE_HPHP_WORD: |
| 1793 |
classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywordsPHP, classifierPHP, styler); |
| 1794 |
break; |
| 1795 |
case SCE_H_XCCOMMENT: |
| 1796 |
styler.ColourTo(i - 1, state); |
| 1797 |
break; |
| 1798 |
default : |
| 1799 |
styler.ColourTo(i - 1, StateToPrint); |
| 1800 |
break; |
| 1801 |
} |
| 1802 |
if (scriptLanguage != eScriptSGML) { |
| 1803 |
i++; |
| 1804 |
visibleChars++; |
| 1805 |
} |
| 1806 |
if (ch == '%') |
| 1807 |
styler.ColourTo(i, SCE_H_ASP); |
| 1808 |
else if (scriptLanguage == eScriptXML) |
| 1809 |
styler.ColourTo(i, SCE_H_XMLEND); |
| 1810 |
else if (scriptLanguage == eScriptSGML) |
| 1811 |
styler.ColourTo(i, SCE_H_SGML_DEFAULT); |
| 1812 |
else |
| 1813 |
styler.ColourTo(i, SCE_H_QUESTION); |
| 1814 |
state = beforePreProc; |
| 1815 |
if (inScriptType == eNonHtmlScriptPreProc) |
| 1816 |
inScriptType = eNonHtmlScript; |
| 1817 |
else |
| 1818 |
inScriptType = eHtml; |
| 1819 |
// Unfold all scripting languages, except for XML tag |
| 1820 |
if (foldHTMLPreprocessor && (scriptLanguage != eScriptXML)) { |
| 1821 |
levelCurrent--; |
| 1822 |
} |
| 1823 |
scriptLanguage = beforeLanguage; |
| 1824 |
continue; |
| 1825 |
} |
| 1826 |
///////////////////////////////////// |
| 1827 |
|
| 1828 |
switch (state) { |
| 1829 |
case SCE_H_DEFAULT: |
| 1830 |
if (ch == '<') { |
| 1831 |
// in HTML, fold on tag open and unfold on tag close |
| 1832 |
tagOpened = true; |
| 1833 |
tagClosing = (chNext == '/'); |
| 1834 |
if (foldXmlAtTagOpen && !AnyOf(chNext, '/', '?', '!', '-', '%')) { |
| 1835 |
levelCurrent++; |
| 1836 |
} |
| 1837 |
if (foldXmlAtTagOpen && chNext == '/') { |
| 1838 |
levelCurrent--; |
| 1839 |
} |
| 1840 |
styler.ColourTo(i - 1, StateToPrint); |
| 1841 |
if (chNext != '!') |
| 1842 |
state = SCE_H_TAGUNKNOWN; |
| 1843 |
} else if (ch == '&') { |
| 1844 |
styler.ColourTo(i - 1, SCE_H_DEFAULT); |
| 1845 |
state = SCE_H_ENTITY; |
| 1846 |
} |
| 1847 |
break; |
| 1848 |
case SCE_H_SGML_DEFAULT: |
| 1849 |
case SCE_H_SGML_BLOCK_DEFAULT: |
| 1850 |
// if (scriptLanguage == eScriptSGMLblock) |
| 1851 |
// StateToPrint = SCE_H_SGML_BLOCK_DEFAULT; |
| 1852 |
|
| 1853 |
if (ch == '\"') { |
| 1854 |
styler.ColourTo(i - 1, StateToPrint); |
| 1855 |
state = SCE_H_SGML_DOUBLESTRING; |
| 1856 |
} else if (ch == '\'') { |
| 1857 |
styler.ColourTo(i - 1, StateToPrint); |
| 1858 |
state = SCE_H_SGML_SIMPLESTRING; |
| 1859 |
} else if ((ch == '-') && (chPrev == '-')) { |
| 1860 |
if (static_cast<Sci_Position>(styler.GetStartSegment()) <= (i - 2)) { |
| 1861 |
styler.ColourTo(i - 2, StateToPrint); |
| 1862 |
} |
| 1863 |
state = SCE_H_SGML_COMMENT; |
| 1864 |
} else if (ch == '%' && IsUpperOrLowerCase(chNext)) { |
| 1865 |
styler.ColourTo(i - 1, StateToPrint); |
| 1866 |
state = SCE_H_SGML_ENTITY; |
| 1867 |
} else if (ch == '#') { |
| 1868 |
styler.ColourTo(i - 1, StateToPrint); |
| 1869 |
state = SCE_H_SGML_SPECIAL; |
| 1870 |
} else if (ch == '[') { |
| 1871 |
styler.ColourTo(i - 1, StateToPrint); |
| 1872 |
styler.ColourTo(i, SCE_H_SGML_DEFAULT); |
| 1873 |
++sgmlBlockLevel; |
| 1874 |
scriptLanguage = eScriptSGMLblock; |
| 1875 |
state = SCE_H_SGML_BLOCK_DEFAULT; |
| 1876 |
} else if (ch == ']') { |
| 1877 |
if (sgmlBlockLevel > 0) { |
| 1878 |
--sgmlBlockLevel; |
| 1879 |
if (sgmlBlockLevel == 0) { |
| 1880 |
beforePreProc = SCE_H_DEFAULT; |
| 1881 |
} |
| 1882 |
styler.ColourTo(i - 1, StateToPrint); |
| 1883 |
styler.ColourTo(i, SCE_H_SGML_DEFAULT); |
| 1884 |
scriptLanguage = eScriptSGML; |
| 1885 |
} else { |
| 1886 |
styler.ColourTo(i - 1, StateToPrint); |
| 1887 |
styler.ColourTo(i, SCE_H_SGML_ERROR); |
| 1888 |
} |
| 1889 |
state = SCE_H_SGML_DEFAULT; |
| 1890 |
} |
| 1891 |
break; |
| 1892 |
case SCE_H_SGML_COMMAND: |
| 1893 |
if (!issgmlwordchar(ch)) { |
| 1894 |
if (isWordHSGML(styler.GetStartSegment(), i - 1, keywordsSGML, styler)) { |
| 1895 |
styler.ColourTo(i - 1, StateToPrint); |
| 1896 |
state = SCE_H_SGML_1ST_PARAM; |
| 1897 |
} else { |
| 1898 |
state = SCE_H_SGML_ERROR; |
| 1899 |
} |
| 1900 |
} |
| 1901 |
break; |
| 1902 |
case SCE_H_SGML_1ST_PARAM: |
| 1903 |
// wait for the beginning of the word |
| 1904 |
if ((ch == '-') && (chPrev == '-')) { |
| 1905 |
styler.ColourTo(i - 2, SCE_H_SGML_DEFAULT); |
| 1906 |
state = SCE_H_SGML_1ST_PARAM_COMMENT; |
| 1907 |
} else if (issgmlwordchar(ch)) { |
| 1908 |
styler.ColourTo(i - 1, SCE_H_SGML_DEFAULT); |
| 1909 |
// find the length of the word |
| 1910 |
Sci_Position size = 1; |
| 1911 |
while (setHTMLWord.Contains(SafeGetUnsignedCharAt(styler, i + size))) |
| 1912 |
size++; |
| 1913 |
styler.ColourTo(i + size - 1, StateToPrint); |
| 1914 |
i += size - 1; |
| 1915 |
visibleChars += size - 1; |
| 1916 |
ch = SafeGetUnsignedCharAt(styler, i); |
| 1917 |
state = SCE_H_SGML_DEFAULT; |
| 1918 |
continue; |
| 1919 |
} |
| 1920 |
break; |
| 1921 |
case SCE_H_SGML_ERROR: |
| 1922 |
if ((ch == '-') && (chPrev == '-')) { |
| 1923 |
styler.ColourTo(i - 2, StateToPrint); |
| 1924 |
state = SCE_H_SGML_COMMENT; |
| 1925 |
} |
| 1926 |
break; |
| 1927 |
case SCE_H_SGML_DOUBLESTRING: |
| 1928 |
if (ch == '\"') { |
| 1929 |
styler.ColourTo(i, StateToPrint); |
| 1930 |
state = SCE_H_SGML_DEFAULT; |
| 1931 |
} |
| 1932 |
break; |
| 1933 |
case SCE_H_SGML_SIMPLESTRING: |
| 1934 |
if (ch == '\'') { |
| 1935 |
styler.ColourTo(i, StateToPrint); |
| 1936 |
state = SCE_H_SGML_DEFAULT; |
| 1937 |
} |
| 1938 |
break; |
| 1939 |
case SCE_H_SGML_COMMENT: |
| 1940 |
if ((ch == '-') && (chPrev == '-')) { |
| 1941 |
styler.ColourTo(i, StateToPrint); |
| 1942 |
state = SCE_H_SGML_DEFAULT; |
| 1943 |
} |
| 1944 |
break; |
| 1945 |
case SCE_H_CDATA: |
| 1946 |
if ((chPrev2 == ']') && (chPrev == ']') && (ch == '>')) { |
| 1947 |
styler.ColourTo(i, StateToPrint); |
| 1948 |
state = SCE_H_DEFAULT; |
| 1949 |
levelCurrent--; |
| 1950 |
} |
| 1951 |
break; |
| 1952 |
case SCE_H_COMMENT: |
| 1953 |
if ((scriptLanguage != eScriptComment) && (chPrev2 == '-') && (chPrev == '-') && (ch == '>' || (!isXml && ch == '!' && chNext == '>'))) { |
| 1954 |
// close HTML comment with --!> |
| 1955 |
// https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment |
| 1956 |
if (ch == '!') { |
| 1957 |
i += 1; |
| 1958 |
} |
| 1959 |
styler.ColourTo(i, StateToPrint); |
| 1960 |
state = SCE_H_DEFAULT; |
| 1961 |
levelCurrent--; |
| 1962 |
} |
| 1963 |
break; |
| 1964 |
case SCE_H_SGML_1ST_PARAM_COMMENT: |
| 1965 |
if ((ch == '-') && (chPrev == '-')) { |
| 1966 |
styler.ColourTo(i, SCE_H_SGML_COMMENT); |
| 1967 |
state = SCE_H_SGML_1ST_PARAM; |
| 1968 |
} |
| 1969 |
break; |
| 1970 |
case SCE_H_SGML_SPECIAL: |
| 1971 |
if (!IsUpperCase(ch)) { |
| 1972 |
styler.ColourTo(i - 1, StateToPrint); |
| 1973 |
if (IsAlphaNumeric(ch)) { |
| 1974 |
state = SCE_H_SGML_ERROR; |
| 1975 |
} else { |
| 1976 |
state = SCE_H_SGML_DEFAULT; |
| 1977 |
} |
| 1978 |
} |
| 1979 |
break; |
| 1980 |
case SCE_H_SGML_ENTITY: |
| 1981 |
if (!(IsAlphaNumeric(ch)) && ch != '-' && ch != '.' && ch != '_') { |
| 1982 |
styler.ColourTo(i, ((ch == ';') ? StateToPrint : SCE_H_SGML_ERROR)); |
| 1983 |
state = defaultStateForSGML(scriptLanguage); |
| 1984 |
} |
| 1985 |
break; |
| 1986 |
case SCE_H_ENTITY: |
| 1987 |
if (ch == ';') { |
| 1988 |
styler.ColourTo(i, StateToPrint); |
| 1989 |
state = SCE_H_DEFAULT; |
| 1990 |
} else if (!setEntity.Contains(ch)) { |
| 1991 |
styler.ColourTo(i-1, SCE_H_TAGUNKNOWN); |
| 1992 |
state = SCE_H_DEFAULT; |
| 1993 |
if (!isLineEnd(ch)) { |
| 1994 |
// Retreat one byte so the character that is invalid inside entity |
| 1995 |
// may start something else like a tag. |
| 1996 |
--i; |
| 1997 |
continue; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
break; |
| 2001 |
case SCE_H_TAGUNKNOWN: |
| 2002 |
if (!setTagContinue.Contains(ch) && !((ch == '/') && (chPrev == '<'))) { |
| 2003 |
int eClass = classifyTagHTML(styler.GetStartSegment(), |
| 2004 |
i - 1, keywordsHTML, classifierTags, styler, tagDontFold, caseSensitive, isXml, allowScripts, nonFoldingTags, lastTag); |
| 2005 |
if (eClass == SCE_H_SCRIPT || eClass == SCE_H_COMMENT) { |
| 2006 |
if (!tagClosing) { |
| 2007 |
inScriptType = eNonHtmlScript; |
| 2008 |
scriptLanguage = eClass == SCE_H_SCRIPT ? clientScript : eScriptComment; |
| 2009 |
} else { |
| 2010 |
scriptLanguage = eScriptNone; |
| 2011 |
} |
| 2012 |
isLanguageType = false; |
| 2013 |
eClass = SCE_H_TAG; |
| 2014 |
} |
| 2015 |
if (ch == '>') { |
| 2016 |
styler.ColourTo(i, eClass); |
| 2017 |
if (inScriptType == eNonHtmlScript) { |
| 2018 |
state = StateForScript(scriptLanguage); |
| 2019 |
} else { |
| 2020 |
state = SCE_H_DEFAULT; |
| 2021 |
} |
| 2022 |
tagOpened = false; |
| 2023 |
if (!(foldXmlAtTagOpen || tagDontFold)) { |
| 2024 |
if (tagClosing) { |
| 2025 |
levelCurrent--; |
| 2026 |
} else { |
| 2027 |
levelCurrent++; |
| 2028 |
} |
| 2029 |
} |
| 2030 |
tagClosing = false; |
| 2031 |
} else if (ch == '/' && chNext == '>') { |
| 2032 |
if (eClass == SCE_H_TAGUNKNOWN) { |
| 2033 |
styler.ColourTo(i + 1, SCE_H_TAGUNKNOWN); |
| 2034 |
} else { |
| 2035 |
styler.ColourTo(i - 1, StateToPrint); |
| 2036 |
styler.ColourTo(i + 1, SCE_H_TAGEND); |
| 2037 |
} |
| 2038 |
i++; |
| 2039 |
ch = chNext; |
| 2040 |
state = SCE_H_DEFAULT; |
| 2041 |
tagOpened = false; |
| 2042 |
if (foldXmlAtTagOpen) { |
| 2043 |
levelCurrent--; |
| 2044 |
} |
| 2045 |
} else { |
| 2046 |
if (eClass != SCE_H_TAGUNKNOWN) { |
| 2047 |
if (eClass == SCE_H_SGML_DEFAULT) { |
| 2048 |
state = SCE_H_SGML_DEFAULT; |
| 2049 |
} else { |
| 2050 |
state = SCE_H_OTHER; |
| 2051 |
} |
| 2052 |
} |
| 2053 |
} |
| 2054 |
} |
| 2055 |
break; |
| 2056 |
case SCE_H_ATTRIBUTE: |
| 2057 |
if (!setAttributeContinue.Contains(ch)) { |
| 2058 |
isLanguageType = classifyAttribHTML(inScriptType, styler.GetStartSegment(), i - 1, keywordsHTML, classifierAttributes, styler, lastTag); |
| 2059 |
if (ch == '>') { |
| 2060 |
styler.ColourTo(i, SCE_H_TAG); |
| 2061 |
if (inScriptType == eNonHtmlScript) { |
| 2062 |
state = StateForScript(scriptLanguage); |
| 2063 |
} else { |
| 2064 |
state = SCE_H_DEFAULT; |
| 2065 |
} |
| 2066 |
tagOpened = false; |
| 2067 |
if (!(foldXmlAtTagOpen || tagDontFold)) { |
| 2068 |
if (tagClosing) { |
| 2069 |
levelCurrent--; |
| 2070 |
} else { |
| 2071 |
levelCurrent++; |
| 2072 |
} |
| 2073 |
} |
| 2074 |
tagClosing = false; |
| 2075 |
} else if (ch == '=') { |
| 2076 |
styler.ColourTo(i, SCE_H_OTHER); |
| 2077 |
state = SCE_H_VALUE; |
| 2078 |
} else { |
| 2079 |
state = SCE_H_OTHER; |
| 2080 |
} |
| 2081 |
} |
| 2082 |
break; |
| 2083 |
case SCE_H_OTHER: |
| 2084 |
if (ch == '>') { |
| 2085 |
styler.ColourTo(i - 1, StateToPrint); |
| 2086 |
styler.ColourTo(i, SCE_H_TAG); |
| 2087 |
if (inScriptType == eNonHtmlScript) { |
| 2088 |
state = StateForScript(scriptLanguage); |
| 2089 |
} else { |
| 2090 |
state = SCE_H_DEFAULT; |
| 2091 |
} |
| 2092 |
tagOpened = false; |
| 2093 |
if (!(foldXmlAtTagOpen || tagDontFold)) { |
| 2094 |
if (tagClosing) { |
| 2095 |
levelCurrent--; |
| 2096 |
} else { |
| 2097 |
levelCurrent++; |
| 2098 |
} |
| 2099 |
} |
| 2100 |
tagClosing = false; |
| 2101 |
} else if (ch == '\"') { |
| 2102 |
styler.ColourTo(i - 1, StateToPrint); |
| 2103 |
state = SCE_H_DOUBLESTRING; |
| 2104 |
} else if (ch == '\'') { |
| 2105 |
styler.ColourTo(i - 1, StateToPrint); |
| 2106 |
state = SCE_H_SINGLESTRING; |
| 2107 |
} else if (ch == '=') { |
| 2108 |
styler.ColourTo(i, StateToPrint); |
| 2109 |
state = SCE_H_VALUE; |
| 2110 |
} else if (ch == '/' && chNext == '>') { |
| 2111 |
styler.ColourTo(i - 1, StateToPrint); |
| 2112 |
styler.ColourTo(i + 1, SCE_H_TAGEND); |
| 2113 |
i++; |
| 2114 |
ch = chNext; |
| 2115 |
state = SCE_H_DEFAULT; |
| 2116 |
tagOpened = false; |
| 2117 |
if (foldXmlAtTagOpen) { |
| 2118 |
levelCurrent--; |
| 2119 |
} |
| 2120 |
} else if (ch == '?' && chNext == '>') { |
| 2121 |
styler.ColourTo(i - 1, StateToPrint); |
| 2122 |
styler.ColourTo(i + 1, SCE_H_XMLEND); |
| 2123 |
i++; |
| 2124 |
ch = chNext; |
| 2125 |
state = SCE_H_DEFAULT; |
| 2126 |
} else if (setHTMLWord.Contains(ch)) { |
| 2127 |
styler.ColourTo(i - 1, StateToPrint); |
| 2128 |
state = SCE_H_ATTRIBUTE; |
| 2129 |
} |
| 2130 |
break; |
| 2131 |
case SCE_H_DOUBLESTRING: |
| 2132 |
if (ch == '\"') { |
| 2133 |
if (isLanguageType) { |
| 2134 |
scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage); |
| 2135 |
clientScript = scriptLanguage; |
| 2136 |
isLanguageType = false; |
| 2137 |
} |
| 2138 |
styler.ColourTo(i, SCE_H_DOUBLESTRING); |
| 2139 |
state = SCE_H_OTHER; |
| 2140 |
} |
| 2141 |
break; |
| 2142 |
case SCE_H_SINGLESTRING: |
| 2143 |
if (ch == '\'') { |
| 2144 |
if (isLanguageType) { |
| 2145 |
scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage); |
| 2146 |
clientScript = scriptLanguage; |
| 2147 |
isLanguageType = false; |
| 2148 |
} |
| 2149 |
styler.ColourTo(i, SCE_H_SINGLESTRING); |
| 2150 |
state = SCE_H_OTHER; |
| 2151 |
} |
| 2152 |
break; |
| 2153 |
case SCE_H_VALUE: |
| 2154 |
if (!setHTMLWord.Contains(ch)) { |
| 2155 |
if (ch == '\"' && chPrev == '=') { |
| 2156 |
// Should really test for being first character |
| 2157 |
state = SCE_H_DOUBLESTRING; |
| 2158 |
} else if (ch == '\'' && chPrev == '=') { |
| 2159 |
state = SCE_H_SINGLESTRING; |
| 2160 |
} else { |
| 2161 |
if (IsNumberChar(styler[styler.GetStartSegment()])) { |
| 2162 |
styler.ColourTo(i - 1, SCE_H_NUMBER); |
| 2163 |
} else { |
| 2164 |
styler.ColourTo(i - 1, StateToPrint); |
| 2165 |
} |
| 2166 |
if (ch == '>') { |
| 2167 |
styler.ColourTo(i, SCE_H_TAG); |
| 2168 |
if (inScriptType == eNonHtmlScript) { |
| 2169 |
state = StateForScript(scriptLanguage); |
| 2170 |
} else { |
| 2171 |
state = SCE_H_DEFAULT; |
| 2172 |
} |
| 2173 |
tagOpened = false; |
| 2174 |
if (!tagDontFold) { |
| 2175 |
if (tagClosing) { |
| 2176 |
levelCurrent--; |
| 2177 |
} else { |
| 2178 |
levelCurrent++; |
| 2179 |
} |
| 2180 |
} |
| 2181 |
tagClosing = false; |
| 2182 |
} else { |
| 2183 |
state = SCE_H_OTHER; |
| 2184 |
} |
| 2185 |
} |
| 2186 |
} |
| 2187 |
break; |
| 2188 |
case SCE_HJ_DEFAULT: |
| 2189 |
case SCE_HJ_START: |
| 2190 |
case SCE_HJ_SYMBOLS: |
| 2191 |
if (IsAWordStart(ch)) { |
| 2192 |
styler.ColourTo(i - 1, StateToPrint); |
| 2193 |
state = SCE_HJ_WORD; |
| 2194 |
} else if (ch == '/' && chNext == '*') { |
| 2195 |
styler.ColourTo(i - 1, StateToPrint); |
| 2196 |
i++; |
| 2197 |
if (chNext2 == '*') |
| 2198 |
state = SCE_HJ_COMMENTDOC; |
| 2199 |
else |
| 2200 |
state = SCE_HJ_COMMENT; |
| 2201 |
} else if (ch == '/' && chNext == '/') { |
| 2202 |
styler.ColourTo(i - 1, StateToPrint); |
| 2203 |
state = SCE_HJ_COMMENTLINE; |
| 2204 |
} else if (ch == '/' && setOKBeforeJSRE.Contains(chPrevNonWhite)) { |
| 2205 |
styler.ColourTo(i - 1, StateToPrint); |
| 2206 |
state = SCE_HJ_REGEX; |
| 2207 |
} else if (ch == '\"') { |
| 2208 |
styler.ColourTo(i - 1, StateToPrint); |
| 2209 |
state = SCE_HJ_DOUBLESTRING; |
| 2210 |
} else if (ch == '\'') { |
| 2211 |
styler.ColourTo(i - 1, StateToPrint); |
| 2212 |
state = SCE_HJ_SINGLESTRING; |
| 2213 |
} else if (ch == '`') { |
| 2214 |
styler.ColourTo(i - 1, StateToPrint); |
| 2215 |
state = SCE_HJ_TEMPLATELITERAL; |
| 2216 |
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') && |
| 2217 |
styler.SafeGetCharAt(i + 3) == '-') { |
| 2218 |
styler.ColourTo(i - 1, StateToPrint); |
| 2219 |
state = SCE_HJ_COMMENTLINE; |
| 2220 |
} else if ((ch == '-') && (chNext == '-') && (chNext2 == '>')) { |
| 2221 |
styler.ColourTo(i - 1, StateToPrint); |
| 2222 |
state = SCE_HJ_COMMENTLINE; |
| 2223 |
i += 2; |
| 2224 |
} else if (IsOperator(ch)) { |
| 2225 |
styler.ColourTo(i - 1, StateToPrint); |
| 2226 |
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType)); |
| 2227 |
state = SCE_HJ_DEFAULT; |
| 2228 |
} else if ((ch == ' ') || (ch == '\t')) { |
| 2229 |
if (state == SCE_HJ_START) { |
| 2230 |
styler.ColourTo(i - 1, StateToPrint); |
| 2231 |
state = SCE_HJ_DEFAULT; |
| 2232 |
} |
| 2233 |
} |
| 2234 |
break; |
| 2235 |
case SCE_HJ_WORD: |
| 2236 |
if (!IsAWordChar(ch)) { |
| 2237 |
classifyWordHTJS(styler.GetStartSegment(), i - 1, keywordsJS, |
| 2238 |
classifierJavaScript, classifierJavaScriptServer, styler, inScriptType); |
| 2239 |
//styler.ColourTo(i - 1, eHTJSKeyword); |
| 2240 |
state = SCE_HJ_DEFAULT; |
| 2241 |
if (ch == '/' && chNext == '*') { |
| 2242 |
i++; |
| 2243 |
if (chNext2 == '*') |
| 2244 |
state = SCE_HJ_COMMENTDOC; |
| 2245 |
else |
| 2246 |
state = SCE_HJ_COMMENT; |
| 2247 |
} else if (ch == '/' && chNext == '/') { |
| 2248 |
state = SCE_HJ_COMMENTLINE; |
| 2249 |
} else if (ch == '\"') { |
| 2250 |
state = SCE_HJ_DOUBLESTRING; |
| 2251 |
} else if (ch == '\'') { |
| 2252 |
state = SCE_HJ_SINGLESTRING; |
| 2253 |
} else if (ch == '`') { |
| 2254 |
state = SCE_HJ_TEMPLATELITERAL; |
| 2255 |
} else if ((ch == '-') && (chNext == '-') && (chNext2 == '>')) { |
| 2256 |
styler.ColourTo(i - 1, StateToPrint); |
| 2257 |
state = SCE_HJ_COMMENTLINE; |
| 2258 |
i += 2; |
| 2259 |
} else if (IsOperator(ch)) { |
| 2260 |
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType)); |
| 2261 |
state = SCE_HJ_DEFAULT; |
| 2262 |
} |
| 2263 |
} |
| 2264 |
break; |
| 2265 |
case SCE_HJ_COMMENT: |
| 2266 |
case SCE_HJ_COMMENTDOC: |
| 2267 |
if (ch == '/' && chPrev == '*') { |
| 2268 |
styler.ColourTo(i, StateToPrint); |
| 2269 |
state = SCE_HJ_DEFAULT; |
| 2270 |
ch = ' '; |
| 2271 |
} |
| 2272 |
break; |
| 2273 |
case SCE_HJ_COMMENTLINE: |
| 2274 |
if (ch == '\r' || ch == '\n') { |
| 2275 |
styler.ColourTo(i - 1, statePrintForState(SCE_HJ_COMMENTLINE, inScriptType)); |
| 2276 |
state = SCE_HJ_DEFAULT; |
| 2277 |
ch = ' '; |
| 2278 |
} |
| 2279 |
break; |
| 2280 |
case SCE_HJ_DOUBLESTRING: |
| 2281 |
if (ch == '\\') { |
| 2282 |
if (chNext == '\"' || chNext == '\'' || chNext == '\\') { |
| 2283 |
i++; |
| 2284 |
} |
| 2285 |
} else if (ch == '\"') { |
| 2286 |
styler.ColourTo(i, statePrintForState(SCE_HJ_DOUBLESTRING, inScriptType)); |
| 2287 |
state = SCE_HJ_DEFAULT; |
| 2288 |
} else if (isLineEnd(ch)) { |
| 2289 |
styler.ColourTo(i - 1, StateToPrint); |
| 2290 |
if (chPrev != '\\' && (chPrev2 != '\\' || chPrev != '\r' || ch != '\n')) { |
| 2291 |
state = SCE_HJ_STRINGEOL; |
| 2292 |
} |
| 2293 |
} |
| 2294 |
break; |
| 2295 |
case SCE_HJ_SINGLESTRING: |
| 2296 |
if (ch == '\\') { |
| 2297 |
if (chNext == '\"' || chNext == '\'' || chNext == '\\') { |
| 2298 |
i++; |
| 2299 |
} |
| 2300 |
} else if (ch == '\'') { |
| 2301 |
styler.ColourTo(i, statePrintForState(SCE_HJ_SINGLESTRING, inScriptType)); |
| 2302 |
state = SCE_HJ_DEFAULT; |
| 2303 |
} else if (isLineEnd(ch)) { |
| 2304 |
styler.ColourTo(i - 1, StateToPrint); |
| 2305 |
if (chPrev != '\\' && (chPrev2 != '\\' || chPrev != '\r' || ch != '\n')) { |
| 2306 |
state = SCE_HJ_STRINGEOL; |
| 2307 |
} |
| 2308 |
} |
| 2309 |
break; |
| 2310 |
case SCE_HJ_TEMPLATELITERAL: |
| 2311 |
if (ch == '\\') { |
| 2312 |
if (chNext == '$' || chNext == '`' || chNext == '\\') { |
| 2313 |
i++; |
| 2314 |
} |
| 2315 |
} else if (ch == '`') { |
| 2316 |
styler.ColourTo(i, statePrintForState(SCE_HJ_TEMPLATELITERAL, inScriptType)); |
| 2317 |
state = SCE_HJ_DEFAULT; |
| 2318 |
} |
| 2319 |
break; |
| 2320 |
case SCE_HJ_STRINGEOL: |
| 2321 |
if (!isLineEnd(ch)) { |
| 2322 |
styler.ColourTo(i - 1, StateToPrint); |
| 2323 |
state = SCE_HJ_DEFAULT; |
| 2324 |
} else if (!isLineEnd(chNext)) { |
| 2325 |
styler.ColourTo(i, StateToPrint); |
| 2326 |
state = SCE_HJ_DEFAULT; |
| 2327 |
} |
| 2328 |
break; |
| 2329 |
case SCE_HJ_REGEX: |
| 2330 |
if (ch == '\r' || ch == '\n' || ch == '/') { |
| 2331 |
if (ch == '/') { |
| 2332 |
while (IsLowerCase(chNext)) { // gobble regex flags |
| 2333 |
i++; |
| 2334 |
ch = chNext; |
| 2335 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2336 |
} |
| 2337 |
} |
| 2338 |
styler.ColourTo(i, StateToPrint); |
| 2339 |
state = SCE_HJ_DEFAULT; |
| 2340 |
continue; |
| 2341 |
} else if (ch == '\\') { |
| 2342 |
// Gobble up the quoted character |
| 2343 |
if (chNext == '\\' || chNext == '/') { |
| 2344 |
i++; |
| 2345 |
ch = chNext; |
| 2346 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2347 |
} |
| 2348 |
} |
| 2349 |
break; |
| 2350 |
case SCE_HB_DEFAULT: |
| 2351 |
case SCE_HB_START: |
| 2352 |
if (IsAWordStart(ch)) { |
| 2353 |
styler.ColourTo(i - 1, StateToPrint); |
| 2354 |
state = SCE_HB_WORD; |
| 2355 |
} else if (ch == '\'') { |
| 2356 |
styler.ColourTo(i - 1, StateToPrint); |
| 2357 |
state = SCE_HB_COMMENTLINE; |
| 2358 |
} else if (ch == '\"') { |
| 2359 |
styler.ColourTo(i - 1, StateToPrint); |
| 2360 |
state = SCE_HB_STRING; |
| 2361 |
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') && |
| 2362 |
styler.SafeGetCharAt(i + 3) == '-') { |
| 2363 |
styler.ColourTo(i - 1, StateToPrint); |
| 2364 |
state = SCE_HB_COMMENTLINE; |
| 2365 |
} else if (IsOperator(ch)) { |
| 2366 |
styler.ColourTo(i - 1, StateToPrint); |
| 2367 |
styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType)); |
| 2368 |
state = SCE_HB_DEFAULT; |
| 2369 |
} else if ((ch == ' ') || (ch == '\t')) { |
| 2370 |
if (state == SCE_HB_START) { |
| 2371 |
styler.ColourTo(i - 1, StateToPrint); |
| 2372 |
state = SCE_HB_DEFAULT; |
| 2373 |
} |
| 2374 |
} |
| 2375 |
break; |
| 2376 |
case SCE_HB_WORD: |
| 2377 |
if (!IsAWordChar(ch)) { |
| 2378 |
state = classifyWordHTVB(styler.GetStartSegment(), i - 1, keywordsVB, classifierBasic, styler, inScriptType); |
| 2379 |
if (state == SCE_HB_DEFAULT) { |
| 2380 |
if (ch == '\"') { |
| 2381 |
state = SCE_HB_STRING; |
| 2382 |
} else if (ch == '\'') { |
| 2383 |
state = SCE_HB_COMMENTLINE; |
| 2384 |
} else if (IsOperator(ch)) { |
| 2385 |
styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType)); |
| 2386 |
state = SCE_HB_DEFAULT; |
| 2387 |
} |
| 2388 |
} |
| 2389 |
} |
| 2390 |
break; |
| 2391 |
case SCE_HB_STRING: |
| 2392 |
if (ch == '\"') { |
| 2393 |
styler.ColourTo(i, StateToPrint); |
| 2394 |
state = SCE_HB_DEFAULT; |
| 2395 |
} else if (ch == '\r' || ch == '\n') { |
| 2396 |
styler.ColourTo(i - 1, StateToPrint); |
| 2397 |
state = SCE_HB_STRINGEOL; |
| 2398 |
} |
| 2399 |
break; |
| 2400 |
case SCE_HB_COMMENTLINE: |
| 2401 |
if (ch == '\r' || ch == '\n') { |
| 2402 |
styler.ColourTo(i - 1, StateToPrint); |
| 2403 |
state = SCE_HB_DEFAULT; |
| 2404 |
} |
| 2405 |
break; |
| 2406 |
case SCE_HB_STRINGEOL: |
| 2407 |
if (!isLineEnd(ch)) { |
| 2408 |
styler.ColourTo(i - 1, StateToPrint); |
| 2409 |
state = SCE_HB_DEFAULT; |
| 2410 |
} else if (!isLineEnd(chNext)) { |
| 2411 |
styler.ColourTo(i, StateToPrint); |
| 2412 |
state = SCE_HB_DEFAULT; |
| 2413 |
} |
| 2414 |
break; |
| 2415 |
case SCE_HP_DEFAULT: |
| 2416 |
case SCE_HP_START: |
| 2417 |
if (IsAWordStart(ch)) { |
| 2418 |
styler.ColourTo(i - 1, StateToPrint); |
| 2419 |
state = SCE_HP_WORD; |
| 2420 |
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') && |
| 2421 |
styler.SafeGetCharAt(i + 3) == '-') { |
| 2422 |
styler.ColourTo(i - 1, StateToPrint); |
| 2423 |
state = SCE_HP_COMMENTLINE; |
| 2424 |
} else if (ch == '#') { |
| 2425 |
styler.ColourTo(i - 1, StateToPrint); |
| 2426 |
state = SCE_HP_COMMENTLINE; |
| 2427 |
} else if (ch == '\"') { |
| 2428 |
styler.ColourTo(i - 1, StateToPrint); |
| 2429 |
if (chNext == '\"' && chNext2 == '\"') { |
| 2430 |
i += 2; |
| 2431 |
state = SCE_HP_TRIPLEDOUBLE; |
| 2432 |
ch = ' '; |
| 2433 |
chPrev = ' '; |
| 2434 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2435 |
} else { |
| 2436 |
// state = statePrintForState(SCE_HP_STRING,inScriptType); |
| 2437 |
state = SCE_HP_STRING; |
| 2438 |
} |
| 2439 |
} else if (ch == '\'') { |
| 2440 |
styler.ColourTo(i - 1, StateToPrint); |
| 2441 |
if (chNext == '\'' && chNext2 == '\'') { |
| 2442 |
i += 2; |
| 2443 |
state = SCE_HP_TRIPLE; |
| 2444 |
ch = ' '; |
| 2445 |
chPrev = ' '; |
| 2446 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2447 |
} else { |
| 2448 |
state = SCE_HP_CHARACTER; |
| 2449 |
} |
| 2450 |
} else if (IsOperator(ch)) { |
| 2451 |
styler.ColourTo(i - 1, StateToPrint); |
| 2452 |
styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType)); |
| 2453 |
} else if ((ch == ' ') || (ch == '\t')) { |
| 2454 |
if (state == SCE_HP_START) { |
| 2455 |
styler.ColourTo(i - 1, StateToPrint); |
| 2456 |
state = SCE_HP_DEFAULT; |
| 2457 |
} |
| 2458 |
} |
| 2459 |
break; |
| 2460 |
case SCE_HP_WORD: |
| 2461 |
if (!IsAWordChar(ch)) { |
| 2462 |
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywordsPy, classifierPython, styler, prevWord, inScriptType, isMako); |
| 2463 |
state = SCE_HP_DEFAULT; |
| 2464 |
if (ch == '#') { |
| 2465 |
state = SCE_HP_COMMENTLINE; |
| 2466 |
} else if (ch == '\"') { |
| 2467 |
if (chNext == '\"' && chNext2 == '\"') { |
| 2468 |
i += 2; |
| 2469 |
state = SCE_HP_TRIPLEDOUBLE; |
| 2470 |
ch = ' '; |
| 2471 |
chPrev = ' '; |
| 2472 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2473 |
} else { |
| 2474 |
state = SCE_HP_STRING; |
| 2475 |
} |
| 2476 |
} else if (ch == '\'') { |
| 2477 |
if (chNext == '\'' && chNext2 == '\'') { |
| 2478 |
i += 2; |
| 2479 |
state = SCE_HP_TRIPLE; |
| 2480 |
ch = ' '; |
| 2481 |
chPrev = ' '; |
| 2482 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2483 |
} else { |
| 2484 |
state = SCE_HP_CHARACTER; |
| 2485 |
} |
| 2486 |
} else if (IsOperator(ch)) { |
| 2487 |
styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType)); |
| 2488 |
} |
| 2489 |
} |
| 2490 |
break; |
| 2491 |
case SCE_HP_COMMENTLINE: |
| 2492 |
if (ch == '\r' || ch == '\n') { |
| 2493 |
styler.ColourTo(i - 1, StateToPrint); |
| 2494 |
state = SCE_HP_DEFAULT; |
| 2495 |
} |
| 2496 |
break; |
| 2497 |
case SCE_HP_STRING: |
| 2498 |
if (ch == '\\') { |
| 2499 |
if (chNext == '\"' || chNext == '\'' || chNext == '\\') { |
| 2500 |
i++; |
| 2501 |
ch = chNext; |
| 2502 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2503 |
} |
| 2504 |
} else if (ch == '\"') { |
| 2505 |
styler.ColourTo(i, StateToPrint); |
| 2506 |
state = SCE_HP_DEFAULT; |
| 2507 |
} |
| 2508 |
break; |
| 2509 |
case SCE_HP_CHARACTER: |
| 2510 |
if (ch == '\\') { |
| 2511 |
if (chNext == '\"' || chNext == '\'' || chNext == '\\') { |
| 2512 |
i++; |
| 2513 |
ch = chNext; |
| 2514 |
chNext = SafeGetUnsignedCharAt(styler, i + 1); |
| 2515 |
} |
| 2516 |
} else if (ch == '\'') { |
| 2517 |
styler.ColourTo(i, StateToPrint); |
| 2518 |
state = SCE_HP_DEFAULT; |
| 2519 |
} |
| 2520 |
break; |
| 2521 |
case SCE_HP_TRIPLE: |
| 2522 |
if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') { |
| 2523 |
styler.ColourTo(i, StateToPrint); |
| 2524 |
state = SCE_HP_DEFAULT; |
| 2525 |
} |
| 2526 |
break; |
| 2527 |
case SCE_HP_TRIPLEDOUBLE: |
| 2528 |
if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') { |
| 2529 |
styler.ColourTo(i, StateToPrint); |
| 2530 |
state = SCE_HP_DEFAULT; |
| 2531 |
} |
| 2532 |
break; |
| 2533 |
///////////// start - PHP state handling |
| 2534 |
case SCE_HPHP_WORD: |
| 2535 |
if (!IsPhpWordChar(ch)) { |
| 2536 |
classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywordsPHP, classifierPHP, styler); |
| 2537 |
if (ch == '/' && chNext == '*') { |
| 2538 |
i++; |
| 2539 |
state = SCE_HPHP_COMMENT; |
| 2540 |
} else if (ch == '/' && chNext == '/') { |
| 2541 |
i++; |
| 2542 |
state = SCE_HPHP_COMMENTLINE; |
| 2543 |
} else if (ch == '#' && chNext != '[') { |
| 2544 |
state = SCE_HPHP_COMMENTLINE; |
| 2545 |
} else if (ch == '\"') { |
| 2546 |
state = SCE_HPHP_HSTRING; |
| 2547 |
phpStringDelimiter = "\""; |
| 2548 |
} else if (styler.Match(i, "<<<")) { |
| 2549 |
bool isSimpleString = false; |
| 2550 |
i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString); |
| 2551 |
if (!phpStringDelimiter.empty()) { |
| 2552 |
state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING); |
| 2553 |
if (foldHeredoc) levelCurrent++; |
| 2554 |
} |
| 2555 |
} else if (ch == '\'') { |
| 2556 |
state = SCE_HPHP_SIMPLESTRING; |
| 2557 |
phpStringDelimiter = "\'"; |
| 2558 |
} else if (ch == '$' && IsPhpWordStart(chNext)) { |
| 2559 |
state = SCE_HPHP_VARIABLE; |
| 2560 |
} else if (IsOperator(ch)) { |
| 2561 |
state = SCE_HPHP_OPERATOR; |
| 2562 |
} else { |
| 2563 |
state = SCE_HPHP_DEFAULT; |
| 2564 |
} |
| 2565 |
} |
| 2566 |
break; |
| 2567 |
case SCE_HPHP_NUMBER: |
| 2568 |
if (phpNumber.check(chNext, chNext2)) { |
| 2569 |
styler.ColourTo(i, phpNumber.isInvalid() ? SCE_HPHP_DEFAULT : SCE_HPHP_NUMBER); |
| 2570 |
state = SCE_HPHP_DEFAULT; |
| 2571 |
} |
| 2572 |
break; |
| 2573 |
case SCE_HPHP_VARIABLE: |
| 2574 |
if (!IsPhpWordChar(chNext)) { |
| 2575 |
styler.ColourTo(i, SCE_HPHP_VARIABLE); |
| 2576 |
state = SCE_HPHP_DEFAULT; |
| 2577 |
} |
| 2578 |
break; |
| 2579 |
case SCE_HPHP_COMMENT: |
| 2580 |
if (ch == '/' && chPrev == '*') { |
| 2581 |
styler.ColourTo(i, StateToPrint); |
| 2582 |
state = SCE_HPHP_DEFAULT; |
| 2583 |
} |
| 2584 |
break; |
| 2585 |
case SCE_HPHP_COMMENTLINE: |
| 2586 |
if (ch == '\r' || ch == '\n') { |
| 2587 |
styler.ColourTo(i - 1, StateToPrint); |
| 2588 |
state = SCE_HPHP_DEFAULT; |
| 2589 |
} |
| 2590 |
break; |
| 2591 |
case SCE_HPHP_HSTRING: |
| 2592 |
if (ch == '\\' && ((phpStringDelimiter == "\"") || chNext == '$' || chNext == '{')) { |
| 2593 |
// skip the next char |
| 2594 |
i++; |
| 2595 |
} else if (((ch == '{' && chNext == '$') || (ch == '$' && chNext == '{')) |
| 2596 |
&& IsPhpWordStart(chNext2)) { |
| 2597 |
styler.ColourTo(i - 1, StateToPrint); |
| 2598 |
state = SCE_HPHP_COMPLEX_VARIABLE; |
| 2599 |
} else if (ch == '$' && IsPhpWordStart(chNext)) { |
| 2600 |
styler.ColourTo(i - 1, StateToPrint); |
| 2601 |
state = SCE_HPHP_HSTRING_VARIABLE; |
| 2602 |
} else if (styler.Match(i, phpStringDelimiter.c_str())) { |
| 2603 |
if (phpStringDelimiter == "\"") { |
| 2604 |
styler.ColourTo(i, StateToPrint); |
| 2605 |
state = SCE_HPHP_DEFAULT; |
| 2606 |
} else if (lineStartVisibleChars == 1) { |
| 2607 |
const int psdLength = static_cast<int>(phpStringDelimiter.length()); |
| 2608 |
if (!IsPhpWordChar(styler.SafeGetCharAt(i + psdLength))) { |
| 2609 |
i += (((i + psdLength) < lengthDoc) ? psdLength : lengthDoc) - 1; |
| 2610 |
styler.ColourTo(i, StateToPrint); |
| 2611 |
state = SCE_HPHP_DEFAULT; |
| 2612 |
if (foldHeredoc) levelCurrent--; |
| 2613 |
} |
| 2614 |
} |
| 2615 |
} |
| 2616 |
break; |
| 2617 |
case SCE_HPHP_SIMPLESTRING: |
| 2618 |
if (phpStringDelimiter == "\'") { |
| 2619 |
if (ch == '\\') { |
| 2620 |
// skip the next char |
| 2621 |
i++; |
| 2622 |
} else if (ch == '\'') { |
| 2623 |
styler.ColourTo(i, StateToPrint); |
| 2624 |
state = SCE_HPHP_DEFAULT; |
| 2625 |
} |
| 2626 |
} else if (lineStartVisibleChars == 1 && styler.Match(i, phpStringDelimiter.c_str())) { |
| 2627 |
const int psdLength = static_cast<int>(phpStringDelimiter.length()); |
| 2628 |
if (!IsPhpWordChar(styler.SafeGetCharAt(i + psdLength))) { |
| 2629 |
i += (((i + psdLength) < lengthDoc) ? psdLength : lengthDoc) - 1; |
| 2630 |
styler.ColourTo(i, StateToPrint); |
| 2631 |
state = SCE_HPHP_DEFAULT; |
| 2632 |
if (foldHeredoc) levelCurrent--; |
| 2633 |
} |
| 2634 |
} |
| 2635 |
break; |
| 2636 |
case SCE_HPHP_HSTRING_VARIABLE: |
| 2637 |
if (!IsPhpWordChar(chNext)) { |
| 2638 |
styler.ColourTo(i, StateToPrint); |
| 2639 |
state = SCE_HPHP_HSTRING; |
| 2640 |
} |
| 2641 |
break; |
| 2642 |
case SCE_HPHP_COMPLEX_VARIABLE: |
| 2643 |
if (ch == '}') { |
| 2644 |
styler.ColourTo(i, StateToPrint); |
| 2645 |
state = SCE_HPHP_HSTRING; |
| 2646 |
} |
| 2647 |
break; |
| 2648 |
case SCE_HPHP_OPERATOR: |
| 2649 |
case SCE_HPHP_DEFAULT: |
| 2650 |
styler.ColourTo(i - 1, StateToPrint); |
| 2651 |
if (phpNumber.init(ch, chNext, chNext2)) { |
| 2652 |
if (phpNumber.isFinished()) { |
| 2653 |
styler.ColourTo(i, phpNumber.isInvalid() ? SCE_HPHP_DEFAULT : SCE_HPHP_NUMBER); |
| 2654 |
state = SCE_HPHP_DEFAULT; |
| 2655 |
} else { |
| 2656 |
state = SCE_HPHP_NUMBER; |
| 2657 |
} |
| 2658 |
} else if (IsAWordStart(ch)) { |
| 2659 |
state = SCE_HPHP_WORD; |
| 2660 |
} else if (ch == '/' && chNext == '*') { |
| 2661 |
i++; |
| 2662 |
state = SCE_HPHP_COMMENT; |
| 2663 |
} else if (ch == '/' && chNext == '/') { |
| 2664 |
i++; |
| 2665 |
state = SCE_HPHP_COMMENTLINE; |
| 2666 |
} else if (ch == '#' && chNext != '[') { |
| 2667 |
state = SCE_HPHP_COMMENTLINE; |
| 2668 |
} else if (ch == '\"') { |
| 2669 |
state = SCE_HPHP_HSTRING; |
| 2670 |
phpStringDelimiter = "\""; |
| 2671 |
} else if (styler.Match(i, "<<<")) { |
| 2672 |
bool isSimpleString = false; |
| 2673 |
i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString); |
| 2674 |
if (!phpStringDelimiter.empty()) { |
| 2675 |
state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING); |
| 2676 |
if (foldHeredoc) levelCurrent++; |
| 2677 |
} |
| 2678 |
} else if (ch == '\'') { |
| 2679 |
state = SCE_HPHP_SIMPLESTRING; |
| 2680 |
phpStringDelimiter = "\'"; |
| 2681 |
} else if (ch == '$' && IsPhpWordStart(chNext)) { |
| 2682 |
state = SCE_HPHP_VARIABLE; |
| 2683 |
} else if (IsOperator(ch)) { |
| 2684 |
state = SCE_HPHP_OPERATOR; |
| 2685 |
} else if ((state == SCE_HPHP_OPERATOR) && (IsASpace(ch))) { |
| 2686 |
state = SCE_HPHP_DEFAULT; |
| 2687 |
} |
| 2688 |
break; |
| 2689 |
///////////// end - PHP state handling |
| 2690 |
} |
| 2691 |
|
| 2692 |
// Some of the above terminated their lexeme but since the same character starts |
| 2693 |
// the same class again, only reenter if non empty segment. |
| 2694 |
|
| 2695 |
const bool nonEmptySegment = i >= static_cast<Sci_Position>(styler.GetStartSegment()); |
| 2696 |
if (state == SCE_HB_DEFAULT) { // One of the above succeeded |
| 2697 |
if ((ch == '\"') && (nonEmptySegment)) { |
| 2698 |
state = SCE_HB_STRING; |
| 2699 |
} else if (ch == '\'') { |
| 2700 |
state = SCE_HB_COMMENTLINE; |
| 2701 |
} else if (IsAWordStart(ch)) { |
| 2702 |
state = SCE_HB_WORD; |
| 2703 |
} else if (IsOperator(ch)) { |
| 2704 |
styler.ColourTo(i, SCE_HB_DEFAULT); |
| 2705 |
} |
| 2706 |
} else if (state == SCE_HBA_DEFAULT) { // One of the above succeeded |
| 2707 |
if ((ch == '\"') && (nonEmptySegment)) { |
| 2708 |
state = SCE_HBA_STRING; |
| 2709 |
} else if (ch == '\'') { |
| 2710 |
state = SCE_HBA_COMMENTLINE; |
| 2711 |
} else if (IsAWordStart(ch)) { |
| 2712 |
state = SCE_HBA_WORD; |
| 2713 |
} else if (IsOperator(ch)) { |
| 2714 |
styler.ColourTo(i, SCE_HBA_DEFAULT); |
| 2715 |
} |
| 2716 |
} else if (state == SCE_HJ_DEFAULT) { // One of the above succeeded |
| 2717 |
if (ch == '/' && chNext == '*') { |
| 2718 |
i++; |
| 2719 |
if (styler.SafeGetCharAt(i + 1) == '*') |
| 2720 |
state = SCE_HJ_COMMENTDOC; |
| 2721 |
else |
| 2722 |
state = SCE_HJ_COMMENT; |
| 2723 |
} else if (ch == '/' && chNext == '/') { |
| 2724 |
state = SCE_HJ_COMMENTLINE; |
| 2725 |
} else if ((ch == '\"') && (nonEmptySegment)) { |
| 2726 |
state = SCE_HJ_DOUBLESTRING; |
| 2727 |
} else if ((ch == '\'') && (nonEmptySegment)) { |
| 2728 |
state = SCE_HJ_SINGLESTRING; |
| 2729 |
} else if ((ch == '`') && (nonEmptySegment)) { |
| 2730 |
state = SCE_HJ_TEMPLATELITERAL; |
| 2731 |
} else if (IsAWordStart(ch)) { |
| 2732 |
state = SCE_HJ_WORD; |
| 2733 |
} else if (IsOperator(ch)) { |
| 2734 |
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType)); |
| 2735 |
} |
| 2736 |
} |
| 2737 |
} |
| 2738 |
|
| 2739 |
switch (state) { |
| 2740 |
case SCE_HJ_WORD: |
| 2741 |
classifyWordHTJS(styler.GetStartSegment(), lengthDoc - 1, keywordsJS, |
| 2742 |
classifierJavaScript, classifierJavaScriptServer, styler, inScriptType); |
| 2743 |
break; |
| 2744 |
case SCE_HB_WORD: |
| 2745 |
classifyWordHTVB(styler.GetStartSegment(), lengthDoc - 1, keywordsVB, classifierBasic, styler, inScriptType); |
| 2746 |
break; |
| 2747 |
case SCE_HP_WORD: |
| 2748 |
classifyWordHTPy(styler.GetStartSegment(), lengthDoc - 1, keywordsPy, classifierPython, styler, prevWord, inScriptType, isMako); |
| 2749 |
break; |
| 2750 |
case SCE_HPHP_WORD: |
| 2751 |
classifyWordHTPHP(styler.GetStartSegment(), lengthDoc - 1, keywordsPHP, classifierPHP, styler); |
| 2752 |
break; |
| 2753 |
default: |
| 2754 |
StateToPrint = statePrintForState(state, inScriptType); |
| 2755 |
if (static_cast<Sci_Position>(styler.GetStartSegment()) < lengthDoc) |
| 2756 |
styler.ColourTo(lengthDoc - 1, StateToPrint); |
| 2757 |
break; |
| 2758 |
} |
| 2759 |
|
| 2760 |
// Fill in the real level of the next line, keeping the current flags as they will be filled in later |
| 2761 |
if (fold) { |
| 2762 |
const int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; |
| 2763 |
styler.SetLevel(lineCurrent, levelPrev | flagsNext); |
| 2764 |
} |
| 2765 |
styler.Flush(); |
| 2766 |
} |
| 2767 |
|
| 2768 |
extern const LexerModule lmHTML(SCLEX_HTML, LexerHTML::LexerFactoryHTML, "hypertext", htmlWordListDesc); |
| 2769 |
extern const LexerModule lmXML(SCLEX_XML, LexerHTML::LexerFactoryXML, "xml", htmlWordListDesc); |
| 2770 |
extern const LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, LexerHTML::LexerFactoryPHPScript, "phpscript", phpscriptWordListDesc); |