Skip to content

Commit

Permalink
the line length (#26)
Browse files Browse the repository at this point in the history
* better line length tracker that takes into account comment newlines
* add newline to debug yaml
* fix missing pragma expr comments (pragmaexpr shouldn't have prefix)
* fix missing dedent after some end-of-statements
* fix some double/missing indents
  • Loading branch information
arnetheduck authored Jan 4, 2024
1 parent a8e3c27 commit bfc7db5
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 268 deletions.
4 changes: 1 addition & 3 deletions src/astcmp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# (c) Copyright 2023 Jacek Sieka
## Compare two AST's for semantic equivalence - aka undo whitespace bugs in the
## Nim parser / grammar
import
"$nim"/compiler/[ast, llstream, parser, idents, options, pathutils],
std/sequtils
import "$nim"/compiler/[ast, llstream, parser, idents, options, pathutils], std/sequtils

from std/math import isNaN

Expand Down
4 changes: 2 additions & 2 deletions src/nph.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ proc prettyPrint(infile, outfile: string, debug, check, printTokens: bool): int
if infile != "-":
if debug:
# Always write file in debug mode
writeFile(infile & ".nph.yaml", treeToYaml(nil, node))
writeFile(infile & ".nph.yaml", treeToYaml(nil, node) & "\n")
if infile != outfile:
writeFile(outfile, output)
writeFile(
outfile & ".nph.yaml",
treeToYaml(nil, parse(output, outfile, printTokens, newConfigRef())),
treeToYaml(nil, parse(output, outfile, printTokens, newConfigRef())) & "\n",
)
elif fileExists(outFile) and output == readFile(outFile):
# No formatting difference - don't touch file modificuation date
Expand Down
4 changes: 2 additions & 2 deletions src/phlineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ const
warnUnusedImportX: "imported and not used: '$1'",
warnInheritFromException:
"inherit from a more precise exception type like ValueError, " &
"IOError or OSError. If these don't suit, inherit from CatchableError or Defect.",
"IOError or OSError. If these don't suit, inherit from CatchableError or Defect.",
warnEachIdentIsTuple: "each identifier is a tuple",
warnUnsafeSetLen:
"setLen can potentially expand the sequence, " &
"but the element type '$1' doesn't have a valid default value",
"but the element type '$1' doesn't have a valid default value",
warnUnsafeDefault: "The '$1' type doesn't have a valid default value",
warnProveInit:
"Cannot prove that '$1' is initialized. This will become a compile time error in the future.",
Expand Down
8 changes: 4 additions & 4 deletions src/phparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ proc simpleExprAux(p: var Parser, limit: int, mode: PrimaryMode): PNode =
mode = pmNormal
if p.tok.tokType == tkCurlyDotLe and (p.tok.indent < 0 or realInd(p)) and
mode == pmNormal:
var pragmaExp = newNodeP(nkPragmaExpr, p)
var pragmaExp = newNodeP(nkPragmaExpr, p, withPrefix = false)
pragmaExp.add result
pragmaExp.add p.parsePragma
result = pragmaExp
Expand Down Expand Up @@ -1096,7 +1096,7 @@ proc identWithPragma(p: var Parser, allowDot = false): PNode =
#| identWithPragmaDot = identVisDot pragma?
var a = identVis(p, allowDot)
if p.tok.tokType == tkCurlyDotLe:
result = newNodeP(nkPragmaExpr, p)
result = newNodeP(nkPragmaExpr, p, withPrefix = false)
result.add(a)
result.add(parsePragma(p))
else:
Expand Down Expand Up @@ -1896,7 +1896,7 @@ proc parseIfOrWhen(p: var Parser, kind: TNodeKind): PNode =
branch.add(parseExpr(p))
branch.add(parseColComStmt(p, branch, clMid))
result.add(branch)
splitLookahead(p, branch, clPostfix)
splitLookahead(p, branch, p.currInd, clPostfix)
if p.tok.tokType != tkElif or not sameOrNoInd(p):
break
if p.tok.tokType == tkElse and sameOrNoInd(p):
Expand Down Expand Up @@ -2483,7 +2483,7 @@ proc parseTypeDef(p: var Parser): PNode =
else:
pragma = p.emptyNode
if pragma.kind != nkEmpty:
identPragma = newNodeP(nkPragmaExpr, p)
identPragma = newNodeP(nkPragmaExpr, p, withPrefix = false)
identPragma.add(identifier)
identPragma.add(pragma)

Expand Down
Loading

0 comments on commit bfc7db5

Please sign in to comment.