From 0b1d1b7886396d943a54843c63e4dc0604db0cdb Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 3 Nov 2022 16:18:09 +0800 Subject: fixes #15688; handle `strongSpace` overflow issues (#20724) * fixes #15688; handle `strongSpace` overflow issues * stop at 1 * change the type of strongSpaceA to bool --- compiler/parser.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'compiler/parser.nim') diff --git a/compiler/parser.nim b/compiler/parser.nim index 990f7dfef..19600f686 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -301,13 +301,13 @@ proc isUnary(tok: Token): bool = ## Check if the given token is a unary operator tok.tokType in {tkOpr, tkDotDot} and tok.strongSpaceB == 0 and - tok.strongSpaceA > 0 + tok.strongSpaceA proc checkBinary(p: Parser) {.inline.} = ## Check if the current parser token is a binary operator. # we don't check '..' here as that's too annoying if p.tok.tokType == tkOpr: - if p.tok.strongSpaceB > 0 and p.tok.strongSpaceA == 0: + if p.tok.strongSpaceB > 0 and not p.tok.strongSpaceA: parMessage(p, warnInconsistentSpacing, prettyTok(p.tok)) #| module = stmt ^* (';' / IND{=}) @@ -477,7 +477,7 @@ proc dotExpr(p: var Parser, a: PNode): PNode = optInd(p, result) result.add(a) result.add(parseSymbol(p, smAfterDot)) - if p.tok.tokType == tkBracketLeColon and p.tok.strongSpaceA <= 0: + if p.tok.tokType == tkBracketLeColon and not p.tok.strongSpaceA: var x = newNodeI(nkBracketExpr, p.parLineInfo) # rewrite 'x.y[:z]()' to 'y[z](x)' x.add result[1] @@ -486,7 +486,7 @@ proc dotExpr(p: var Parser, a: PNode): PNode = var y = newNodeI(nkCall, p.parLineInfo) y.add x y.add result[0] - if p.tok.tokType == tkParLe and p.tok.strongSpaceA <= 0: + if p.tok.tokType == tkParLe and not p.tok.strongSpaceA: exprColonEqExprListAux(p, tkParRi, y) result = y @@ -842,7 +842,7 @@ proc primarySuffix(p: var Parser, r: PNode, case p.tok.tokType of tkParLe: # progress guaranteed - if p.tok.strongSpaceA > 0: + if p.tok.strongSpaceA: result = commandExpr(p, result, mode) # type sections allow full command syntax if mode == pmTypeDef: @@ -861,13 +861,13 @@ proc primarySuffix(p: var Parser, r: PNode, result = parseGStrLit(p, result) of tkBracketLe: # progress guaranteed - if p.tok.strongSpaceA > 0: + if p.tok.strongSpaceA: result = commandExpr(p, result, mode) break result = namedParams(p, result, nkBracketExpr, tkBracketRi) of tkCurlyLe: # progress guaranteed - if p.tok.strongSpaceA > 0: + if p.tok.strongSpaceA: result = commandExpr(p, result, mode) break result = namedParams(p, result, nkCurlyExpr, tkCurlyRi) @@ -2386,7 +2386,7 @@ proc parseAll(p: var Parser): PNode = parMessage(p, errInvalidIndentation) proc checkFirstLineIndentation*(p: var Parser) = - if p.tok.indent != 0 and p.tok.strongSpaceA > 0: + if p.tok.indent != 0 and p.tok.strongSpaceA: parMessage(p, errInvalidIndentation) proc parseTopLevelStmt(p: var Parser): PNode = -- cgit 1.4.1-2-gfad0