Skip to content

Commit

Permalink
Keep section beginning on same line even if entry is long (#33)
Browse files Browse the repository at this point in the history
The section "short form" was restored to its 0.2 format to allow the
before-`=` part of the section to stay on the same line as the section
keyword.

This reduces the overall indent of the (long) RHS which gives it better
chances to be formatted nicely.
  • Loading branch information
arnetheduck authored Jan 26, 2024
1 parent a793758 commit 5bed5cf
Show file tree
Hide file tree
Showing 12 changed files with 1,124 additions and 1,204 deletions.
64 changes: 31 additions & 33 deletions src/astcmp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,41 +90,39 @@ proc equivalent*(a, b: PNode): Outcome =

return Outcome(kind: Different, a: a, b: b)

let
eq =
case a.kind
of nkCharLit .. nkUInt64Lit:
a.intVal == b.intVal
of nkFloatLit .. nkFloat128Lit:
(isNaN(a.floatVal) and isNaN(b.floatVal)) or a.floatVal == b.floatVal
of nkStrLit .. nkTripleStrLit:
a.strVal == b.strVal
of nkSym:
raiseAssert "Shouldn't eixst in parser"
of nkIdent:
a.ident.s == b.ident.s
else:
let
skipped =
if a.kind == nkStmtListExpr:
# When inserting a `;`, we might get some extra empty statements (?)
{nkEmpty, nkCommentStmt}
else:
{nkCommentStmt}
# TODO don't break comments!
let
af = a.sons.filterIt(it.kind notin skipped)
bf = b.sons.filterIt(it.kind notin skipped)

if af.len() != bf.len():
false
let eq =
case a.kind
of nkCharLit .. nkUInt64Lit:
a.intVal == b.intVal
of nkFloatLit .. nkFloat128Lit:
(isNaN(a.floatVal) and isNaN(b.floatVal)) or a.floatVal == b.floatVal
of nkStrLit .. nkTripleStrLit:
a.strVal == b.strVal
of nkSym:
raiseAssert "Shouldn't eixst in parser"
of nkIdent:
a.ident.s == b.ident.s
else:
let skipped =
if a.kind == nkStmtListExpr:
# When inserting a `;`, we might get some extra empty statements (?)
{nkEmpty, nkCommentStmt}
else:
for (aa, bb) in zip(af, bf):
let eq = equivalent(aa, bb)
if eq.kind == Different:
return eq
{nkCommentStmt}
# TODO don't break comments!
let
af = a.sons.filterIt(it.kind notin skipped)
bf = b.sons.filterIt(it.kind notin skipped)

if af.len() != bf.len():
false
else:
for (aa, bb) in zip(af, bf):
let eq = equivalent(aa, bb)
if eq.kind == Different:
return eq

true
true

if not eq:
Outcome(kind: Different, a: a, b: b)
Expand Down
Loading

0 comments on commit 5bed5cf

Please sign in to comment.