Skip to content

Commit

Permalink
pretty: improve block/proc-arg formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed May 27, 2012
1 parent a9d9061 commit da2eb3e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions kernel/pretty.ay
Expand Up @@ -180,6 +180,24 @@ Atomy AST open:
grouped(n)


braces-block(contents, left = /empty) =
align(left <+> (lbrace <+> body(contents)) nest(2) <+> rbrace) <||>
if(left empty?)
then: align((lbrace <+> vbody(contents)) nest(2) <$> rbrace)
else: align(left <+> (lbrace <$> vbody(contents)) nest(2) <$> rbrace)

proc-arg(left, contents) =
if(from(.top)?)
then:
block =
(colon <+> body(contents)) <||>
(colon <$> vbody(contents))

align((left <> block) nest(2))
else:
braces-block(contents, left)


/doc(b: Infix) :=
from(.infix):
( if(b private)
Expand All @@ -189,31 +207,16 @@ Atomy AST open:
unamb(b left) <+> text(b operator) <\> unamb(b right)
) hang(2)

/doc(b: Block) := do:
args =
/doc(b: Block) :=
braces-block(
b contents
if(b arguments empty?)
then: empty
else: list(render-sequence(b arguments))

contents = body(b contents)

align(args <+> (lbrace </> contents) nest(2) <\> rbrace)
else: list(render-sequence(b arguments)))

/doc(c: Call) :=
from(.call) { unamb(c name) } <> tupled(render-sequence(c arguments))

proc-arg(left, contents) =
if(from(.top)?)
then:
block =
(colon <+> body(contents)) <||>
(colon <$> vbody(contents))

align((left <> block) nest(2))
else:
align((left <+> lbrace <\> body(contents)) nest(2) <\> rbrace)


/doc(`(~x [~*ys] { ~*zs })) :=
proc-arg(
from(.compose) { unamb(x) } <+>
Expand Down

0 comments on commit da2eb3e

Please sign in to comment.