Skip to content

Commit

Permalink
the expression
Browse files Browse the repository at this point in the history
Clean up expressions so that they look better, take less space and don't
break as often.

* avoid placing `[`, `(` et al alone on a line
* avoid space around `..` et al
* consistently render stmt list expressions with parenthesis
  • Loading branch information
arnetheduck committed Dec 15, 2023
1 parent 5ef2305 commit 196306a
Show file tree
Hide file tree
Showing 25 changed files with 2,875 additions and 885 deletions.
11 changes: 6 additions & 5 deletions src/astcmp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ type
a*, b*: PNode

proc similarKinds(ak, bk: TNodeKind): bool =
ak == bk or (ak in {nkElseExpr, nkElse} and bk in {nkElseExpr, nkElse}) or
(ak in {nkElifExpr, nkElifBranch} and bk in {nkElifExpr, nkElifBranch})
ak == bk or (ak in {nkElseExpr, nkElse} and bk in {nkElseExpr, nkElse}) or (
ak in {nkElifExpr, nkElifBranch} and bk in {nkElifExpr, nkElifBranch}
)

proc equivalent*(a, b: PNode): Outcome =
if not similarKinds(a.kind, b.kind):
Expand Down Expand Up @@ -57,11 +58,11 @@ proc equivalent*(a, b: PNode): Outcome =

let eq =
case a.kind
of nkCharLit .. nkUInt64Lit:
of nkCharLit..nkUInt64Lit:
a.intVal == b.intVal
of nkFloatLit .. nkFloat128Lit:
of nkFloatLit..nkFloat128Lit:
a.floatVal == b.floatVal
of nkStrLit .. nkTripleStrLit:
of nkStrLit..nkTripleStrLit:
a.strVal == b.strVal
of nkSym:
raiseAssert "Shouldn't eixst in parser"
Expand Down
8 changes: 4 additions & 4 deletions src/astyaml.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proc addYamlString*(res: var string; s: string) =
res.add "\""
for c in s:
case c
of '\0' .. '\x1F', '\x7F' .. '\xFF':
of '\0'..'\x1F', '\x7F'..'\xFF':
res.add("\\u" & strutils.toHex(ord(c), 4))
of '\"', '\\':
res.add '\\' & c
Expand Down Expand Up @@ -156,11 +156,11 @@ proc treeToYamlAux(
if conf != nil:
res.addf("\n$1info: $2", [istr, lineInfoToStr(conf, n.info)])
case n.kind
of nkCharLit .. nkInt64Lit:
of nkCharLit..nkInt64Lit:
res.addf("\n$1intVal: $2", [istr, $(n.intVal)])
of nkFloatLit, nkFloat32Lit, nkFloat64Lit:
res.addf("\n$1floatVal: $2", [istr, n.floatVal.toStrMaxPrecision])
of nkStrLit .. nkTripleStrLit:
of nkStrLit..nkTripleStrLit:
res.addf("\n$1strVal: $2", [istr, makeYamlString(n.strVal)])
of nkSym:
res.addf("\n$1sym: ", [istr])
Expand All @@ -173,7 +173,7 @@ proc treeToYamlAux(
else:
if n.len > 0:
res.addf("\n$1sons: ", [istr])
for i in 0 ..< n.len:
for i in 0..<n.len:
res.addf("\n$1 - ", [istr])
res.treeToYamlAux(conf, n[i], marker, indent + 1, maxRecDepth - 1)
if n.typ != nil:
Expand Down
9 changes: 4 additions & 5 deletions src/nph.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
## Opinionated source code formatter

import
"."/
[
astcmp, astyaml, phast, phastalgo, phmsgs, phlineinfos, phoptions, phparser,
phrenderer
]
"."/[
astcmp, astyaml, phast, phastalgo, phmsgs, phlineinfos, phoptions, phparser,
phrenderer
]

import "$nim"/compiler/idents

Expand Down
Loading

0 comments on commit 196306a

Please sign in to comment.