diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/layouter.nim | 6 | ||||
-rw-r--r-- | compiler/lexer.nim | 6 | ||||
-rw-r--r-- | compiler/nimconf.nim | 28 | ||||
-rw-r--r-- | compiler/parser.nim | 8 |
4 files changed, 26 insertions, 22 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim index 3ac907f1d..057bad5ba 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -346,7 +346,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) = if endsInAlpha(em): wrSpace em elif not em.inquote and not endsInWhite(em) and - em.lastTok notin openPars and not em.lastTokWasTerse: + em.lastTok notin (openPars+{tkOpr, tkDotDot}) and not em.lastTokWasTerse: #and tok.tokType in oprSet wrSpace em @@ -392,8 +392,8 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) = wr(em, TokTypeToStr[tok.tokType], ltOther) if not em.inquote: wrSpace(em) of tkOpr, tkDotDot: - if ((tok.strongSpaceA == 0 and tok.strongSpaceB == 0) or em.inquote) and - tok.ident.s notin ["<", ">", "<=", ">=", "==", "!="]: + if em.inquote or ((tok.strongSpaceA == 0 and tok.strongSpaceB == 0) and + tok.ident.s notin ["<", ">", "<=", ">=", "==", "!="]): # bug #9504: remember to not spacify a keyword: lastTokWasTerse = true # if not surrounded by whitespace, don't produce any whitespace either: diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 421a83c19..97fa91b3a 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 02d1e7d2a..f518b3abf 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 eda75f926..65fb2c5a3 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 |