fixes #25387; embedsrc breaks with Line Continuation (#25388)

fixes #25387


https://stackoverflow.com/questions/30286253/how-to-escape-backslash-in-comment

- adding a whitespace or `\t` after `\` breaks the `goto` block
- `\* *\` doesn't support nesting, causing problems for using it in the
Nim comments
This commit is contained in:
ringabout
2025-12-26 04:02:54 +08:00
committed by GitHub
parent 5e53a70e62
commit a41bbf6901
2 changed files with 12 additions and 1 deletions

View File

@@ -337,7 +337,10 @@ proc genLineDir(p: BProc, t: PNode) =
let line = t.info.safeLineNm
if optEmbedOrigSrc in p.config.globalOptions:
p.s(cpsStmts).add("//" & sourceLine(p.config, t.info) & "\L")
var code = sourceLine(p.config, t.info)
if code.endsWith('\\'):
code.add "#"
p.s(cpsStmts).add("// " & code & "\L")
let lastFileIndex = p.lastLineInfo.fileIndex
let freshLine = freshLineInfo(p, t.info)
if freshLine:

8
tests/ccgbugs/t25387.nim Normal file
View File

@@ -0,0 +1,8 @@
discard """
matrix: "--embedsrc=on"
"""
proc trim() =
let s = 10
let x = s + 5 # user entered literal \
trim()