From cd370e4725e2b138cc31a6925c3f7c21624e0f75 Mon Sep 17 00:00:00 2001 From: Judd Date: Mon, 25 Nov 2024 17:51:03 +0800 Subject: [PATCH] Fix highlite.nim (#24457) When parsing `a = 1` with `langPython`, Eof is reported unexpectedly. Fix: allow other languages to fallback to "Identifier" when it is not a keyword. This patch is useful as this is a highlighter. `Eof` as annoying. (cherry picked from commit 6112c51e7850e77963856e4424c74abf596c84ac) --- lib/packages/docutils/highlite.nim | 2 ++ tests/stdlib/trstgen.nim | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/packages/docutils/highlite.nim b/lib/packages/docutils/highlite.nim index f8376f46c3..7542b88018 100644 --- a/lib/packages/docutils/highlite.nim +++ b/lib/packages/docutils/highlite.nim @@ -301,6 +301,8 @@ proc nimNextToken(g: var GeneralTokenizer, keywords: openArray[string] = @[]) = g.kind = nimGetKeyword(id) elif isKeyword(keywords, id) >= 0: g.kind = gtKeyword + else: + g.kind = gtIdentifier of '0': inc(pos) case g.buf[pos] diff --git a/tests/stdlib/trstgen.nim b/tests/stdlib/trstgen.nim index 6253e7146d..ae980afd80 100644 --- a/tests/stdlib/trstgen.nim +++ b/tests/stdlib/trstgen.nim @@ -1629,8 +1629,8 @@ suite "RST/Code highlight": """ - let expected = """

def f_name(arg=42): - print(f"{arg}")

""" + let expected = """

def f_name(arg=42): + print(f"{arg}")

""" check strip(rstToHtml(pythonCode, {}, newStringTable(modeCaseSensitive))) == strip(expected)