diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98c7067..0704bb2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,8 +68,8 @@ jobs: - name: Check formatting run: | - ! ./nph --check tests/before - ./nph --check tests/after + ! ./nph --check tests/before || echo "Failed before check" + ./nph --check tests/after || echo "Failed after check" ./nph src - git diff --exit-code + git diff --exit-code || echo "Failed diff" diff --git a/src/nph.nim b/src/nph.nim index e8169ca..15ed94c 100644 --- a/src/nph.nim +++ b/src/nph.nim @@ -76,7 +76,9 @@ proc prettyPrint(infile, outfile: string; debug, check, printTokens: bool): int if conf.errorCounter > 0: return ErrParseFailed - let output = renderTree(node, conf) & "\n" + var output = renderTree(node, conf) + if not output.endsWith("\n"): + output.add "\n" if conf.errorCounter > 0: return ErrParseFailed diff --git a/src/phlexer.nim b/src/phlexer.nim index 848b088..e58342b 100644 --- a/src/phlexer.nim +++ b/src/phlexer.nim @@ -1314,7 +1314,7 @@ proc bufMatches(L: Lexer; pos: int; chars: string): bool = true proc scanMultiLineComment( - L: var Lexer; tok: var Token; start: int; starter, ender: string; endOptional = true + L: var Lexer; tok: var Token; start: int; starter, ender: string; endOptional = false ) = var pos = start @@ -1324,7 +1324,9 @@ proc scanMultiLineComment( pos += 1 - var nesting = 0 + var + nesting = 0 + ended = false while true: if L.buf[pos] == nimlexbase.EndOfFile: if not endOptional: @@ -1334,22 +1336,32 @@ proc scanMultiLineComment( if L.bufMatches(pos, starter): nesting += 1 elif L.bufMatches(pos, ender): - if nesting == 0: - tok.literal.add ender + if nesting <= 0: + if endOptional: + ended = true + else: + tok.literal.add ender - pos += ender.len + pos += ender.len - break + break nesting -= 1 - tok.literal.add L.buf[pos] if L.buf[pos] in {CR, LF}: + if ended: + break + + tok.literal.add L.buf[pos] pos = handleCRLF(L, pos) else: + tok.literal.add L.buf[pos] pos += 1 - tokenEnd(tok, pos - 1) + if ended: + tokenEnd(tok, pos) + else: + tokenEnd(tok, pos - 1) L.bufpos = pos diff --git a/tests/after/fmtofffile.nim b/tests/after/fmtofffile.nim index d2d0835..22d882b 100644 --- a/tests/after/fmtofffile.nim +++ b/tests/after/fmtofffile.nim @@ -3,4 +3,3 @@ proc uglyFormat(hangingIndent: int, isVery: bool, ugly = true) - diff --git a/tests/after/fmtofffile.nim.nph.yaml b/tests/after/fmtofffile.nim.nph.yaml index fda9fb2..6f7c08d 100644 --- a/tests/after/fmtofffile.nim.nph.yaml +++ b/tests/after/fmtofffile.nim.nph.yaml @@ -1,4 +1,4 @@ kind: "nkStmtList" sons: - kind: "nkCommentStmt" - "comment": "#!fmt: off\u000A\u000Aproc uglyFormat(hangingIndent: int,\u000A isVery: bool,\u000A ugly = true)\u000A\u000A" \ No newline at end of file + "comment": "#!fmt: off\u000A\u000Aproc uglyFormat(hangingIndent: int,\u000A isVery: bool,\u000A ugly = true)\u000A" \ No newline at end of file