mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-01 11:34:43 +00:00
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:
@@ -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]
|
||||
|
||||
@@ -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"{arg}"</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"{arg}"</span><span class="Punctuation">)</span></p></blockquote>"""
|
||||
|
||||
check strip(rstToHtml(pythonCode, {}, newStringTable(modeCaseSensitive))) ==
|
||||
strip(expected)
|
||||
|
||||
Reference in New Issue
Block a user