From 413755fd45f5a77f9c3323cf7185830249c3f310 Mon Sep 17 00:00:00 2001 From: alaviss Date: Mon, 21 Jan 2019 22:57:48 +0700 Subject: [PATCH] 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 --- compiler/parser.nim | 5 ++++- compiler/semstmts.nim | 20 ++++++++++---------- nimsuggest/tests/taccent_highlight.nim | 8 ++++++++ 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 nimsuggest/tests/taccent_highlight.nim diff --git a/compiler/parser.nim b/compiler/parser.nim index afc49c0d37..c9626c527c 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -332,12 +332,15 @@ proc parseSymbol(p: var TParser, mode = smNormal): PNode = parMessage(p, errIdentifierExpected, p.tok) break of tkOpr, tkDot, tkDotDot, tkEquals, tkParLe..tkParDotRi: + let lineinfo = parLineinfo(p) var accm = "" while p.tok.tokType in {tkOpr, tkDot, tkDotDot, tkEquals, tkParLe..tkParDotRi}: accm.add(tokToStr(p.tok)) 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: result.add(newIdentNodeP(p.lex.cache.getIdent(tokToStr(p.tok)), p)) getTok(p) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index de39e95c8d..288820d862 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -318,16 +318,16 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym = result = semIdentWithPragma(c, kind, n, {}) if result.owner.kind == skModule: incl(result.flags, sfGlobal) - let info = case n.kind - of nkPostfix: - n.sons[1].info - of nkPragmaExpr: - if n.sons[0].kind == nkPostfix: - n.sons[0].sons[1].info - else: - n.sons[0].info - else: - n.info + + proc getLineInfo(n: PNode): TLineInfo = + case n.kind + of nkPostfix: + getLineInfo(n.sons[1]) + of nkAccQuoted, nkPragmaExpr: + getLineInfo(n.sons[0]) + else: + n.info + let info = getLineInfo(n) suggestSym(c.config, info, result, c.graph.usageSym) proc checkNilable(c: PContext; v: PSym) = diff --git a/nimsuggest/tests/taccent_highlight.nim b/nimsuggest/tests/taccent_highlight.nim new file mode 100644 index 0000000000..2f03d7c860 --- /dev/null +++ b/nimsuggest/tests/taccent_highlight.nim @@ -0,0 +1,8 @@ +proc `$$$`#[!]# + +discard """ +disabled:true +$nimsuggest --tester $file +>highlight $1 +highlight;;skProc;;1;;6;;3 +"""