diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/KeyWords.cxx | 1 | ||||
-rw-r--r-- | src/LexOthers.cxx | 84 |
2 files changed, 80 insertions, 5 deletions
diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index d98c43ffa..b38e515a0 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -205,6 +205,7 @@ int Scintilla_LinkLexers() { LINK_LEXER(lmPHP); LINK_LEXER(lmPHPSCRIPT); LINK_LEXER(lmPLM); + LINK_LEXER(lmPo); LINK_LEXER(lmPOV); LINK_LEXER(lmPowerShell); LINK_LEXER(lmProgress); diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx index d3b58a635..24eee96a3 100644 --- a/src/LexOthers.cxx +++ b/src/LexOthers.cxx @@ -24,6 +24,10 @@ using namespace Scintilla; #endif +static bool strstart(const char *haystack, const char *needle) { + return strncmp(haystack, needle, strlen(needle)) == 0; +} + static bool Is0To9(char ch) { return (ch >= '0') && (ch <= '9'); } @@ -564,6 +568,79 @@ static void FoldDiffDoc(unsigned int startPos, int length, int, WordList *[], Ac } while (static_cast<int>(startPos) + length > curLineStart); } +static void ColourisePoLine( + char *lineBuffer, + unsigned int lengthLine, + unsigned int startLine, + unsigned int endPos, + Accessor &styler) { + + unsigned int i = 0; + static unsigned int state = SCE_PO_DEFAULT; + unsigned int state_start = SCE_PO_DEFAULT; + + while ((i < lengthLine) && isspacechar(lineBuffer[i])) // Skip initial spaces + i++; + if (i < lengthLine) { + if (lineBuffer[i] == '#') { + // check if the comment contains any flags ("#, ") and + // then whether the flags contain "fuzzy" + if (strstart(lineBuffer, "#, ") && strstr(lineBuffer, "fuzzy")) + styler.ColourTo(endPos, SCE_PO_FUZZY); + else + styler.ColourTo(endPos, SCE_PO_COMMENT); + } else { + if (lineBuffer[0] == '"') { + // line continuation, use previous style + styler.ColourTo(endPos, state); + return; + // this implicitly also matches "msgid_plural" + } else if (strstart(lineBuffer, "msgid")) { + state_start = SCE_PO_MSGID; + state = SCE_PO_MSGID_TEXT; + } else if (strstart(lineBuffer, "msgstr")) { + state_start = SCE_PO_MSGSTR; + state = SCE_PO_MSGSTR_TEXT; + } else if (strstart(lineBuffer, "msgctxt")) { + state_start = SCE_PO_MSGCTXT; + state = SCE_PO_MSGCTXT_TEXT; + } + if (state_start != SCE_PO_DEFAULT) { + // find the next space + while ((i < lengthLine) && ! isspacechar(lineBuffer[i])) + i++; + styler.ColourTo(startLine + i - 1, state_start); + styler.ColourTo(startLine + i, SCE_PO_DEFAULT); + styler.ColourTo(endPos, state); + } + } + } else { + styler.ColourTo(endPos, SCE_PO_DEFAULT); + } +} + +static void ColourisePoDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { + char lineBuffer[1024]; + styler.StartAt(startPos); + styler.StartSegment(startPos); + unsigned int linePos = 0; + unsigned int startLine = startPos; + for (unsigned int i = startPos; i < startPos + length; i++) { + lineBuffer[linePos++] = styler[i]; + if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) { + // End of line (or of line buffer) met, colourise it + lineBuffer[linePos] = '\0'; + ColourisePoLine(lineBuffer, linePos, startLine, i, styler); + linePos = 0; + startLine = i + 1; + } + } + if (linePos > 0) { // Last line does not have ending characters + ColourisePoLine(lineBuffer, linePos, startLine, startPos + length - 1, styler); + } +} + + static void ColourisePropsLine( char *lineBuffer, unsigned int lengthLine, @@ -795,10 +872,6 @@ static void ColouriseMakeDoc(unsigned int startPos, int length, int, WordList *[ } } -static bool strstart(const char *haystack, const char *needle) { - return strncmp(haystack, needle, strlen(needle)) == 0; -} - static int RecogniseErrorListLine(const char *lineBuffer, unsigned int lengthLine, int &startValue) { if (lineBuffer[0] == '>') { // Command or return status @@ -902,7 +975,7 @@ static int RecogniseErrorListLine(const char *lineBuffer, unsigned int lengthLin if ((chNext != '\\') && (chNext != '/') && (chNext != ' ')) { // This check is not completely accurate as may be on // GTK+ with a file name that includes ':'. - state = stGccStart; + state = stGccStart; } else if (chNext == ' ') { // indicates a Lua 5.1 error message initialColonPart = true; } @@ -1150,6 +1223,7 @@ static void ColouriseNullDoc(unsigned int startPos, int length, int, WordList *[ LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc, "batch", 0, batchWordListDesc); LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc, "diff", FoldDiffDoc, emptyWordListDesc); +LexerModule lmPo(SCLEX_PO, ColourisePoDoc, "po", 0, emptyWordListDesc); LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc, "props", FoldPropsDoc, emptyWordListDesc); LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc, "makefile", 0, emptyWordListDesc); LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc, "errorlist", 0, emptyWordListDesc); |