Skip to content

Commit 414b6be

Browse files
committed
Add reformatter, fix #73
1 parent 012492e commit 414b6be

File tree

132 files changed

+5152
-1920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+5152
-1920
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ Makefile text
1515
# These tests are explicitly given specific line endings
1616
test_suite/unix_line_endings.jsonnet text eol=lf
1717
test_suite/dos_line_endings.jsonnet text eol=crlf
18-

BUILD

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ genrule(
1717
cc_library(
1818
name = "jsonnet-common",
1919
srcs = [
20-
"core/desugaring.cpp",
20+
"core/desugarer.cpp",
21+
"core/formatter.cpp",
2122
"core/lexer.cpp",
2223
"core/parser.cpp",
2324
"core/static_analysis.cpp",
25+
"core/string_utils.cpp",
2426
"core/vm.cpp",
2527
"core/std.jsonnet.h",
2628
],
2729
hdrs = [
2830
"core/ast.h",
29-
"core/desugaring.h",
31+
"core/desugarer.h",
32+
"core/formatter.h",
3033
"core/lexer.h",
3134
"core/parser.h",
3235
"core/state.h",
3336
"core/static_analysis.h",
3437
"core/static_error.h",
38+
"core/string_utils.h",
3539
"core/unicode.h",
3640
"core/vm.h",
3741
"include/libjsonnet.h",

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ SHARED_LDFLAGS ?= -shared
4242
################################################################################
4343

4444
LIB_SRC = \
45-
core/desugaring.cpp \
45+
core/desugarer.cpp \
46+
core/formatter.cpp \
4647
core/lexer.cpp \
4748
core/libjsonnet.cpp \
4849
core/parser.cpp \
4950
core/static_analysis.cpp \
51+
core/string_utils.cpp \
5052
core/vm.cpp
5153
LIB_OBJ = $(LIB_SRC:.cpp=.o)
5254

@@ -60,12 +62,14 @@ ALL = \
6062
$(LIB_OBJ)
6163
ALL_HEADERS = \
6264
core/ast.h \
63-
core/desugaring.h \
65+
core/desugarer.h \
66+
core/formatter.h \
6467
core/lexer.h \
6568
core/parser.h \
6669
core/state.h \
6770
core/static_analysis.h \
6871
core/static_error.h \
72+
core/string_utils.h \
6973
core/vm.h \
7074
core/std.jsonnet.h \
7175
include/libjsonnet.h
@@ -82,7 +86,7 @@ test: jsonnet libjsonnet.so libjsonnet_test_snippet libjsonnet_test_file
8286
cd examples ; ./check.sh
8387
cd examples/terraform ; ./check.sh
8488
cd test_suite ; ./run_tests.sh
85-
cd test_suite ; ./run_unparse_tests.sh
89+
cd test_suite ; ./run_fmt_tests.sh
8690

8791
MAKEDEPEND_SRCS = \
8892
cmd/jsonnet.cpp \
@@ -92,7 +96,7 @@ MAKEDEPEND_SRCS = \
9296
depend:
9397
makedepend -f- $(LIB_SRC) $(MAKEDEPEND_SRCS) > Makefile.depend
9498

95-
core/desugaring.cpp: core/std.jsonnet.h
99+
core/desugarer.cpp: core/std.jsonnet.h
96100

97101
# Object files
98102
%.o: %.cpp

benchmarks/bench.01.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ local sum(x) =
1818
if x == 0 then
1919
0
2020
else
21-
x + sum(x-1);
21+
x + sum(x - 1);
2222
sum(300)

benchmarks/bench.02.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
local Fib = {
1818
n: 1,
1919
local outer = self,
20-
r: if self.n <= 1 then 1 else (Fib { n: outer.n - 1}).r + (Fib { n: outer.n - 2}).r
20+
r: if self.n <= 1 then 1 else (Fib { n: outer.n - 1 }).r + (Fib { n: outer.n - 2 }).r,
2121
};
2222

2323
(Fib { n: 25 }).r

case_studies/fractal/service.jsonnet

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local credentials = import "credentials.jsonnet";
4545
seed_provider: [
4646
{
4747
class_name: "org.apache.cassandra.locator.SimpleSeedProvider",
48-
parameters: [ { seeds: std.join(", ", cassandraNodes) } ],
48+
parameters: [{ seeds: std.join(", ", cassandraNodes) }],
4949
},
5050
],
5151
},
@@ -100,17 +100,17 @@ local credentials = import "credentials.jsonnet";
100100

101101
// For debugging:
102102
local network_debug = ["traceroute", "lsof", "iptraf", "tcpdump", "host", "dnsutils"],
103-
aptPackages +: ["vim", "git", "psmisc", "screen", "strace" ] + network_debug,
103+
aptPackages+: ["vim", "git", "psmisc", "screen", "strace"] + network_debug,
104104
},
105105

106106
// Frontend image.
107107
"appserv.packer.json": packer.GcpDebianNginxUwsgiFlaskImage + ImageMixin {
108108
name: "appserv-v20150430-2145",
109-
module: "main", // Entrypoint in the Python code.
110-
pipPackages +: ["httplib2", "cassandra-driver", "blist"],
111-
uwsgiConf +: { lazy: "true" }, // cassandra-driver does not survive fork()
109+
module: "main", // Entrypoint in the Python code.
110+
pipPackages+: ["httplib2", "cassandra-driver", "blist"],
111+
uwsgiConf+: { lazy: "true" }, // cassandra-driver does not survive fork()
112112
// Copy website content and code.
113-
provisioners +: [
113+
provisioners+: [
114114
packer.File {
115115
source: "appserv",
116116
destination: "/tmp/",
@@ -134,12 +134,12 @@ local credentials = import "credentials.jsonnet";
134134
name: "tilegen-v20150430-2145",
135135
module: "mandelbrot_service",
136136

137-
aptPackages +: ["g++", "libpng-dev"],
137+
aptPackages+: ["g++", "libpng-dev"],
138138

139139
port: tilegenPort,
140140

141141
// Copy the flask handlers and also build the C++ executable.
142-
provisioners +: [
142+
provisioners+: [
143143
packer.File {
144144
source: "tilegen",
145145
destination: "/tmp/",
@@ -168,7 +168,7 @@ local credentials = import "credentials.jsonnet";
168168
account_file: "service_account_key.json",
169169
project: credentials.project,
170170
region: "us-central1",
171-
}
171+
},
172172
},
173173

174174
// The deployed resources.
@@ -213,12 +213,12 @@ local credentials = import "credentials.jsonnet";
213213
appserv: {
214214
name: "appserv",
215215
health_checks: ["${google_compute_http_health_check.appserv.name}"],
216-
instances: [ "%s/appserv%d" % [zone(k), k] for k in [1, 2, 3] ],
216+
instances: ["%s/appserv%d" % [zone(k), k] for k in [1, 2, 3]],
217217
},
218218
tilegen: {
219219
name: "tilegen",
220220
health_checks: ["${google_compute_http_health_check.tilegen.name}"],
221-
instances: [ "%s/tilegen%d" % [zone(k), k] for k in [1, 2, 3, 4, 5] ],
221+
instances: ["%s/tilegen%d" % [zone(k), k] for k in [1, 2, 3, 4, 5]],
222222
},
223223
},
224224

@@ -234,12 +234,12 @@ local credentials = import "credentials.jsonnet";
234234
name: "tilegen",
235235
target: "${google_compute_target_pool.tilegen.self_link}",
236236
port_range: tilegenPort,
237-
}
237+
},
238238
},
239239

240240
// Open ports for the various services, to instances (identified by tags)
241241
google_compute_firewall: {
242-
local NetworkMixin = { network: "${google_compute_network.fractal.name}", },
242+
local NetworkMixin = { network: "${google_compute_network.fractal.name}" },
243243
ssh: terraform.GcpFirewallSsh + NetworkMixin { name: "ssh" },
244244
appserv: terraform.GcpFirewallHttp + NetworkMixin { name: "appserv" },
245245
tilegen: terraform.GcpFirewallHttp + NetworkMixin { name: "tilegen", port: tilegenPort },
@@ -249,17 +249,17 @@ local credentials = import "credentials.jsonnet";
249249

250250
// All our instances share this configuration.
251251
local FractalInstance(zone_hash) = terraform.GcpInstance {
252-
network_interface: [super.network_interface[0] + {network: "${google_compute_network.fractal.name}"} ],
253-
tags +: ["fractal"],
252+
network_interface: [super.network_interface[0] { network: "${google_compute_network.fractal.name}" }],
253+
tags+: ["fractal"],
254254
zone: zone(zone_hash),
255-
scopes +: ["devstorage.full_control"]
255+
scopes+: ["devstorage.full_control"],
256256
},
257257

258258
// The various kinds of Cassandra instances all share this basic configuration.
259259
local CassandraInstance(zone_hash) = FractalInstance(zone_hash) {
260260
image: "cassandra-v20150430-2145",
261261
machine_type: "n1-standard-1",
262-
tags +: ["fractal-db", "cassandra-server"],
262+
tags+: ["fractal-db", "cassandra-server"],
263263
user:: cassandraUser,
264264
userPass:: credentials.cassandraUserPass,
265265
rootPass:: credentials.cassandraRootPass,
@@ -279,8 +279,8 @@ local credentials = import "credentials.jsonnet";
279279
database_user: cassandraUser,
280280
database_pass: credentials.cassandraUserPass,
281281
},
282-
tags +: ["fractal-appserv", "http-server"],
283-
startup_script +: [self.addFile(self.conf, "/var/www/conf.json")],
282+
tags+: ["fractal-appserv", "http-server"],
283+
startup_script+: [self.addFile(self.conf, "/var/www/conf.json")],
284284
}
285285
for k in [1, 2, 3]
286286

@@ -326,8 +326,8 @@ local credentials = import "credentials.jsonnet";
326326
["tilegen" + k]: FractalInstance(k) {
327327
name: "tilegen" + k,
328328
image: "tilegen-v20150430-2145",
329-
tags +: ["fractal-tilegen", "http-server"],
330-
startup_script +: [self.addFile(ApplicationConf, "/var/www/conf.json")],
329+
tags+: ["fractal-tilegen", "http-server"],
330+
startup_script+: [self.addFile(ApplicationConf, "/var/www/conf.json")],
331331
}
332332
for k in [1, 2, 3, 4]
333333
},
@@ -337,7 +337,7 @@ local credentials = import "credentials.jsonnet";
337337
name: "fractaldemo-com",
338338
dns_name: credentials.dnsPrefix + "fractaldemo.com.",
339339
description: "Fractal Demo DNS Zone",
340-
}
340+
},
341341
},
342342

