Correct lineinfo for accent quoted symbols in proc definition (#10399)
* compiler/parser: preserve lineinfo for accent quoted symbols
Previously the lineinfo for symbol $$$ in this example is:
proc `$$$`
^
After this commit:
proc `$$$`
^
* compiler/semstmts: correct lineinfo for accent quoted idents
Previously nimsuggest would highlight this as:
proc `$$$`
^~~
After this commit:
proc `$$$`
^~~
* nimsuggest/tests: add a test for accent quoted proc
Disabled by default
This commit is contained in:
parent
4bea8dd674
commit
413755fd45
3 changed files with 22 additions and 11 deletions
|
|
@ -332,12 +332,15 @@ proc parseSymbol(p: var TParser, mode = smNormal): PNode =
|
||||||
parMessage(p, errIdentifierExpected, p.tok)
|
parMessage(p, errIdentifierExpected, p.tok)
|
||||||
break
|
break
|
||||||
of tkOpr, tkDot, tkDotDot, tkEquals, tkParLe..tkParDotRi:
|
of tkOpr, tkDot, tkDotDot, tkEquals, tkParLe..tkParDotRi:
|
||||||
|
let lineinfo = parLineinfo(p)
|
||||||
var accm = ""
|
var accm = ""
|
||||||
while p.tok.tokType in {tkOpr, tkDot, tkDotDot, tkEquals,
|
while p.tok.tokType in {tkOpr, tkDot, tkDotDot, tkEquals,
|
||||||
tkParLe..tkParDotRi}:
|
tkParLe..tkParDotRi}:
|
||||||
accm.add(tokToStr(p.tok))
|
accm.add(tokToStr(p.tok))
|
||||||
getTok(p)
|
getTok(p)
|
||||||
result.add(newIdentNodeP(p.lex.cache.getIdent(accm), p))
|
let node = newNodeI(nkIdent, lineinfo)
|
||||||
|
node.ident = p.lex.cache.getIdent(accm)
|
||||||
|
result.add(node)
|
||||||
of tokKeywordLow..tokKeywordHigh, tkSymbol, tkIntLit..tkCharLit:
|
of tokKeywordLow..tokKeywordHigh, tkSymbol, tkIntLit..tkCharLit:
|
||||||
result.add(newIdentNodeP(p.lex.cache.getIdent(tokToStr(p.tok)), p))
|
result.add(newIdentNodeP(p.lex.cache.getIdent(tokToStr(p.tok)), p))
|
||||||
getTok(p)
|
getTok(p)
|
||||||
|
|
|
||||||
|
|
@ -318,16 +318,16 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
|
||||||
result = semIdentWithPragma(c, kind, n, {})
|
result = semIdentWithPragma(c, kind, n, {})
|
||||||
if result.owner.kind == skModule:
|
if result.owner.kind == skModule:
|
||||||
incl(result.flags, sfGlobal)
|
incl(result.flags, sfGlobal)
|
||||||
let info = case n.kind
|
|
||||||
|
proc getLineInfo(n: PNode): TLineInfo =
|
||||||
|
case n.kind
|
||||||
of nkPostfix:
|
of nkPostfix:
|
||||||
n.sons[1].info
|
getLineInfo(n.sons[1])
|
||||||
of nkPragmaExpr:
|
of nkAccQuoted, nkPragmaExpr:
|
||||||
if n.sons[0].kind == nkPostfix:
|
getLineInfo(n.sons[0])
|
||||||
n.sons[0].sons[1].info
|
|
||||||
else:
|
|
||||||
n.sons[0].info
|
|
||||||
else:
|
else:
|
||||||
n.info
|
n.info
|
||||||
|
let info = getLineInfo(n)
|
||||||
suggestSym(c.config, info, result, c.graph.usageSym)
|
suggestSym(c.config, info, result, c.graph.usageSym)
|
||||||
|
|
||||||
proc checkNilable(c: PContext; v: PSym) =
|
proc checkNilable(c: PContext; v: PSym) =
|
||||||
|
|
|
||||||
8
nimsuggest/tests/taccent_highlight.nim
Normal file
8
nimsuggest/tests/taccent_highlight.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
proc `$$$`#[!]#
|
||||||
|
|
||||||
|
discard """
|
||||||
|
disabled:true
|
||||||
|
$nimsuggest --tester $file
|
||||||
|
>highlight $1
|
||||||
|
highlight;;skProc;;1;;6;;3
|
||||||
|
"""
|
||||||
Loading…
Add table
Add a link
Reference in a new issue