Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start development of a new pretty printer for Cadence programs #1024

Merged
merged 35 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ceb2c6
add prettier dependency
turbolent Jun 20, 2021
7eeaa68
prettier bool expression
turbolent Jun 20, 2021
00cf1da
prettier nil expression
turbolent Jun 20, 2021
fbe9a89
prettier string expression
turbolent Jun 20, 2021
50119d7
retain positive literal in integer and fixed-point expressions
turbolent Jun 20, 2021
880e530
prettier integer expression
turbolent Jun 20, 2021
86ca0a7
prettier fixed-point expression
turbolent Jun 20, 2021
60ac685
prettier array expression
turbolent Jun 20, 2021
34238f3
prettier dictionary expression
turbolent Jun 20, 2021
e1c5d67
prettier identifier expression
turbolent Jun 20, 2021
f510858
prettier invocation expression
turbolent Jun 20, 2021
2e42fc0
prettier member expression
turbolent Jun 20, 2021
fbea110
prettier index expression
turbolent Jun 20, 2021
78057b5
prettier path expression
turbolent Jun 20, 2021
96b1fe1
prettier conditional expression
turbolent Jun 20, 2021
706daa5
prettier unary expression
turbolent Jun 20, 2021
0750c31
prettier binary expression
turbolent Jun 20, 2021
5c665e3
prettier casting expression
turbolent Jun 20, 2021
2fbf5a7
prettier destroy expression
turbolent Jun 20, 2021
dab73bf
prettier create expression
turbolent Jun 20, 2021
6dae940
prettier reference expression
turbolent Jun 20, 2021
eb12f29
prettier force expression
turbolent Jun 20, 2021
e45a985
prettier function expression
turbolent Jun 20, 2021
6a48bb3
require Doc function for all expressions
turbolent Jun 20, 2021
eea7581
prettier return statement
turbolent Jun 20, 2021
5889fea
prettier transfer
turbolent Jun 20, 2021
aa0e3b9
add block and type helper functions
turbolent Jun 20, 2021
6a2c1f2
prettier variable declaration
turbolent Jun 20, 2021
4ebea08
add a tool for developing the pretty-printer
turbolent Jun 20, 2021
3295da0
add missing TODOs
turbolent Jun 20, 2021
e0f023e
lint
turbolent Jun 21, 2021
00f071b
add license header
turbolent Jun 25, 2021
5f92991
Merge branch 'master' into bastian/prettier
turbolent Nov 25, 2021
812b0f5
fix lint
turbolent Nov 25, 2021
13f0b32
rename dictionaryEntrySeparatorDoc to dictionaryKeyValueSeparatorDoc
turbolent Nov 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ require (
github.com/rivo/uniseg v0.2.0
github.com/schollz/progressbar/v3 v3.8.3
github.com/stretchr/testify v1.7.0
github.com/turbolent/prettier v0.0.0-20210613180524-3a3f5a5b49ba
go.uber.org/goleak v1.1.10
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/text v0.3.6
golang.org/x/tools v0.0.0-20200828161849-5deb26317202
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect

gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/turbolent/prettier v0.0.0-20210613180524-3a3f5a5b49ba h1:GPg+SVJURgCt6b4IwuRQupixdBM+KzjXPGvawnaQ15E=
github.com/turbolent/prettier v0.0.0-20210613180524-3a3f5a5b49ba/go.mod h1:Nlx5Y115XQvNcIdIy7dZXaNSUpzwBSge4/Ivk93/Yog=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -121,8 +123,9 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 15 additions & 0 deletions runtime/ast/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type Block struct {
Range
}

func (b *Block) IsEmpty() bool {
return len(b.Statements) == 0
}

func (b *Block) Accept(visitor Visitor) Repr {
return visitor.VisitBlock(b)
}
Expand Down Expand Up @@ -54,6 +58,13 @@ type FunctionBlock struct {
PostConditions *Conditions `json:",omitempty"`
}

func (b *FunctionBlock) IsEmpty() bool {
return b == nil ||
(b.Block.IsEmpty() &&
b.PreConditions.IsEmpty() &&
b.PostConditions.IsEmpty())
}

func (b *FunctionBlock) Accept(visitor Visitor) Repr {
return visitor.VisitFunctionBlock(b)
}
Expand Down Expand Up @@ -96,3 +107,7 @@ type Condition struct {
// Conditions

type Conditions []*Condition

func (c *Conditions) IsEmpty() bool {
return c == nil || len(*c) == 0
}
Loading