343343
local instances = self.google_compute_instance,
@@ -374,14 +374,14 @@ local credentials = import "credentials.jsonnet";
374374
ttl: 300,
375375
rrdatas: ["${google_compute_address.appserv.address}"],
376376
},
377-
}
377+
},
378378

379379
},
380380

381381
output: {
382-
"frontend": { value: "${google_compute_address.appserv.address}" },
382+
frontend: { value: "${google_compute_address.appserv.address}" },
383383
},
384384

385-
} // terraform.tf
385+
}, // terraform.tf
386386

387387
}

case_studies/kubernetes/example.jsonnet

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local Kube = import "libkube.jsonnet";
1717
{
1818

1919
# The port that this service should serve on.
20-
redis_port:: 6379,
20+
redis_port:: 6379,
2121
# Change this to your project ID.
2222
project_id:: "cooltool-1009",
2323

@@ -38,8 +38,8 @@ local Kube = import "libkube.jsonnet";
3838
template: {
3939
metadata: {
4040
labels: {
41-
name: "twitter-stream"
42-
}
41+
name: "twitter-stream",
42+
},
4343
},
4444
spec: {
4545
containers: [
@@ -55,11 +55,11 @@ local Kube = import "libkube.jsonnet";
5555
ACCESSTOKENSEC: $.twitter_access_token_sec,
5656
TWSTREAMMODE: "sample",
5757
}),
58-
}
59-
]
60-
}
61-
}
62-
}
58+
},
59+
],
60+
},
61+
},
62+
},
6363
},
6464
"redis-master-service.new.yaml": Kube.v1.Service("redis-master") {
6565
metadata+: {
@@ -72,12 +72,12 @@ local Kube = import "libkube.jsonnet";
7272
# You don't need to specify the targetPort if it is the same as the port,
7373
# though here we include it anyway, to show the syntax.
7474
targetPort: $.redis_port,
75-
}
75+
},
7676
],
7777
selector: {
7878
name: "redis-master",
79-
}
80-
}
79+
},
80+
},
8181
},
8282
"redis-master.new.yaml": Kube.v1.ReplicationController("redis-master") {
8383
spec: {
@@ -86,7 +86,7 @@ local Kube = import "libkube.jsonnet";
8686
metadata: {
8787
labels: {
8888
name: "redis-master",
89-
}
89+
},
9090
},
9191
spec: {
9292
containers: [
@@ -103,11 +103,11 @@ local Kube = import "libkube.jsonnet";
103103
name: "collectd",
104104
image: "gcr.io/%s/collectd-redis:latest" % $.project_id,
105105
ports: [],
106-
}
107-
]
108-
}
109-
}
110-
}
106+
},
107+
],
108+
},
109+
},
110+
},
111111
},
112112
"bigquery-controller.new.yaml": Kube.v1.ReplicationController("bigquery-controller") {
113113
spec: {
@@ -116,7 +116,7 @@ local Kube = import "libkube.jsonnet";
116116
metadata: {
117117
labels: {
118118
name: "bigquery-controller",
119-
}
119+
},
120120
},
121121
spec: {
122122
containers: [
@@ -131,10 +131,10 @@ local Kube = import "libkube.jsonnet";
131131
BQ_DATASET: $.bq_dataset,
132132
BQ_TABLE: $.bq_table,
133133
}),
134-
}
135-
]
136-
}
137-
}
138-
}
139-
}
134+
},
135+
],
136+
},
137+
},
138+
},
139+
},
140140
}

case_studies/kubernetes/libkube.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535

3636
Service(name): ApiVersion + Metadata(name) {
3737
kind: "Service",
38-
}
38+
},
3939
},
4040

4141
pair_list_ex(tab, kfield, vfield)::
42-
[{[kfield]: k, [vfield]: tab[k]} for k in std.objectFields(tab)],
42+
[{ [kfield]: k, [vfield]: tab[k] } for k in std.objectFields(tab)],
4343

4444
pair_list(tab)::
4545
self.pair_list_ex(tab, "name", "value"),

0 commit comments

Comments
 (0)