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.
This commit is contained in:
Judd
2024-11-25 17:51:03 +08:00
committed by GitHub
parent 2df633180a
commit 6112c51e78
2 changed files with 4 additions and 2 deletions

View File

@@ -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]

View File

@@ -1631,8 +1631,8 @@ suite "RST/Code highlight":
"""
let expected = """<blockquote><p><span class="Keyword">def</span> f_name<span class="Punctuation">(</span><span class="Punctuation">arg</span><span class="Operator">=</span><span class="DecNumber">42</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
print<span class="Punctuation">(</span><span class="RawData">f&quot;{arg}&quot;</span><span class="Punctuation">)</span></p></blockquote>"""
let expected = """<blockquote><p><span class="Keyword">def</span> <span class="Identifier">f_name</span><span class="Punctuation">(</span><span class="Identifier">arg</span><span class="Operator">=</span><span class="DecNumber">42</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
<span class="Identifier">print</span><span class="Punctuation">(</span><span class="RawData">f&quot;{arg}&quot;</span><span class="Punctuation">)</span></p></blockquote>"""
check strip(rstToHtml(pythonCode, {}, newStringTable(modeCaseSensitive))) ==
strip(expected)