aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJad Altahan <xviyy@aol.com>2018-11-28 08:55:35 +1100
committerJad Altahan <xviyy@aol.com>2018-11-28 08:55:35 +1100
commitd51da684fea2b1789e33fa4856ed58a07928f7a5 (patch)
tree5ebe6e5228b1df6aa07bd6e06525f398046486a0
parent53a07f5bf3abdd9751fbe8ed52ee72a67956539b (diff)
downloadscintilla-mirror-d51da684fea2b1789e33fa4856ed58a07928f7a5.tar.gz
Move functions to unnamed namespace
-rw-r--r--lexers/LexNim.cxx207
1 files changed, 106 insertions, 101 deletions
diff --git a/lexers/LexNim.cxx b/lexers/LexNim.cxx
index 94d179e04..304f93463 100644
--- a/lexers/LexNim.cxx
+++ b/lexers/LexNim.cxx
@@ -35,6 +35,110 @@
using namespace Scintilla;
+namespace {
+ // Use an unnamed namespace to protect the functions and classes from name conflicts
+
+enum NumType {
+ Binary,
+ Octal,
+ Exponent,
+ Hexadecimal,
+ Decimal,
+ FormatError
+};
+
+int GetNumStyle(const int numType) {
+ if (numType == NumType::FormatError) {
+ return SCE_NIM_NUMERROR;
+ }
+
+ return SCE_NIM_NUMBER;
+}
+
+bool IsAWordChar(const int ch) {
+ return ch < 0x80 && (isalnum(ch) || ch == '_' || ch == '.');
+}
+
+int IsNumHex(const StyleContext &sc) {
+ return sc.chNext == 'x' || sc.chNext == 'X';
+}
+
+int IsNumBinary(const StyleContext &sc) {
+ return sc.chNext == 'b' || sc.chNext == 'B';
+}
+
+int IsNumOctal(const StyleContext &sc) {
+ return IsADigit(sc.chNext) || sc.chNext == 'o';
+}
+
+bool IsNewline(const int ch) {
+ return (ch == '\n' || ch == '\r');
+}
+
+constexpr bool IsTripleLiteral(const int style) noexcept {
+ return style == SCE_NIM_TRIPLE || style == SCE_NIM_TRIPLEDOUBLE;
+}
+
+constexpr bool IsLineComment(const int style) noexcept {
+ return style == SCE_NIM_COMMENTLINE || style == SCE_NIM_COMMENTLINEDOC;
+}
+
+constexpr bool IsStreamComment(const int style) noexcept {
+ return style == SCE_NIM_COMMENT || style == SCE_NIM_COMMENTDOC;
+}
+
+// Adopted from Accessor.cxx
+int GetIndent(const Sci_Position line, Accessor &styler) {
+ Sci_Position startPos = styler.LineStart(line);
+ Sci_Position eolPos = styler.LineStart(line + 1) - 1;
+
+ char ch = styler[startPos];
+ int style = styler.StyleAt(startPos);
+
+ int indent = 0;
+ bool inPrevPrefix = line > 0;
+ Sci_Position posPrev = inPrevPrefix ? styler.LineStart(line - 1) : 0;
+
+ // No fold points inside block comments and triple literals
+ while ((IsASpaceOrTab(ch)
+ || IsStreamComment(style)
+ || IsTripleLiteral(style)) && (startPos < eolPos)) {
+ if (inPrevPrefix) {
+ char chPrev = styler[posPrev++];
+ if (chPrev != ' ' && chPrev != '\t') {
+ inPrevPrefix = false;
+ }
+ }
+
+ if (ch == '\t') {
+ indent = (indent / 8 + 1) * 8;
+ } else {
+ indent++;
+ }
+
+ startPos++;
+ ch = styler[startPos];
+ style = styler.StyleAt(startPos);
+ }
+
+ indent += SC_FOLDLEVELBASE;
+
+ if (styler.LineStart(line) == styler.Length()
+ || IsASpaceOrTab(ch)
+ || IsNewline(ch)
+ || IsLineComment(style)) {
+ return indent | SC_FOLDLEVELWHITEFLAG;
+ } else {
+ return indent;
+ }
+}
+
+int IndentAmount(const Sci_Position line, Accessor &styler) {
+ const int indent = GetIndent(line, styler);
+ const int indentLevel = indent & SC_FOLDLEVELNUMBERMASK;
+ return indentLevel <= SC_FOLDLEVELBASE ? indent : indentLevel | (indent & ~SC_FOLDLEVELNUMBERMASK);
+}
+
struct OptionsNim {
bool fold;
bool foldCompact;
@@ -80,6 +184,8 @@ LexicalClass lexicalClasses[] = {
16, "SCE_NIM_IDENTIFIER", "identifier", "Identifiers",
};
+}
+
class LexerNim : public DefaultLexer {
CharacterSet setWord;
WordList keywords;
@@ -173,55 +279,6 @@ Sci_Position SCI_METHOD LexerNim::WordListSet(int n, const char *wl) {
return firstModification;
}
-enum NumType {
- Binary,
- Octal,
- Exponent,
- Hexadecimal,
- Decimal,
- FormatError
-};
-
-static int GetNumStyle(int numType) {
- if (numType == NumType::FormatError) {
- return SCE_NIM_NUMERROR;
- }
-
- return SCE_NIM_NUMBER;
-}
-
-static bool IsAWordChar(const int ch) {
- return ch < 0x80 && (isalnum(ch) || ch == '_' || ch == '.');
-}
-
-static int IsNumHex(StyleContext &sc) {
- return sc.chNext == 'x' || sc.chNext == 'X';
-}
-
-static int IsNumBinary(StyleContext &sc) {
- return sc.chNext == 'b' || sc.chNext == 'B';
-}
-
-static int IsNumOctal(StyleContext &sc) {
- return IsADigit(sc.chNext) || sc.chNext == 'o';
-}
-
-static bool IsNewline(const int ch) {
- return (ch == '\n' || ch == '\r');
-}
-
-static bool IsTripleLiteral(const int style) {
- return style == SCE_NIM_TRIPLE || style == SCE_NIM_TRIPLEDOUBLE;
-}
-
-static bool IsLineComment(const int style) {
- return style == SCE_NIM_COMMENTLINE || style == SCE_NIM_COMMENTLINEDOC;
-}
-
-static bool IsStreamComment(const int style) {
- return style == SCE_NIM_COMMENT || style == SCE_NIM_COMMENTDOC;
-}
-
void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,
int initStyle, IDocument *pAccess) {
// No one likes a leaky string
@@ -560,58 +617,6 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length,
sc.Complete();
}
-// Adopted from Accessor.cxx
-static int GetIndent(const Sci_Position line, Accessor &styler) {
- Sci_Position startPos = styler.LineStart(line);
- Sci_Position eolPos = styler.LineStart(line + 1) - 1;
-
- char ch = styler[startPos];
- int style = styler.StyleAt(startPos);
-
- int indent = 0;
- bool inPrevPrefix = line > 0;
- Sci_Position posPrev = inPrevPrefix ? styler.LineStart(line - 1) : 0;
-
- // No fold points inside block comments and triple literals
- while ((IsASpaceOrTab(ch)
- || IsStreamComment(style)
- || IsTripleLiteral(style)) && (startPos < eolPos)) {
- if (inPrevPrefix) {
- char chPrev = styler[posPrev++];
- if (chPrev != ' ' && chPrev != '\t') {
- inPrevPrefix = false;
- }
- }
-
- if (ch == '\t') {
- indent = (indent / 8 + 1) * 8;
- } else {
- indent++;
- }
-
- startPos++;
- ch = styler[startPos];
- style = styler.StyleAt(startPos);
- }
-
- indent += SC_FOLDLEVELBASE;
-
- if (styler.LineStart(line) == styler.Length()
- || IsASpaceOrTab(ch)
- || IsNewline(ch)
- || IsLineComment(style)) {
- return indent | SC_FOLDLEVELWHITEFLAG;
- } else {
- return indent;
- }
-}
-
-static int IndentAmount(const Sci_Position line, Accessor &styler) {
- const int indent = GetIndent(line, styler);
- const int indentLevel = indent & SC_FOLDLEVELNUMBERMASK;
- return indentLevel <= SC_FOLDLEVELBASE ? indent : indentLevel | (indent & ~SC_FOLDLEVELNUMBERMASK);
-}
-
void SCI_METHOD LexerNim::Fold(Sci_PositionU startPos, Sci_Position length, int, IDocument *pAccess) {
if (!options.fold) {
return;