From 458304eb583a64fcdec5f5d9270417a1c5c628c8 Mon Sep 17 00:00:00 2001 From: Jad Altahan Date: Wed, 23 Jan 2019 07:43:00 +1100 Subject: Backport: Feature [feature-requests:#1258]. Add function IsFuncName() to Nim lexer. Backport of changeset 7235:6e959f8ec7d9. --- lexers/LexNim.cxx | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lexers/LexNim.cxx b/lexers/LexNim.cxx index fae9e8d6e..c74c1a965 100644 --- a/lexers/LexNim.cxx +++ b/lexers/LexNim.cxx @@ -75,6 +75,26 @@ bool IsNewline(const int ch) { return (ch == '\n' || ch == '\r'); } +bool IsFuncName(const char *str) { + const char *identifiers[] = { + "proc", + "func", + "macro", + "method", + "template", + "iterator", + "converter" + }; + + for (const char *id : identifiers) { + if (strcmp(str, id) == 0) { + return true; + } + } + + return false; +} + constexpr bool IsTripleLiteral(const int style) noexcept { return style == SCE_NIM_TRIPLE || style == SCE_NIM_TRIPLEDOUBLE; } @@ -419,17 +439,7 @@ void SCI_METHOD LexerNim::Lex(Sci_PositionU startPos, Sci_Position length, sc.SetState(SCE_NIM_DEFAULT); if (style == SCE_NIM_WORD) { - if (0 == strcmp(s, "proc") - || 0 == strcmp(s, "func") - || 0 == strcmp(s, "macro") - || 0 == strcmp(s, "method") - || 0 == strcmp(s, "template") - || 0 == strcmp(s, "iterator") - || 0 == strcmp(s, "converter")) { - funcNameExists = true; - } else { - funcNameExists = false; - } + funcNameExists = IsFuncName(s); } else { funcNameExists = false; } -- cgit v1.2.3