diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 421a83c19d..97fa91b3ab 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -173,7 +173,7 @@ proc isNimIdentifier*(s: string): bool = inc(i) result = true -proc tokToStr*(tok: TToken): string = +proc `$`*(tok: TToken): string = case tok.tokType of tkIntLit..tkInt64Lit: result = $tok.iNumber of tkFloatLit..tkFloat64Lit: result = $tok.fNumber @@ -188,11 +188,11 @@ proc tokToStr*(tok: TToken): string = proc prettyTok*(tok: TToken): string = if isKeyword(tok.tokType): result = "keyword " & tok.ident.s - else: result = tokToStr(tok) + else: result = $tok proc printTok*(conf: ConfigRef; tok: TToken) = msgWriteln(conf, $tok.line & ":" & $tok.col & "\t" & - TokTypeToStr[tok.tokType] & " " & tokToStr(tok)) + TokTypeToStr[tok.tokType] & " " & $tok) proc initToken*(L: var TToken) = L.tokType = tkInvalid diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 02d1e7d2ad..f518b3abf7 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -123,31 +123,31 @@ proc parseDirective(L: var TLexer, tok: var TToken; config: ConfigRef; condStack of wEnd: doEnd(L, tok, condStack) of wWrite: ppGetTok(L, tok) - msgs.msgWriteln(config, strtabs.`%`(tokToStr(tok), config.configVars, + msgs.msgWriteln(config, strtabs.`%`($tok, config.configVars, {useEnvironment, useKey})) ppGetTok(L, tok) else: case tok.ident.s.normalize of "putenv": ppGetTok(L, tok) - var key = tokToStr(tok) + var key = $tok ppGetTok(L, tok) - os.putEnv(key, tokToStr(tok)) + os.putEnv(key, $tok) ppGetTok(L, tok) of "prependenv": ppGetTok(L, tok) - var key = tokToStr(tok) + var key = $tok ppGetTok(L, tok) - os.putEnv(key, tokToStr(tok) & os.getEnv(key)) + os.putEnv(key, $tok & os.getEnv(key)) ppGetTok(L, tok) of "appendenv": ppGetTok(L, tok) - var key = tokToStr(tok) + var key = $tok ppGetTok(L, tok) - os.putEnv(key, os.getEnv(key) & tokToStr(tok)) + os.putEnv(key, os.getEnv(key) & $tok) ppGetTok(L, tok) else: - lexMessage(L, errGenerated, "invalid directive: '$1'" % tokToStr(tok)) + lexMessage(L, errGenerated, "invalid directive: '$1'" % $tok) proc confTok(L: var TLexer, tok: var TToken; config: ConfigRef; condStack: var seq[bool]) = ppGetTok(L, tok) @@ -156,7 +156,7 @@ proc confTok(L: var TLexer, tok: var TToken; config: ConfigRef; condStack: var s proc checkSymbol(L: TLexer, tok: TToken) = if tok.tokType notin {tkSymbol..tkInt64Lit, tkStrLit..tkTripleStrLit}: - lexMessage(L, errGenerated, "expected identifier, but got: " & tokToStr(tok)) + lexMessage(L, errGenerated, "expected identifier, but got: " & $tok) proc parseAssignment(L: var TLexer, tok: var TToken; config: ConfigRef; condStack: var seq[bool]) = @@ -164,21 +164,21 @@ proc parseAssignment(L: var TLexer, tok: var TToken; confTok(L, tok, config, condStack) # skip unnecessary prefix var info = getLineInfo(L, tok) # save for later in case of an error checkSymbol(L, tok) - var s = tokToStr(tok) + var s = $tok confTok(L, tok, config, condStack) # skip symbol var val = "" while tok.tokType == tkDot: add(s, '.') confTok(L, tok, config, condStack) checkSymbol(L, tok) - add(s, tokToStr(tok)) + add(s, $tok) confTok(L, tok, config, condStack) if tok.tokType == tkBracketLe: # BUGFIX: val, not s! confTok(L, tok, config, condStack) checkSymbol(L, tok) add(val, '[') - add(val, tokToStr(tok)) + add(val, $tok) confTok(L, tok, config, condStack) if tok.tokType == tkBracketRi: confTok(L, tok, config, condStack) else: lexMessage(L, errGenerated, "expected closing ']'") @@ -188,12 +188,12 @@ proc parseAssignment(L: var TLexer, tok: var TToken; if len(val) > 0: add(val, ':') confTok(L, tok, config, condStack) # skip ':' or '=' or '%' checkSymbol(L, tok) - add(val, tokToStr(tok)) + add(val, $tok) confTok(L, tok, config, condStack) # skip symbol while tok.ident != nil and tok.ident.s == "&": confTok(L, tok, config, condStack) checkSymbol(L, tok) - add(val, tokToStr(tok)) + add(val, $tok) confTok(L, tok, config, condStack) if percent: processSwitch(s, strtabs.`%`(val, config.configVars, diff --git a/compiler/parser.nim b/compiler/parser.nim index eda75f9264..65fb2c5a30 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -343,13 +343,13 @@ proc parseSymbol(p: var TParser, mode = smNormal): PNode = var accm = "" while p.tok.tokType in {tkOpr, tkDot, tkDotDot, tkEquals, tkParLe..tkParDotRi}: - accm.add(tokToStr(p.tok)) + accm.add($p.tok) getTok(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)) + result.add(newIdentNodeP(p.lex.cache.getIdent($p.tok), p)) getTok(p) else: parMessage(p, errIdentifierExpected, p.tok) @@ -903,6 +903,8 @@ proc parsePragma(p: var TParser): PNode = #| pragma = '{.' optInd (exprColonExpr comma?)* optPar ('.}' | '}') result = newNodeP(nkPragma, p) inc p.inPragma + when defined(nimpretty): + inc p.em.keepIndents getTok(p) optInd(p, result) while p.tok.tokType notin {tkCurlyDotRi, tkCurlyRi, tkEof}: @@ -921,6 +923,8 @@ proc parsePragma(p: var TParser): PNode = else: parMessage(p, "expected '.}'") dec p.inPragma + when defined(nimpretty): + dec p.em.keepIndents proc identVis(p: var TParser; allowDot=false): PNode = #| identVis = symbol opr? # postfix position diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim index 2f8fe03f28..e8458d1234 100644 --- a/nimpretty/tests/exhaustive.nim +++ b/nimpretty/tests/exhaustive.nim @@ -409,3 +409,11 @@ type ccFastCall, # fastcall (pass parameters in registers) ccClosure, # proc has a closure ccNoConvention # needed for generating proper C procs sometimes + + +proc isValid1*[A](s: HashSet[A]): bool {.deprecated: + "Deprecated since v0.20; sets are initialized by default".} = + ## Returns `true` if the set has been initialized (with `initHashSet proc + ## <#initHashSet,int>`_ or `init proc <#init,HashSet[A],int>`_). + result = s.data.len > 0 + # bug #11468 diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim index 75580081d6..6089c34c68 100644 --- a/nimpretty/tests/expected/exhaustive.nim +++ b/nimpretty/tests/expected/exhaustive.nim @@ -419,3 +419,11 @@ type ccFastCall, # fastcall (pass parameters in registers) ccClosure, # proc has a closure ccNoConvention # needed for generating proper C procs sometimes + + +proc isValid1*[A](s: HashSet[A]): bool {.deprecated: + "Deprecated since v0.20; sets are initialized by default".} = + ## Returns `true` if the set has been initialized (with `initHashSet proc + ## <#initHashSet,int>`_ or `init proc <#init,HashSet[A],int>`_). + result = s.data.len > 0 + # bug #11468