aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-01-01 01:39:18 +0000
committerMichael Williamson <mike@zwobble.org>2025-01-01 09:45:58 +0000
commitb65c719e2b65a9662b6170b0b53dfed9f1a3edcd (patch)
tree6700b1a717d01a83b644dd06eb508e12a43b492c
parent0df6725da8a0953c5643c5692c5244826e448d09 (diff)
Use JSON5 instead of TOML for config
-rw-r--r--examples-perf/01-fibonacci/shed.json528
-rw-r--r--examples-perf/01-fibonacci/shed.toml21
-rw-r--r--examples/00-missing-main/shed.json514
-rw-r--r--examples/00-missing-main/shed.toml7
-rw-r--r--examples/01-true/shed.json514
-rw-r--r--examples/01-true/shed.toml7
-rw-r--r--examples/02-hello-world/shed.json514
-rw-r--r--examples/02-hello-world/shed.toml7
-rw-r--r--examples/03-val/shed.json514
-rw-r--r--examples/03-val/shed.toml7
-rw-r--r--examples/04-val-as-namespace-statement/shed.json514
-rw-r--r--examples/04-val-as-namespace-statement/shed.toml7
-rw-r--r--examples/05-string-add/shed.json514
-rw-r--r--examples/05-string-add/shed.toml7
-rw-r--r--examples/06-if/shed.json514
-rw-r--r--examples/06-if/shed.toml7
-rw-r--r--examples/07-mutual-recursion/shed.json514
-rw-r--r--examples/07-mutual-recursion/shed.toml7
-rw-r--r--examples/08-blocks/shed.json514
-rw-r--r--examples/08-blocks/shed.toml7
-rw-r--r--examples/09-var/shed.json514
-rw-r--r--examples/09-var/shed.toml7
-rw-r--r--examples/10-while/shed.json514
-rw-r--r--examples/10-while/shed.toml7
-rw-r--r--examples/11-tuples/shed.json514
-rw-r--r--examples/11-tuples/shed.toml7
-rw-r--r--examples/12-named-args/shed.json514
-rw-r--r--examples/12-named-args/shed.toml7
-rw-r--r--examples/13-target-ignore/shed.json514
-rw-r--r--examples/13-target-ignore/shed.toml7
-rw-r--r--examples/14-structs/shed.json514
-rw-r--r--examples/14-structs/shed.toml7
-rw-r--r--examples/15-struct-hoisting/shed.json514
-rw-r--r--examples/15-struct-hoisting/shed.toml7
-rw-r--r--examples/16-struct-positional-fields/shed.json514
-rw-r--r--examples/16-struct-positional-fields/shed.toml7
-rw-r--r--examples/17-sums/shed.json514
-rw-r--r--examples/17-sums/shed.toml7
-rw-r--r--examples/18-import/shed.json514
-rw-r--r--examples/18-import/shed.toml7
-rw-r--r--examples/19-function-expression/shed.json514
-rw-r--r--examples/19-function-expression/shed.toml7
-rw-r--r--examples/20-function-expression-infer-return-type/shed.json514
-rw-r--r--examples/20-function-expression-infer-return-type/shed.toml7
-rw-r--r--examples/21-function-expression-infer-param-type/shed.json514
-rw-r--r--examples/21-function-expression-infer-param-type/shed.toml7
-rw-r--r--examples/22-effect-resume/shed.json514
-rw-r--r--examples/22-effect-resume/shed.toml7
-rw-r--r--examples/23-effect-resume-with-value/shed.json514
-rw-r--r--examples/23-effect-resume-with-value/shed.toml7
-rw-r--r--examples/24-effect-with-state/shed.json514
-rw-r--r--examples/24-effect-with-state/shed.toml7
-rw-r--r--examples/25-effect-handler-pop/shed.json514
-rw-r--r--examples/25-effect-handler-pop/shed.toml7
-rw-r--r--examples/26-effect-handler-pop-on-return/shed.json514
-rw-r--r--examples/26-effect-handler-pop-on-return/shed.toml7
-rw-r--r--examples/27-effect-handler-nested/shed.json514
-rw-r--r--examples/27-effect-handler-nested/shed.toml7
-rw-r--r--examples/28-effect-in-handler/shed.json514
-rw-r--r--examples/28-effect-in-handler/shed.toml7
-rw-r--r--examples/29-effect-break/shed.json514
-rw-r--r--examples/29-effect-break/shed.toml7
-rw-r--r--examples/30-generic-structs/shed.json514
-rw-r--r--examples/30-generic-structs/shed.toml7
-rw-r--r--examples/31-generic-sums/shed.json514
-rw-r--r--examples/31-generic-sums/shed.toml7
-rw-r--r--examples/32-generic-structs-and-sums-inferred-type-args/shed.json514
-rw-r--r--examples/32-generic-structs-and-sums-inferred-type-args/shed.toml7
-rw-r--r--examples/33-generic-functions/shed.json514
-rw-r--r--examples/33-generic-functions/shed.toml7
-rw-r--r--examples/34-generic-effects/shed.json514
-rw-r--r--examples/34-generic-effects/shed.toml7
-rw-r--r--examples/35-struct-methods/shed.json514
-rw-r--r--examples/35-struct-methods/shed.toml7
-rw-r--r--examples/36-struct-method-references/shed.json514
-rw-r--r--examples/36-struct-method-references/shed.toml7
-rw-r--r--examples/37-generic-struct-methods/shed.json514
-rw-r--r--examples/37-generic-struct-methods/shed.toml7
-rw-r--r--pom.xml5
-rw-r--r--src/main/java/org/shedlang/compiler/config/BinConfig.java8
-rw-r--r--src/main/java/org/shedlang/compiler/config/ExampleConfig.java12
-rw-r--r--src/main/java/org/shedlang/compiler/config/GcConfig.java8
-rw-r--r--src/main/java/org/shedlang/compiler/config/GcMarkAndSweepConfig.java6
-rw-r--r--src/main/java/org/shedlang/compiler/config/ProfileConfig.java13
-rw-r--r--src/main/java/org/shedlang/compiler/config/ProjectConfig.java42
-rw-r--r--src/main/java/org/shedlang/compiler/config/errors/Json5SyntaxConfigError.java19
-rw-r--r--src/main/java/org/shedlang/compiler/config/errors/TomlSyntaxConfigError.java19
-rw-r--r--src/main/java/org/shedlang/compiler/config/errors/UnexpectedTypeConfigError.java38
-rw-r--r--src/main/java/org/shedlang/compiler/config/json/Json5ObjectWithSource.java170
-rw-r--r--src/main/java/org/shedlang/compiler/config/json/Json5Path.java36
-rw-r--r--src/main/java/org/shedlang/compiler/config/json/Json5Source.java18
-rw-r--r--src/main/java/org/shedlang/compiler/config/json/Json5StringWithSource.java28
-rw-r--r--src/main/java/org/shedlang/compiler/config/toml/TomlPath.java35
-rw-r--r--src/main/java/org/shedlang/compiler/config/toml/TomlSource.java20
-rw-r--r--src/main/java/org/shedlang/compiler/config/toml/TomlString.java6
-rw-r--r--src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java214
-rw-r--r--src/test/java/org/shedlang/compiler/config/BinConfigTests.java24
-rw-r--r--src/test/java/org/shedlang/compiler/config/GcConfigTests.java28
-rw-r--r--src/test/java/org/shedlang/compiler/config/GcMarkAndSweepConfigTests.java14
-rw-r--r--src/test/java/org/shedlang/compiler/config/ProfileConfigTests.java24
-rw-r--r--src/test/java/org/shedlang/compiler/config/ProjectConfigTests.java164
-rw-r--r--src/test/java/org/shedlang/compiler/config/json/Json5ObjectWithSourceTests.java406
-rw-r--r--src/test/java/org/shedlang/compiler/config/toml/TomlTableWithSourceTests.java325
103 files changed, 1447 insertions, 1082 deletions
diff --git a/examples-perf/01-fibonacci/shed.json5 b/examples-perf/01-fibonacci/shed.json5
new file mode 100644
index 00000000..22161a5e
--- /dev/null
+++ b/examples-perf/01-fibonacci/shed.json5
@@ -0,0 +1,28 @@
+{
+ bins: [
+ {
+ name: "fibonacci",
+ mainNamespace: "Fibonacci",
+ },
+ ],
+ examples: [
+ {
+ bin: "fibonacci",
+ expectedOutput: "success",
+ },
+ ],
+ "profiles": [
+ {
+ name: "gc-bump",
+ gc: {name: "bump"},
+ },
+ {
+ name: "gc-mark-and-sweep",
+ gc: {name: "mark-and-sweep", collectInterval: 10000},
+ },
+ {
+ name: "gc-mark-and-sweep-always-collect",
+ gc: {name: "mark-and-sweep", collectInterval: 1},
+ }
+ ],
+}
diff --git a/examples-perf/01-fibonacci/shed.toml b/examples-perf/01-fibonacci/shed.toml
deleted file mode 100644
index 68dcaf5a..00000000
--- a/examples-perf/01-fibonacci/shed.toml
+++ /dev/null
@@ -1,21 +0,0 @@
-[[shed.bins]]
-name = "fibonacci"
-main-namespace = "Fibonacci"
-
-[[shed.examples]]
-bin = "fibonacci"
-expected-output = "success"
-
-[[shed.profiles]]
-name = "gc-bump"
-gc.name = "bump"
-
-[[shed.profiles]]
-name = "gc-mark-and-sweep"
-gc.name = "mark-and-sweep"
-gc.collect-interval = 10000
-
-[[shed.profiles]]
-name = "gc-mark-and-sweep-always-collect"
-gc.name = "mark-and-sweep"
-gc.collect-interval = 1
diff --git a/examples/00-missing-main/shed.json5 b/examples/00-missing-main/shed.json5
new file mode 100644
index 00000000..f7af8927
--- /dev/null
+++ b/examples/00-missing-main/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "true",
+ mainNamespace: "True",
+ },
+ ],
+ examples: [
+ {
+ bin: "true",
+ expectedError: "Namespace True has no field main",
+ },
+ ],
+}
diff --git a/examples/00-missing-main/shed.toml b/examples/00-missing-main/shed.toml
deleted file mode 100644
index c01af0d7..00000000
--- a/examples/00-missing-main/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "true"
-main-namespace = "True"
-
-[[shed.examples]]
-bin = "true"
-expected-error = "Namespace True has no field main"
diff --git a/examples/01-true/shed.json5 b/examples/01-true/shed.json5
new file mode 100644
index 00000000..a6d9b992
--- /dev/null
+++ b/examples/01-true/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "true",
+ mainNamespace: "True",
+ },
+ ],
+ examples: [
+ {
+ bin: "true",
+ expectedOutput: "",
+ },
+ ],
+}
diff --git a/examples/01-true/shed.toml b/examples/01-true/shed.toml
deleted file mode 100644
index 9acf2972..00000000
--- a/examples/01-true/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "true"
-main-namespace = "True"
-
-[[shed.examples]]
-bin = "true"
-expected-output = ""
diff --git a/examples/02-hello-world/shed.json5 b/examples/02-hello-world/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/02-hello-world/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/02-hello-world/shed.toml b/examples/02-hello-world/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/02-hello-world/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/03-val/shed.json5 b/examples/03-val/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/03-val/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/03-val/shed.toml b/examples/03-val/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/03-val/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/04-val-as-namespace-statement/shed.json5 b/examples/04-val-as-namespace-statement/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/04-val-as-namespace-statement/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/04-val-as-namespace-statement/shed.toml b/examples/04-val-as-namespace-statement/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/04-val-as-namespace-statement/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/05-string-add/shed.json5 b/examples/05-string-add/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/05-string-add/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/05-string-add/shed.toml b/examples/05-string-add/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/05-string-add/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/06-if/shed.json5 b/examples/06-if/shed.json5
new file mode 100644
index 00000000..bf2e41bc
--- /dev/null
+++ b/examples/06-if/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "counting",
+ mainNamespace: "Counting",
+ },
+ ],
+ examples: [
+ {
+ bin: "counting",
+ expectedOutput: "one\ntwo\nmany",
+ },
+ ],
+}
diff --git a/examples/06-if/shed.toml b/examples/06-if/shed.toml
deleted file mode 100644
index 1f0949cd..00000000
--- a/examples/06-if/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "counting"
-main-namespace = "Counting"
-
-[[shed.examples]]
-bin = "counting"
-expected-output = "one\ntwo\nmany"
diff --git a/examples/07-mutual-recursion/shed.json5 b/examples/07-mutual-recursion/shed.json5
new file mode 100644
index 00000000..bc0776a5
--- /dev/null
+++ b/examples/07-mutual-recursion/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "mutual-recursion",
+ mainNamespace: "MutualRecursion",
+ },
+ ],
+ examples: [
+ {
+ bin: "mutual-recursion",
+ expectedOutput: "ababa",
+ },
+ ],
+}
diff --git a/examples/07-mutual-recursion/shed.toml b/examples/07-mutual-recursion/shed.toml
deleted file mode 100644
index e30e4462..00000000
--- a/examples/07-mutual-recursion/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "mutual-recursion"
-main-namespace = "MutualRecursion"
-
-[[shed.examples]]
-bin = "mutual-recursion"
-expected-output = "ababa"
diff --git a/examples/08-blocks/shed.json5 b/examples/08-blocks/shed.json5
new file mode 100644
index 00000000..7d7719ad
--- /dev/null
+++ b/examples/08-blocks/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "counting",
+ mainNamespace: "Counting",
+ },
+ ],
+ examples: [
+ {
+ bin: "counting",
+ expectedOutput: "count=one\ncount=two\ncount=many",
+ },
+ ],
+}
diff --git a/examples/08-blocks/shed.toml b/examples/08-blocks/shed.toml
deleted file mode 100644
index b7a54fd6..00000000
--- a/examples/08-blocks/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "counting"
-main-namespace = "Counting"
-
-[[shed.examples]]
-bin = "counting"
-expected-output = "count=one\ncount=two\ncount=many"
diff --git a/examples/09-var/shed.json5 b/examples/09-var/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/09-var/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/09-var/shed.toml b/examples/09-var/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/09-var/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/10-while/shed.json5 b/examples/10-while/shed.json5
new file mode 100644
index 00000000..bf2e41bc
--- /dev/null
+++ b/examples/10-while/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "counting",
+ mainNamespace: "Counting",
+ },
+ ],
+ examples: [
+ {
+ bin: "counting",
+ expectedOutput: "one\ntwo\nmany",
+ },
+ ],
+}
diff --git a/examples/10-while/shed.toml b/examples/10-while/shed.toml
deleted file mode 100644
index 1f0949cd..00000000
--- a/examples/10-while/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "counting"
-main-namespace = "Counting"
-
-[[shed.examples]]
-bin = "counting"
-expected-output = "one\ntwo\nmany"
diff --git a/examples/11-tuples/shed.json5 b/examples/11-tuples/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/11-tuples/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/11-tuples/shed.toml b/examples/11-tuples/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/11-tuples/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/12-named-args/shed.json5 b/examples/12-named-args/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/12-named-args/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/12-named-args/shed.toml b/examples/12-named-args/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/12-named-args/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/13-target-ignore/shed.json5 b/examples/13-target-ignore/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/13-target-ignore/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/13-target-ignore/shed.toml b/examples/13-target-ignore/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/13-target-ignore/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/14-structs/shed.json5 b/examples/14-structs/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/14-structs/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/14-structs/shed.toml b/examples/14-structs/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/14-structs/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/15-struct-hoisting/shed.json5 b/examples/15-struct-hoisting/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/15-struct-hoisting/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/15-struct-hoisting/shed.toml b/examples/15-struct-hoisting/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/15-struct-hoisting/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/16-struct-positional-fields/shed.json5 b/examples/16-struct-positional-fields/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/16-struct-positional-fields/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/16-struct-positional-fields/shed.toml b/examples/16-struct-positional-fields/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/16-struct-positional-fields/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/17-sums/shed.json5 b/examples/17-sums/shed.json5
new file mode 100644
index 00000000..ef44c0ca
--- /dev/null
+++ b/examples/17-sums/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "Some(hello, world!)\nNone",
+ },
+ ],
+}
diff --git a/examples/17-sums/shed.toml b/examples/17-sums/shed.toml
deleted file mode 100644
index 842e1e9c..00000000
--- a/examples/17-sums/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "Some(hello, world!)\nNone"
diff --git a/examples/18-import/shed.json5 b/examples/18-import/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/18-import/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/18-import/shed.toml b/examples/18-import/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/18-import/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/19-function-expression/shed.json5 b/examples/19-function-expression/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/19-function-expression/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/19-function-expression/shed.toml b/examples/19-function-expression/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/19-function-expression/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/20-function-expression-infer-return-type/shed.json5 b/examples/20-function-expression-infer-return-type/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/20-function-expression-infer-return-type/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/20-function-expression-infer-return-type/shed.toml b/examples/20-function-expression-infer-return-type/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/20-function-expression-infer-return-type/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/21-function-expression-infer-param-type/shed.json5 b/examples/21-function-expression-infer-param-type/shed.json5
new file mode 100644
index 00000000..589f5e5d
--- /dev/null
+++ b/examples/21-function-expression-infer-param-type/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world\nworld, hello",
+ },
+ ],
+}
diff --git a/examples/21-function-expression-infer-param-type/shed.toml b/examples/21-function-expression-infer-param-type/shed.toml
deleted file mode 100644
index 1503d826..00000000
--- a/examples/21-function-expression-infer-param-type/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world\nworld, hello"
diff --git a/examples/22-effect-resume/shed.json5 b/examples/22-effect-resume/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/22-effect-resume/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/22-effect-resume/shed.toml b/examples/22-effect-resume/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/22-effect-resume/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/23-effect-resume-with-value/shed.json5 b/examples/23-effect-resume-with-value/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/23-effect-resume-with-value/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/23-effect-resume-with-value/shed.toml b/examples/23-effect-resume-with-value/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/23-effect-resume-with-value/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/24-effect-with-state/shed.json5 b/examples/24-effect-with-state/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/24-effect-with-state/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/24-effect-with-state/shed.toml b/examples/24-effect-with-state/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/24-effect-with-state/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/25-effect-handler-pop/shed.json5 b/examples/25-effect-handler-pop/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/25-effect-handler-pop/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/25-effect-handler-pop/shed.toml b/examples/25-effect-handler-pop/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/25-effect-handler-pop/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/26-effect-handler-pop-on-return/shed.json5 b/examples/26-effect-handler-pop-on-return/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/26-effect-handler-pop-on-return/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/26-effect-handler-pop-on-return/shed.toml b/examples/26-effect-handler-pop-on-return/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/26-effect-handler-pop-on-return/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/27-effect-handler-nested/shed.json5 b/examples/27-effect-handler-nested/shed.json5
new file mode 100644
index 00000000..ca7c7829
--- /dev/null
+++ b/examples/27-effect-handler-nested/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "example",
+ mainNamespace: "Example",
+ },
+ ],
+ examples: [
+ {
+ bin: "example",
+ expectedOutput: "a outer\na inner\na inner\nb\na inner\na inner\na outer",
+ },
+ ],
+}
diff --git a/examples/27-effect-handler-nested/shed.toml b/examples/27-effect-handler-nested/shed.toml
deleted file mode 100644
index 291ca6db..00000000
--- a/examples/27-effect-handler-nested/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "example"
-main-namespace = "Example"
-
-[[shed.examples]]
-bin = "example"
-expected-output = "a outer\na inner\na inner\nb\na inner\na inner\na outer"
diff --git a/examples/28-effect-in-handler/shed.json5 b/examples/28-effect-in-handler/shed.json5
new file mode 100644
index 00000000..cb9b7f24
--- /dev/null
+++ b/examples/28-effect-in-handler/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "example",
+ mainNamespace: "Example",
+ },
+ ],
+ examples: [
+ {
+ bin: "example",
+ expectedOutput: "a outer\na inner start\na outer\na inner end\nb start\na inner start\na outer\na inner end\nb end\na inner start\na outer\na inner end\na outer",
+ },
+ ],
+}
diff --git a/examples/28-effect-in-handler/shed.toml b/examples/28-effect-in-handler/shed.toml
deleted file mode 100644
index fc01b961..00000000
--- a/examples/28-effect-in-handler/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "example"
-main-namespace = "Example"
-
-[[shed.examples]]
-bin = "example"
-expected-output = "a outer\na inner start\na outer\na inner end\nb start\na inner start\na outer\na inner end\nb end\na inner start\na outer\na inner end\na outer"
diff --git a/examples/29-effect-break/shed.json5 b/examples/29-effect-break/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/29-effect-break/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/29-effect-break/shed.toml b/examples/29-effect-break/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/29-effect-break/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/30-generic-structs/shed.json5 b/examples/30-generic-structs/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/30-generic-structs/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/30-generic-structs/shed.toml b/examples/30-generic-structs/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/30-generic-structs/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/examples/31-generic-sums/shed.json5 b/examples/31-generic-sums/shed.json5
new file mode 100644
index 00000000..ef44c0ca
--- /dev/null
+++ b/examples/31-generic-sums/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "Some(hello, world!)\nNone",
+ },
+ ],
+}
diff --git a/examples/31-generic-sums/shed.toml b/examples/31-generic-sums/shed.toml
deleted file mode 100644
index 842e1e9c..00000000
--- a/examples/31-generic-sums/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "Some(hello, world!)\nNone"
diff --git a/examples/32-generic-structs-and-sums-inferred-type-args/shed.json5 b/examples/32-generic-structs-and-sums-inferred-type-args/shed.json5
new file mode 100644
index 00000000..ef44c0ca
--- /dev/null
+++ b/examples/32-generic-structs-and-sums-inferred-type-args/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "Some(hello, world!)\nNone",
+ },
+ ],
+}
diff --git a/examples/32-generic-structs-and-sums-inferred-type-args/shed.toml b/examples/32-generic-structs-and-sums-inferred-type-args/shed.toml
deleted file mode 100644
index 842e1e9c..00000000
--- a/examples/32-generic-structs-and-sums-inferred-type-args/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "Some(hello, world!)\nNone"
diff --git a/examples/33-generic-functions/shed.json5 b/examples/33-generic-functions/shed.json5
new file mode 100644
index 00000000..9e86b280
--- /dev/null
+++ b/examples/33-generic-functions/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world!",
+ },
+ ],
+}
diff --git a/examples/33-generic-functions/shed.toml b/examples/33-generic-functions/shed.toml
deleted file mode 100644
index 9c1a6d01..00000000
--- a/examples/33-generic-functions/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world!"
diff --git a/examples/34-generic-effects/shed.json5 b/examples/34-generic-effects/shed.json5
new file mode 100644
index 00000000..b1c76b7a
--- /dev/null
+++ b/examples/34-generic-effects/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello\nhello",
+ },
+ ],
+}
diff --git a/examples/34-generic-effects/shed.toml b/examples/34-generic-effects/shed.toml
deleted file mode 100644
index 04d4475a..00000000
--- a/examples/34-generic-effects/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello\nhello"
diff --git a/examples/35-struct-methods/shed.json5 b/examples/35-struct-methods/shed.json5
new file mode 100644
index 00000000..8953bef1
--- /dev/null
+++ b/examples/35-struct-methods/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "one\ntwo\nmany",
+ },
+ ],
+}
diff --git a/examples/35-struct-methods/shed.toml b/examples/35-struct-methods/shed.toml
deleted file mode 100644
index 0564616e..00000000
--- a/examples/35-struct-methods/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "one\ntwo\nmany"
diff --git a/examples/36-struct-method-references/shed.json5 b/examples/36-struct-method-references/shed.json5
new file mode 100644
index 00000000..748b84b8
--- /dev/null
+++ b/examples/36-struct-method-references/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "one apple\ntwo bananas\nmany coconuts!",
+ },
+ ],
+}
diff --git a/examples/36-struct-method-references/shed.toml b/examples/36-struct-method-references/shed.toml
deleted file mode 100644
index d66739b4..00000000
--- a/examples/36-struct-method-references/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "one apple\ntwo bananas\nmany coconuts!"
diff --git a/examples/37-generic-struct-methods/shed.json5 b/examples/37-generic-struct-methods/shed.json5
new file mode 100644
index 00000000..e08441e6
--- /dev/null
+++ b/examples/37-generic-struct-methods/shed.json5
@@ -0,0 +1,14 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+ examples: [
+ {
+ bin: "hello-world",
+ expectedOutput: "hello, world",
+ },
+ ],
+}
diff --git a/examples/37-generic-struct-methods/shed.toml b/examples/37-generic-struct-methods/shed.toml
deleted file mode 100644
index bf5c13c4..00000000
--- a/examples/37-generic-struct-methods/shed.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[[shed.bins]]
-name = "hello-world"
-main-namespace = "HelloWorld"
-
-[[shed.examples]]
-bin = "hello-world"
-expected-output = "hello, world"
diff --git a/pom.xml b/pom.xml
index d6994dc2..d76b55d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,6 +53,11 @@
<version>1.1.0</version>
</dependency>
<dependency>
+ <groupId>com.github.mwilliamson</groupId>
+ <artifactId>java-json5</artifactId>
+ <version>73905f74f2ffbbac57bf4c15e103c9e0f4741426</version>
+ </dependency>
+ <dependency>
<groupId>org.pcollections</groupId>
<artifactId>pcollections</artifactId>
<version>4.0.1</version>
diff --git a/src/main/java/org/shedlang/compiler/config/BinConfig.java b/src/main/java/org/shedlang/compiler/config/BinConfig.java
index e91a6af4..5f2b0a7d 100644
--- a/src/main/java/org/shedlang/compiler/config/BinConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/BinConfig.java
@@ -1,7 +1,7 @@
package org.shedlang.compiler.config;
import org.shedlang.compiler.config.errors.ConfigError;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.parser.SourceParser;
import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.tokeniser.UnexpectedTokenException;
@@ -10,10 +10,10 @@ import org.shedlang.compiler.types.NamespaceName;
import java.text.MessageFormat;
public record BinConfig(String name, NamespaceName mainNamespace) {
- public static BinConfig fromToml(TomlTableWithSource table) {
- var name = table.getString("name").value();
+ public static BinConfig fromJson5(Json5ObjectWithSource object) {
+ var name = object.getString("name").value();
- var mainNamespaceString = table.getString("main-namespace");
+ var mainNamespaceString = object.getString("mainNamespace");
try {
var mainNamespace = SourceParser.parseNamespaceName(Sources.string(mainNamespaceString.value()));
diff --git a/src/main/java/org/shedlang/compiler/config/ExampleConfig.java b/src/main/java/org/shedlang/compiler/config/ExampleConfig.java
index abc311d3..1135066f 100644
--- a/src/main/java/org/shedlang/compiler/config/ExampleConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/ExampleConfig.java
@@ -1,7 +1,7 @@
package org.shedlang.compiler.config;
-import org.shedlang.compiler.config.toml.TomlString;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
+import org.shedlang.compiler.config.json.Json5StringWithSource;
import java.util.Optional;
@@ -10,11 +10,11 @@ public record ExampleConfig(
Optional<String> expectedOutput,
Optional<String> expectedError
) {
- public static ExampleConfig fromToml(TomlTableWithSource table) {
+ public static ExampleConfig fromJson5(Json5ObjectWithSource object) {
return new ExampleConfig(
- table.getString("bin").value(),
- table.getStringOrNone("expected-output").map(TomlString::value),
- table.getStringOrNone("expected-error").map(TomlString::value)
+ object.getString("bin").value(),
+ object.getStringOrNone("expectedOutput").map(Json5StringWithSource::value),
+ object.getStringOrNone("expectedError").map(Json5StringWithSource::value)
);
}
}
diff --git a/src/main/java/org/shedlang/compiler/config/GcConfig.java b/src/main/java/org/shedlang/compiler/config/GcConfig.java
index fad51f63..312c2f96 100644
--- a/src/main/java/org/shedlang/compiler/config/GcConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/GcConfig.java
@@ -1,6 +1,6 @@
package org.shedlang.compiler.config;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import java.util.List;
@@ -8,15 +8,15 @@ public sealed interface GcConfig permits GcBumpConfig, GcMarkAndSweepConfig {
GcConfig BUMP = new GcBumpConfig();
GcConfig DEFAULT = GcMarkAndSweepConfig.DEFAULT;
- static GcConfig fromToml(TomlTableWithSource table) {
- var name = table.getString("name").value();
+ static GcConfig fromJson5(Json5ObjectWithSource object) {
+ var name = object.getString("name").value();
return switch (name) {
case "bump" ->
BUMP;
case "mark-and-sweep" ->
- GcMarkAndSweepConfig.fromToml(table);
+ GcMarkAndSweepConfig.fromJson5(object);
default ->
throw new IllegalArgumentException("Unrecognised GC name: \"%s\"".formatted(name));
diff --git a/src/main/java/org/shedlang/compiler/config/GcMarkAndSweepConfig.java b/src/main/java/org/shedlang/compiler/config/GcMarkAndSweepConfig.java
index 0c2ea9bb..8ac9ce56 100644
--- a/src/main/java/org/shedlang/compiler/config/GcMarkAndSweepConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/GcMarkAndSweepConfig.java
@@ -1,6 +1,6 @@
package org.shedlang.compiler.config;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import java.util.ArrayList;
import java.util.List;
@@ -13,8 +13,8 @@ public record GcMarkAndSweepConfig(
OptionalLong.empty()
);
- public static GcMarkAndSweepConfig fromToml(TomlTableWithSource table) {
- var collectInterval = table.getLongOrNone("collect-interval");
+ public static GcMarkAndSweepConfig fromJson5(Json5ObjectWithSource object) {
+ var collectInterval = object.getLongOrNone("collectInterval");
return new GcMarkAndSweepConfig(collectInterval);
}
diff --git a/src/main/java/org/shedlang/compiler/config/ProfileConfig.java b/src/main/java/org/shedlang/compiler/config/ProfileConfig.java
index cf8b4998..d922a4cb 100644
--- a/src/main/java/org/shedlang/compiler/config/ProfileConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/ProfileConfig.java
@@ -1,19 +1,16 @@
package org.shedlang.compiler.config;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import java.util.Optional;
public record ProfileConfig(String name, Optional<GcConfig> gc) {
public static final ProfileConfig DEFAULT = new ProfileConfig("dev", Optional.empty());
- public static ProfileConfig fromToml(TomlTableWithSource table) {
- var name = table.getString("name").value();
- var gc = table.getTable("gc").map(GcConfig::fromToml);
+ public static ProfileConfig fromJson5(Json5ObjectWithSource object) {
+ var name = object.getString("name").value();
+ var gc = object.getObject("gc").map(GcConfig::fromJson5);
- return new ProfileConfig(
- name,
- gc
- );
+ return new ProfileConfig(name, gc);
}
}
diff --git a/src/main/java/org/shedlang/compiler/config/ProjectConfig.java b/src/main/java/org/shedlang/compiler/config/ProjectConfig.java
index f6ddb80f..0408a143 100644
--- a/src/main/java/org/shedlang/compiler/config/ProjectConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/ProjectConfig.java
@@ -1,6 +1,6 @@
package org.shedlang.compiler.config;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.sources.Sources;
import java.io.IOException;
@@ -15,55 +15,49 @@ public record ProjectConfig(
List<ProfileConfig> profiles
) {
public static ProjectConfig read(Path projectPath) throws IOException {
- var configPath = projectPath.resolve("shed.toml");
+ var configPath = projectPath.resolve("shed.json5");
var contents = Files.readString(configPath);
var source = Sources.file(configPath, contents);
- return fromToml(projectPath, TomlTableWithSource.parse(source));
+ return fromJson5(projectPath, Json5ObjectWithSource.parse(source));
}
public static ProjectConfig fromString(Path projectPath, String config) {
- return fromToml(
+ return fromJson5(
projectPath,
- TomlTableWithSource.parse(Sources.string(config))
+ Json5ObjectWithSource.parse(Sources.string(config))
);
}
- public static ProjectConfig fromToml(Path root, TomlTableWithSource table) {
+ public static ProjectConfig fromJson5(Path root, Json5ObjectWithSource object) {
return new ProjectConfig(
root,
- binsFromToml(table),
- examplesFromToml(table),
- profilesFromToml(table)
+ binsFromToml(object),
+ examplesFromToml(object),
+ profilesFromToml(object)
);
}
- private static List<BinConfig> binsFromToml(TomlTableWithSource table) {
- return table
- .getTable("shed")
- .flatMap(shed -> shed.getArrayOfTables("bins"))
+ private static List<BinConfig> binsFromToml(Json5ObjectWithSource object) {
+ return object.getArrayOfObjects("bins")
.orElseGet(() -> List.of())
.stream()
- .map(bin -> BinConfig.fromToml(bin))
+ .map(bin -> BinConfig.fromJson5(bin))
.toList();
}
- public static List<ExampleConfig> examplesFromToml(TomlTableWithSource table) {
- return table
- .getTable("shed")
- .flatMap(shed -> shed.getArrayOfTables("examples"))
+ public static List<ExampleConfig> examplesFromToml(Json5ObjectWithSource object) {
+ return object.getArrayOfObjects("examples")
.orElseGet(() -> List.of())
.stream()
- .map(example -> ExampleConfig.fromToml(example))
+ .map(example -> ExampleConfig.fromJson5(example))
.toList();
}
- public static List<ProfileConfig> profilesFromToml(TomlTableWithSource table) {
- return table
- .getTable("shed")
- .flatMap(shed -> shed.getArrayOfTables("profiles"))
+ public static List<ProfileConfig> profilesFromToml(Json5ObjectWithSource object) {
+ return object.getArrayOfObjects("profiles")
.orElseGet(() -> List.of())
.stream()
- .map(profile -> ProfileConfig.fromToml(profile))
+ .map(profile -> ProfileConfig.fromJson5(profile))
.toList();
}
diff --git a/src/main/java/org/shedlang/compiler/config/errors/Json5SyntaxConfigError.java b/src/main/java/org/shedlang/compiler/config/errors/Json5SyntaxConfigError.java
new file mode 100644
index 00000000..d0db7f6c
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/config/errors/Json5SyntaxConfigError.java
@@ -0,0 +1,19 @@
+package org.shedlang.compiler.config.errors;
+
+import org.shedlang.compiler.config.json.Json5Source;
+import org.shedlang.compiler.sources.Source;
+import org.zwobble.json5.parser.Json5ParseError;
+
+public class Json5SyntaxConfigError extends ConfigError {
+ public static Json5SyntaxConfigError fromJson5ParseError(
+ Json5ParseError error,
+ Source fullSource
+ ) {
+ var source = Json5Source.fromSourceRange(fullSource, error.sourceRange());
+ return new Json5SyntaxConfigError(error.getMessage(), source);
+ }
+
+ public Json5SyntaxConfigError(String message, Source source) {
+ super(message, source);
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/config/errors/TomlSyntaxConfigError.java b/src/main/java/org/shedlang/compiler/config/errors/TomlSyntaxConfigError.java
deleted file mode 100644
index aa034738..00000000
--- a/src/main/java/org/shedlang/compiler/config/errors/TomlSyntaxConfigError.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.shedlang.compiler.config.errors;
-
-import org.shedlang.compiler.config.toml.TomlSource;
-import org.shedlang.compiler.sources.Source;
-import org.tomlj.TomlParseError;
-
-public class TomlSyntaxConfigError extends ConfigError {
- public static TomlSyntaxConfigError fromTomljError(
- TomlParseError error,
- Source fullSource
- ) {
- var source = TomlSource.sourceAtTomlPosition(fullSource, error.position());
- return new TomlSyntaxConfigError(error.getMessage(), source);
- }
-
- public TomlSyntaxConfigError(String message, Source source) {
- super(message, source);
- }
-}
diff --git a/src/main/java/org/shedlang/compiler/config/errors/UnexpectedTypeConfigError.java b/src/main/java/org/shedlang/compiler/config/errors/UnexpectedTypeConfigError.java
index 0b0eda67..1a13f3a2 100644
--- a/src/main/java/org/shedlang/compiler/config/errors/UnexpectedTypeConfigError.java
+++ b/src/main/java/org/shedlang/compiler/config/errors/UnexpectedTypeConfigError.java
@@ -1,25 +1,51 @@
package org.shedlang.compiler.config.errors;
-import org.shedlang.compiler.config.toml.TomlPath;
+import org.shedlang.compiler.config.json.Json5Path;
import org.shedlang.compiler.sources.Source;
+import org.zwobble.json5.values.*;
import java.text.MessageFormat;
public class UnexpectedTypeConfigError extends ConfigError {
public UnexpectedTypeConfigError(
- TomlPath path,
- String expectedType,
- Class<?> actualType,
+ Json5Path path,
+ Class<? extends Json5Value> expectedType,
+ Class<? extends Json5Value> actualType,
Source source
) {
super(
MessageFormat.format(
"Expected {0} to be {1}, but was {2}",
path,
- expectedType,
- actualType.getSimpleName()
+ // TODO: nicer names for JSON5 value types
+ describeJson5ValueType(expectedType),
+ describeJson5ValueType(actualType)
),
source
);
}
+
+ private static String describeJson5ValueType(Class<? extends Json5Value> expectedType) {
+ if (expectedType.equals(Json5Array.class)) {
+ return "array";
+ } else if (expectedType.equals(Json5Boolean.class)) {
+ return "boolean";
+ } else if (expectedType.equals(Json5Null.class)) {
+ return "null";
+ } else if (expectedType.equals(Json5NumberFinite.class)) {
+ return "finite number";
+ } else if (expectedType.equals(Json5NumberNan.class)) {
+ return "NaN";
+ } else if (expectedType.equals(Json5NumberPositiveInfinity.class)) {
+ return "Infinity";
+ } else if (expectedType.equals(Json5NumberNegativeInfinity.class)) {
+ return "-Infinity";
+ } else if (expectedType.equals(Json5Object.class)) {
+ return "object";
+ } else if (expectedType.equals(Json5String.class)) {
+ return "string";
+ } else {
+ return expectedType.getSimpleName();
+ }
+ }
}
diff --git a/src/main/java/org/shedlang/compiler/config/json/Json5ObjectWithSource.java b/src/main/java/org/shedlang/compiler/config/json/Json5ObjectWithSource.java
new file mode 100644
index 00000000..f073f267
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/config/json/Json5ObjectWithSource.java
@@ -0,0 +1,170 @@
+package org.shedlang.compiler.config.json;
+
+import org.shedlang.compiler.config.errors.ConfigError;
+import org.shedlang.compiler.config.errors.Json5SyntaxConfigError;
+import org.shedlang.compiler.config.errors.UnexpectedTypeConfigError;
+import org.shedlang.compiler.sources.Source;
+import org.zwobble.json5.parser.Json5ParseError;
+import org.zwobble.json5.parser.Json5Parser;
+import org.zwobble.json5.values.*;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.OptionalLong;
+
+public class Json5ObjectWithSource {
+ private final Json5Object object;
+ private final Json5Path path;
+ private final Source fullSource;
+
+ private Json5ObjectWithSource(
+ Json5Object object,
+ Json5Path path,
+ Source fullSource
+ ) {
+ this.object = object;
+ this.path = path;
+ this.fullSource = fullSource;
+ }
+
+ public static Json5ObjectWithSource parse(Source source) {
+ try {
+ var document = Json5Parser.parseText(source.contents());
+
+ if (document instanceof Json5Object object) {
+ return new Json5ObjectWithSource(
+ object,
+ Json5Path.TOP,
+ source
+ );
+ } else {
+ // TODO: write a test for this.
+ throw new UnexpectedTypeConfigError(
+ Json5Path.TOP,
+ Json5Object.class,
+ document.getClass(),
+ source
+ );
+ }
+ } catch (Json5ParseError error) {
+ throw Json5SyntaxConfigError.fromJson5ParseError(error, source);
+ }
+ }
+
+ public Optional<Json5ObjectWithSource> getObject(String memberName) {
+ return getValueOfType(Json5Object.class, memberName)
+ .map(object -> new Json5ObjectWithSource(
+ object,
+ path.plusMemberName(memberName),
+ fullSource
+ ));
+ }
+
+ private Optional<Json5Array> getArray(String memberName) {
+ return getValueOfType(Json5Array.class, memberName);
+ }
+
+ public Optional<List<Json5ObjectWithSource>> getArrayOfObjects(String memberName) {
+ return getArray(memberName).map(array -> {
+ var objects = new ArrayList<Json5ObjectWithSource>();
+ var index = 0;
+ var arrayPath = path.plusMemberName(memberName);
+ for (var element : array.elements()) {
+ var objectPath = arrayPath.plusArrayIndex(index);
+ var object = castJson5Value(
+ Json5Object.class,
+ objectPath,
+ element,
+ fullSource
+ );
+ objects.add(new Json5ObjectWithSource(
+ object,
+ objectPath,
+ fullSource
+ ));
+ index++;
+ }
+ return objects;
+ });
+ }
+
+ public Optional<Json5StringWithSource> getStringOrNone(String memberName) {
+ return getValueOfType(Json5String.class, memberName)
+ .map(string -> new Json5StringWithSource(
+ string,
+ path.plusMemberName(memberName),
+ fullSource
+ ));
+ }
+
+ public Json5StringWithSource getString(String memberName) {
+ return getStringOrNone(memberName)
+ .orElseThrow(() -> new ConfigError(
+ // TODO: escape member name
+ MessageFormat.format("{0} is missing {1}", path, memberName),
+ Json5Source.fromSourceRange(fullSource, object.sourceRange())
+ ));
+ }
+
+ public OptionalLong getLongOrNone(String memberName) {
+ var numberFinite = getValueOfType(Json5NumberFinite.class, memberName);
+ if (numberFinite.isEmpty()) {
+ return OptionalLong.empty();
+ }
+
+ try {
+ return OptionalLong.of(numberFinite.get().value().longValueExact());
+ } catch (ArithmeticException exception) {
+ // TODO: more specific error?
+ throw new ConfigError(
+ String.format(
+ "%s must be a 64-bit integer",
+ path.plusMemberName(memberName)
+ ),
+ Json5Source.fromSourceRange(fullSource, numberFinite.get().sourceRange())
+ );
+ }
+ }
+
+ public long getLong(String memberName) {
+ return getLongOrNone(memberName)
+ .orElseThrow(() -> new ConfigError(
+ // TODO: escape member name
+ MessageFormat.format("{0} is missing {1}", path, memberName),
+ Json5Source.fromSourceRange(fullSource, object.sourceRange())
+ ));
+ }
+
+ private <TValue extends Json5Value> Optional<TValue> getValueOfType(
+ Class<TValue> valueType,
+ String memberName
+ ) {
+ return object.getValue(memberName)
+ .map(value -> castJson5Value(
+ valueType,
+ path.plusMemberName(memberName),
+ value,
+ fullSource
+ ));
+ }
+
+ private static <TValue extends Json5Value> TValue castJson5Value(
+ Class<TValue> valueType,
+ Json5Path path,
+ Json5Value value,
+ Source fullSource
+ ) {
+ try {
+ return valueType.cast(value);
+ } catch (ClassCastException exception) {
+ throw new UnexpectedTypeConfigError(
+ path,
+ valueType,
+ value.getClass(),
+ Json5Source.fromSourceRange(fullSource, value.sourceRange())
+ );
+ }
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/config/json/Json5Path.java b/src/main/java/org/shedlang/compiler/config/json/Json5Path.java
new file mode 100644
index 00000000..f63e7ae4
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/config/json/Json5Path.java
@@ -0,0 +1,36 @@
+package org.shedlang.compiler.config.json;
+
+import org.pcollections.PVector;
+import org.shedlang.compiler.util.CheckReturnValue;
+import org.shedlang.compiler.util.P;
+
+import java.text.MessageFormat;
+
+public class Json5Path {
+ public static final Json5Path TOP = new Json5Path(P.vector());
+
+ private final PVector<String> components;
+
+ private Json5Path(PVector<String> components) {
+ this.components = components;
+ }
+
+ @CheckReturnValue
+ public Json5Path plusMemberName(String memberName) {
+ // TODO: handle string escaping
+ var component = components.isEmpty() ? memberName : "." + memberName;
+ return new Json5Path(this.components.plus(component));
+ }
+
+ @CheckReturnValue
+ public Json5Path plusArrayIndex(int index) {
+ var component = MessageFormat.format("[{0}]", index);
+ return new Json5Path(this.components.plus(component));
+ }
+
+ @Override
+ public String toString() {
+ // TODO: handle empty path
+ return String.join("", this.components);
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/config/json/Json5Source.java b/src/main/java/org/shedlang/compiler/config/json/Json5Source.java
new file mode 100644
index 00000000..6b761a6a
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/config/json/Json5Source.java
@@ -0,0 +1,18 @@
+package org.shedlang.compiler.config.json;
+
+import org.shedlang.compiler.sources.Source;
+import org.zwobble.json5.sources.Json5SourceRange;
+
+public class Json5Source {
+ private Json5Source() {}
+
+ public static Source fromSourceRange(Source fullSource, Json5SourceRange sourceRange) {
+ // TODO: decide whether we're using code points or code units, and make
+ // consistent (currently Shed sources use UTF-16 code units, JSON5
+ // sources use code points)
+ return fullSource.at(
+ sourceRange.startCodePointIndex(),
+ sourceRange.endCodePointIndex()
+ );
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/config/json/Json5StringWithSource.java b/src/main/java/org/shedlang/compiler/config/json/Json5StringWithSource.java
new file mode 100644
index 00000000..bc9cf4b9
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/config/json/Json5StringWithSource.java
@@ -0,0 +1,28 @@
+package org.shedlang.compiler.config.json;
+
+import org.shedlang.compiler.sources.Source;
+import org.zwobble.json5.values.Json5String;
+
+public class Json5StringWithSource {
+ private final Json5String string;
+ private final Json5Path path;
+ private final Source fullSource;
+
+ public Json5StringWithSource(
+ Json5String string,
+ Json5Path path,
+ Source fullSource
+ ) {
+ this.string = string;
+ this.path = path;
+ this.fullSource = fullSource;
+ }
+
+ public String value() {
+ return string.value();
+ }
+
+ public Source source() {
+ return Json5Source.fromSourceRange(fullSource, string.sourceRange());
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/config/toml/TomlPath.java b/src/main/java/org/shedlang/compiler/config/toml/TomlPath.java
deleted file mode 100644
index dc5910a9..00000000
--- a/src/main/java/org/shedlang/compiler/config/toml/TomlPath.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.shedlang.compiler.config.toml;
-
-import org.pcollections.PVector;
-import org.shedlang.compiler.util.CheckReturnValue;
-import org.shedlang.compiler.util.P;
-
-import java.text.MessageFormat;
-
-public class TomlPath {
- public static final TomlPath TOP = new TomlPath(P.vector());
-
- private final PVector<String> components;
-
- private TomlPath(PVector<String> components) {
- this.components = components;
- }
-
- @CheckReturnValue
- public TomlPath plusKey(String key) {
- // TODO: handle string escaping
- var component = components.isEmpty() ? key : "." + key;
- return new TomlPath(this.components.plus(component));
- }
-
- @CheckReturnValue
- public TomlPath plusIndex(int index) {
- var component = MessageFormat.format("[{0}]", index);
- return new TomlPath(this.components.plus(component));
- }
-
- @Override
- public String toString() {
- return String.join("", this.components);
- }
-}
diff --git a/src/main/java/org/shedlang/compiler/config/toml/TomlSource.java b/src/main/java/org/shedlang/compiler/config/toml/TomlSource.java
deleted file mode 100644
index e72fbb45..00000000
--- a/src/main/java/org/shedlang/compiler/config/toml/TomlSource.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.shedlang.compiler.config.toml;
-
-import org.shedlang.compiler.sources.Source;
-import org.tomlj.TomlPosition;
-
-import java.util.Arrays;
-
-public class TomlSource {
- private TomlSource() {}
-
- public static Source sourceAtTomlPosition(Source fullSource, TomlPosition position) {
- var lines = fullSource.contents().split("\n");
- var lineCharacterIndex = Arrays.stream(lines)
- .limit(position.line() - 1)
- .mapToInt(line -> line.length() + 1)
- .sum();
- var characterIndex = lineCharacterIndex + position.column() - 1;
- return fullSource.at(characterIndex, characterIndex);
- }
-}
diff --git a/src/main/java/org/shedlang/compiler/config/toml/TomlString.java b/src/main/java/org/shedlang/compiler/config/toml/TomlString.java
deleted file mode 100644
index b8aac9e5..00000000
--- a/src/main/java/org/shedlang/compiler/config/toml/TomlString.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.shedlang.compiler.config.toml;
-
-import org.shedlang.compiler.sources.Source;
-
-public record TomlString(String value, Source source) {
-}
diff --git a/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java b/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java
deleted file mode 100644
index f7ef240f..00000000
--- a/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java
+++ /dev/null
@@ -1,214 +0,0 @@
-package org.shedlang.compiler.config.toml;
-
-import org.shedlang.compiler.config.errors.ConfigError;
-import org.shedlang.compiler.config.errors.TomlSyntaxConfigError;
-import org.shedlang.compiler.config.errors.UnexpectedTypeConfigError;
-import org.shedlang.compiler.sources.Source;
-import org.tomlj.Toml;
-import org.tomlj.TomlArray;
-import org.tomlj.TomlPosition;
-import org.tomlj.TomlTable;
-
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.Optional;
-import java.util.OptionalLong;
-import java.util.stream.IntStream;
-
-public class TomlTableWithSource {
- private final TomlTable table;
- private final TomlPath path;
- private final TomlPosition position;
- private final Source fullSource;
-
- private TomlTableWithSource(TomlTable table, TomlPath path, TomlPosition position, Source fullSource) {
- this.table = table;
- this.path = path;
- this.position = position;
- this.fullSource = fullSource;
- }
-
- public static TomlTableWithSource parse(Source source) {
- var result = Toml.parse(source.contents());
-
- if (result.hasErrors()) {
- var error = result.errors().get(0);
- throw TomlSyntaxConfigError.fromTomljError(error, source);
- }
-
- return new TomlTableWithSource(
- result,
- TomlPath.TOP,
- TomlPosition.positionAt(1, 1),
- source
- );
- }
-
- public Optional<TomlTableWithSource> getTable(String key) {
- var value = table.get(key);
- var position = table.inputPositionOf(key);
-
- return tomlValueToTable(path.plusKey(key), value, position);
- }
-
- private Optional<TomlTableWithSource> tomlValueToTable(
- TomlPath valuePath,
- Object value,
- TomlPosition valuePosition
- ) {
- if (value == null || valuePosition == null) {
- return Optional.empty();
- }
-
- if (value instanceof TomlTable valueTable) {
- return Optional.of(new TomlTableWithSource(
- valueTable,
- valuePath,
- valuePosition,
- fullSource
- ));
- }
-
- throw new UnexpectedTypeConfigError(
- valuePath,
- "a table",
- value.getClass(),
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- }
-
- private Optional<TomlArray> getArray(String key) {
- var value = table.get(key);
- var position = table.inputPositionOf(key);
-
- if (value == null || position == null) {
- return Optional.empty();
- }
-
- if (value instanceof TomlArray valueArray) {
- return Optional.of(valueArray);
- }
-
- throw new UnexpectedTypeConfigError(
- path.plusKey(key),
- "an array",
- value.getClass(),
- TomlSource.sourceAtTomlPosition(fullSource, position)
- );
- }
-
- public Optional<List<TomlTableWithSource>> getArrayOfTables(String key) {
- return getArray(key).map(array ->
- IntStream.range(0, array.size())
- .mapToObj(index -> {
- var element = array.get(index);
- var elementPosition = array.inputPositionOf(index);
- return tomlValueToTable(
- path.plusKey(key).plusIndex(index),
- element,
- elementPosition
- );
- })
- .flatMap(x -> x.stream())
- .toList()
- );
- }
-
- public Optional<TomlString> getStringOrNone(String key) {
- var value = table.get(key);
- var valuePosition = table.inputPositionOf(key);
-
- if (value == null || valuePosition == null) {
- return Optional.empty();
- }
-
- if (value instanceof String valueString) {
- var tomlString = new TomlString(
- valueString,
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- return Optional.of(tomlString);
- }
-
- throw new UnexpectedTypeConfigError(
- path.plusKey(key),
- "a string",
- value.getClass(),
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- }
-
- public TomlString getString(String key) {
- var value = table.get(key);
- var valuePosition = table.inputPositionOf(key);
-
- if (value == null || valuePosition == null) {
- throw new ConfigError(
- MessageFormat.format("{0} is missing {1}", path, key),
- TomlSource.sourceAtTomlPosition(fullSource, position)
- );
- }
-
- if (value instanceof String valueString) {
- return new TomlString(
- valueString,
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- }
-
- throw new UnexpectedTypeConfigError(
- path.plusKey(key),
- "a string",
- value.getClass(),
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- }
-
- public OptionalLong getLongOrNone(String key) {
- var value = table.get(key);
- var valuePosition = table.inputPositionOf(key);
-
- if (value == null) {
- return OptionalLong.empty();
- }
-
- if (value instanceof Long valueLong) {
- return OptionalLong.of(valueLong);
- }
-
- throw new UnexpectedTypeConfigError(
- path.plusKey(key),
- "a long",
- value.getClass(),
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- }
-
- public long getLong(String key) {
- var value = table.get(key);
- var valuePosition = table.inputPositionOf(key);
-
- if (value == null) {
- throw new ConfigError(
- MessageFormat.format("{0} is missing {1}", path, key),
- TomlSource.sourceAtTomlPosition(fullSource, position)
- );
- }
-
- if (value instanceof Long valueLong) {
- return valueLong;
- }
-
- throw new UnexpectedTypeConfigError(
- path.plusKey(key),
- "a long",
- value.getClass(),
- TomlSource.sourceAtTomlPosition(fullSource, valuePosition)
- );
- }
-
- public Optional<Source> getSource(String key) {
- return Optional.ofNullable(table.inputPositionOf(key))
- .map(position -> TomlSource.sourceAtTomlPosition(fullSource, position));
- }
-}
diff --git a/src/test/java/org/shedlang/compiler/config/BinConfigTests.java b/src/test/java/org/shedlang/compiler/config/BinConfigTests.java
index aead8546..d909bb84 100644
--- a/src/test/java/org/shedlang/compiler/config/BinConfigTests.java
+++ b/src/test/java/org/shedlang/compiler/config/BinConfigTests.java
@@ -2,7 +2,7 @@ package org.shedlang.compiler.config;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.config.errors.ConfigError;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.types.NamespaceName;
@@ -14,11 +14,13 @@ public class BinConfigTests {
@Test
public void canParseBinConfigWithNameAndMainNamespace() {
var source = Sources.string("""
- name = "one"
- main-namespace = "A/B"
+ {
+ name: "one",
+ mainNamespace: "A/B",
+ }
""");
- var config = BinConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = BinConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, allOf(
has("name", x -> x.name(), equalTo("one")),
@@ -28,13 +30,15 @@ public class BinConfigTests {
@Test
public void whenMainNamespaceHasSyntaxErrorThenErrorIsThrown() {
var source = Sources.string("""
- name = "one"
- main-namespace = "A.B"
+ {
+ name: "one",
+ mainNamespace: "A.B",
+ }
""");
var error = assertThrows(
ConfigError.class,
- () -> BinConfig.fromToml(TomlTableWithSource.parse(source))
+ () -> BinConfig.fromJson5(Json5ObjectWithSource.parse(source))
);
assertThat(error.getMessage(), equalTo("""
@@ -46,8 +50,8 @@ public class BinConfigTests {
A.B
^"""));
assertThat(error.source().describe(), equalTo("""
- <string>:2:1
- main-namespace = "A.B"
- ^"""));
+ <string>:3:20
+ mainNamespace: "A.B",
+ ^"""));
}
}
diff --git a/src/test/java/org/shedlang/compiler/config/GcConfigTests.java b/src/test/java/org/shedlang/compiler/config/GcConfigTests.java
index 6803cf70..351d3d5b 100644
--- a/src/test/java/org/shedlang/compiler/config/GcConfigTests.java
+++ b/src/test/java/org/shedlang/compiler/config/GcConfigTests.java
@@ -1,7 +1,7 @@
package org.shedlang.compiler.config;
import org.junit.jupiter.api.Test;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.sources.Sources;
import java.util.OptionalLong;
@@ -14,12 +14,14 @@ public class GcConfigTests {
@Test
public void whenNameIsUnrecognisedThenErrorIsThrown() {
var source = Sources.string("""
- name = "huh"
+ {
+ name: "huh",
+ }
""");
var error = assertThrows(
IllegalArgumentException.class,
- () -> GcConfig.fromToml(TomlTableWithSource.parse(source))
+ () -> GcConfig.fromJson5(Json5ObjectWithSource.parse(source))
);
assertThat(error.getMessage(), equalTo("Unrecognised GC name: \"huh\""));
@@ -28,10 +30,12 @@ public class GcConfigTests {
@Test
public void canParseConfigForBump() {
var source = Sources.string("""
- name = "bump"
+ {
+ "name": "bump",
+ }
""");
- var config = GcConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = GcConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, instanceOf(GcBumpConfig.class));
}
@@ -39,10 +43,12 @@ public class GcConfigTests {
@Test
public void canParseMinimalConfigForMarkAndSweep() {
var source = Sources.string("""
- name = "mark-and-sweep"
+ {
+ name: "mark-and-sweep",
+ }
""");
- var config = GcConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = GcConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, instanceOf(GcMarkAndSweepConfig.class));
}
@@ -50,11 +56,13 @@ public class GcConfigTests {
@Test
public void additionalFieldsCanBeUsedBySpecificGcConfig() {
var source = Sources.string("""
- name = "mark-and-sweep"
- collect-interval = 10000
+ {
+ name: "mark-and-sweep",
+ collectInterval: 10000,
+ }
""");
- var config = GcConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = GcConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, instanceOf(
GcMarkAndSweepConfig.class,
diff --git a/src/test/java/org/shedlang/compiler/config/GcMarkAndSweepConfigTests.java b/src/test/java/org/shedlang/compiler/config/GcMarkAndSweepConfigTests.java
index 91d0d234..551c29d6 100644
--- a/src/test/java/org/shedlang/compiler/config/GcMarkAndSweepConfigTests.java
+++ b/src/test/java/org/shedlang/compiler/config/GcMarkAndSweepConfigTests.java
@@ -1,7 +1,7 @@
package org.shedlang.compiler.config;
import org.junit.jupiter.api.Test;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.sources.Sources;
import java.util.OptionalLong;
@@ -13,9 +13,9 @@ import static org.zwobble.precisely.Matchers.has;
public class GcMarkAndSweepConfigTests {
@Test
public void collectIntervalCanBeMissing() {
- var source = Sources.string("");
+ var source = Sources.string("{}");
- var config = GcMarkAndSweepConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = GcMarkAndSweepConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, has(
"collectInterval",
@@ -27,11 +27,13 @@ public class GcMarkAndSweepConfigTests {
@Test
public void additionalFieldsCanBeUsedBySpecificGcConfig() {
var source = Sources.string("""
- name = "mark-and-sweep"
- collect-interval = 10000
+ {
+ name: "mark-and-sweep",
+ collectInterval: 10000,
+ }
""");
- var config = GcMarkAndSweepConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = GcMarkAndSweepConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, has(
"collectInterval",
diff --git a/src/test/java/org/shedlang/compiler/config/ProfileConfigTests.java b/src/test/java/org/shedlang/compiler/config/ProfileConfigTests.java
index 7e779252..d7e5ac6f 100644
--- a/src/test/java/org/shedlang/compiler/config/ProfileConfigTests.java
+++ b/src/test/java/org/shedlang/compiler/config/ProfileConfigTests.java
@@ -1,7 +1,7 @@
package org.shedlang.compiler.config;
import org.junit.jupiter.api.Test;
-import org.shedlang.compiler.config.toml.TomlTableWithSource;
+import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.sources.Sources;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -11,10 +11,12 @@ public class ProfileConfigTests {
@Test
public void canParseProfileConfigWithName() {
var source = Sources.string("""
- name = "one"
+ {
+ name: "one",
+ }
""");
- var config = ProfileConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = ProfileConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, has("name", x -> x.name(), equalTo("one")));
}
@@ -22,10 +24,12 @@ public class ProfileConfigTests {
@Test
public void canParseProfileConfigWithoutGc() {
var source = Sources.string("""
- name = "one"
+ {
+ name: "one",
+ }
""");
- var config = ProfileConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = ProfileConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, has("name", x -> x.gc(), isOptionalEmpty()));
}
@@ -33,11 +37,15 @@ public class ProfileConfigTests {
@Test
public void canParseProfileConfigWithGc() {
var source = Sources.string("""
- name = "one"
- gc.name = "bump"
+ {
+ name: "one",
+ gc: {
+ "name": "bump",
+ },
+ }
""");
- var config = ProfileConfig.fromToml(TomlTableWithSource.parse(source));
+ var config = ProfileConfig.fromJson5(Json5ObjectWithSource.parse(source));
assertThat(config, has(
"gc",
diff --git a/src/test/java/org/shedlang/compiler/config/ProjectConfigTests.java b/src/test/java/org/shedlang/compiler/config/ProjectConfigTests.java
index 10397acf..f0deac1e 100644
--- a/src/test/java/org/shedlang/compiler/config/ProjectConfigTests.java
+++ b/src/test/java/org/shedlang/compiler/config/ProjectConfigTests.java
@@ -2,7 +2,7 @@ package org.shedlang.compiler.config;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.config.errors.ConfigError;
-import org.shedlang.compiler.config.errors.TomlSyntaxConfigError;
+import org.shedlang.compiler.config.errors.Json5SyntaxConfigError;
import org.shedlang.compiler.types.NamespaceName;
import java.nio.file.Path;
@@ -17,14 +17,14 @@ public class ProjectConfigTests {
@Test
public void whenProjectConfigHasSyntaxErrorsOnFirstLineThenErrorIsThrown() {
var error = assertThrows(
- TomlSyntaxConfigError.class,
- () -> ProjectConfig.fromString(PROJECT_PATH, "[x] ]x")
+ Json5SyntaxConfigError.class,
+ () -> ProjectConfig.fromString(PROJECT_PATH, "[1] ]1")
);
- assertThat(error.getMessage(), equalTo("Unexpected ']', expected a newline or end-of-input"));
+ assertThat(error.getMessage(), equalTo("Expected end of document, but was ']'"));
assertThat(error.source().describe(), equalTo("""
<string>:1:5
- [x] ]x
+ [1] ]1
^"""
));
}
@@ -32,38 +32,21 @@ public class ProjectConfigTests {
@Test
public void whenProjectConfigHasSyntaxErrorsOnNonFirstLineThenErrorIsThrown() {
var error = assertThrows(
- TomlSyntaxConfigError.class,
- () -> ProjectConfig.fromString(PROJECT_PATH, "[a]\n[x] ]x")
+ Json5SyntaxConfigError.class,
+ () -> ProjectConfig.fromString(PROJECT_PATH, "[\n1\n]\n 2")
);
- assertThat(error.getMessage(), equalTo("Unexpected ']', expected a newline or end-of-input"));
+ assertThat(error.getMessage(), equalTo("Expected end of document, but was number '2'"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:5
- [x] ]x
- ^"""
- ));
- }
-
- @Test
- public void whenProjectConfigHasShedThatArentArrayThenErrorIsThrown() {
- var error = assertThrows(
- ConfigError.class,
- () -> ProjectConfig.fromString(PROJECT_PATH, """
- shed = true"""
- )
- );
-
- assertThat(error.getMessage(), equalTo("Expected shed to be a table, but was Boolean"));
- assertThat(error.source().describe(), equalTo("""
- <string>:1:1
- shed = true
- ^"""
+ <string>:4:3
+ 2
+ ^"""
));
}
@Test
public void canParseProjectConfigWithNoBins() {
- var config = ProjectConfig.fromString(PROJECT_PATH, "");
+ var config = ProjectConfig.fromString(PROJECT_PATH, "{}");
assertThat(config.bins(), isSequence());
}
@@ -71,13 +54,18 @@ public class ProjectConfigTests {
@Test
public void canParseProjectConfigWithBins() {
var config = ProjectConfig.fromString(PROJECT_PATH, """
- [[shed.bins]]
- name = "one"
- main-namespace = "One"
-
- [[shed.bins]]
- name = "two"
- main-namespace = "Two"
+ {
+ bins: [
+ {
+ name: "one",
+ mainNamespace: "One",
+ },
+ {
+ name: "two",
+ mainNamespace: "Two",
+ },
+ ],
+ }
""");
assertThat(config.bins(), isSequence(
@@ -99,40 +87,40 @@ public class ProjectConfigTests {
var error = assertThrows(
ConfigError.class,
() -> ProjectConfig.fromString(PROJECT_PATH, """
- [shed]
- bins = true"""
+ {bins: true}"""
)
);
- assertThat(error.getMessage(), equalTo("Expected shed.bins to be an array, but was Boolean"));
+ assertThat(error.getMessage(), equalTo("Expected bins to be array, but was boolean"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:1
- bins = true
- ^"""
+ <string>:1:8
+ {bins: true}
+ ^"""
));
}
@Test
- public void whenProjectConfigHasBinThatIsntTableThenErrorIsThrown() {
+ public void whenProjectConfigHasBinThatIsntObjectThenErrorIsThrown() {
var error = assertThrows(
ConfigError.class,
() -> ProjectConfig.fromString(PROJECT_PATH, """
- [shed]
- bins = [1]"""
+ {
+ bins: [1],
+ }"""
)
);
- assertThat(error.getMessage(), equalTo("Expected shed.bins[0] to be a table, but was Long"));
+ assertThat(error.getMessage(), equalTo("Expected bins[0] to be object, but was finite number"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:9
- bins = [1]
- ^"""
+ <string>:2:12
+ bins: [1],
+ ^"""
));
}
@Test
public void canParseProjectConfigWithNoExamples() {
- var config = ProjectConfig.fromString(PROJECT_PATH, "");
+ var config = ProjectConfig.fromString(PROJECT_PATH, "{}");
assertThat(config.examples(), isSequence());
}
@@ -140,11 +128,12 @@ public class ProjectConfigTests {
@Test
public void canParseProjectConfigWithExamples() {
var config = ProjectConfig.fromString(PROJECT_PATH, """
- [[shed.examples]]
- bin = "one"
-
- [[shed.examples]]
- bin = "two"
+ {
+ examples: [
+ {bin: "one"},
+ {bin: "two"},
+ ],
+ }
""");
assertThat(config.examples(), isSequence(
@@ -164,40 +153,40 @@ public class ProjectConfigTests {
var error = assertThrows(
ConfigError.class,
() -> ProjectConfig.fromString(PROJECT_PATH, """
- [shed]
- examples = true"""
+ {examples: true}"""
)
);
- assertThat(error.getMessage(), equalTo("Expected shed.examples to be an array, but was Boolean"));
+ assertThat(error.getMessage(), equalTo("Expected examples to be array, but was boolean"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:1
- examples = true
- ^"""
+ <string>:1:12
+ {examples: true}
+ ^"""
));
}
@Test
- public void whenProjectConfigHasExampleThatIsntTableThenErrorIsThrown() {
+ public void whenProjectConfigHasExampleThatIsntObjectThenErrorIsThrown() {
var error = assertThrows(
ConfigError.class,
() -> ProjectConfig.fromString(PROJECT_PATH, """
- [shed]
- examples = [1]"""
+ {
+ examples: [1],
+ }"""
)
);
- assertThat(error.getMessage(), equalTo("Expected shed.examples[0] to be a table, but was Long"));
+ assertThat(error.getMessage(), equalTo("Expected examples[0] to be object, but was finite number"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:13
- examples = [1]
- ^"""
+ <string>:2:16
+ examples: [1],
+ ^"""
));
}
@Test
public void canParseProjectConfigWithNoProfiles() {
- var config = ProjectConfig.fromString(PROJECT_PATH, "");
+ var config = ProjectConfig.fromString(PROJECT_PATH, "{}");
assertThat(config.profiles(), isSequence());
}
@@ -205,11 +194,12 @@ public class ProjectConfigTests {
@Test
public void canParseProjectConfigWithProfiles() {
var config = ProjectConfig.fromString(PROJECT_PATH, """
- [[shed.profiles]]
- name = "one"
-
- [[shed.profiles]]
- name = "two"
+ {
+ profiles: [
+ {name: "one"},
+ {name: "two"},
+ ],
+ }
""");
assertThat(config.profiles(), isSequence(
@@ -229,34 +219,34 @@ public class ProjectConfigTests {
var error = assertThrows(
ConfigError.class,
() -> ProjectConfig.fromString(PROJECT_PATH, """
- [shed]
- profiles = true"""
+ {profiles: true}"""
)
);
- assertThat(error.getMessage(), equalTo("Expected shed.profiles to be an array, but was Boolean"));
+ assertThat(error.getMessage(), equalTo("Expected profiles to be array, but was boolean"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:1
- profiles = true
- ^"""
+ <string>:1:12
+ {profiles: true}
+ ^"""
));
}
@Test
- public void whenProjectConfigHasProfileThatIsntTableThenErrorIsThrown() {
+ public void whenProjectConfigHasProfileThatIsntObjectThenErrorIsThrown() {
var error = assertThrows(
ConfigError.class,
() -> ProjectConfig.fromString(PROJECT_PATH, """
- [shed]
- profiles = [1]"""
+ {
+ profiles: [1],
+ }"""
)
);
- assertThat(error.getMessage(), equalTo("Expected shed.profiles[0] to be a table, but was Long"));
+ assertThat(error.getMessage(), equalTo("Expected profiles[0] to be object, but was finite number"));
assertThat(error.source().describe(), equalTo("""
- <string>:2:13
- profiles = [1]
- ^"""
+ <string>:2:16
+ profiles: [1],
+ ^"""
));
}
}
diff --git a/src/test/java/org/shedlang/compiler/config/json/Json5ObjectWithSourceTests.java b/src/test/java/org/shedlang/compiler/config/json/Json5ObjectWithSourceTests.java
new file mode 100644
index 00000000..ad7f7c1c
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/config/json/Json5ObjectWithSourceTests.java
@@ -0,0 +1,406 @@
+package org.shedlang.compiler.config.json;
+
+import org.junit.jupiter.api.Test;
+import org.shedlang.compiler.config.errors.ConfigError;
+import org.shedlang.compiler.sources.Sources;
+
+import java.util.Optional;
+import java.util.OptionalLong;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.*;
+
+public class Json5ObjectWithSourceTests {
+ @Test
+ public void whenMemberIsMissingThenGetLongThrowsError() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLong("x")
+ );
+
+ assertThat(error.getMessage(), equalTo("a.b[1] is missing x"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:13
+ {},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsNotNumberFiniteThenGetLongThrowsError() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {x: true},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLong("x")
+ );
+
+ assertThat(error.getMessage(), equalTo("Expected a.b[1].x to be finite number, but was boolean"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:17
+ {x: true},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsFiniteNumberButIsNotLongThenGetLongThrowsError() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {x: 1.2},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLong("x")
+ );
+
+ assertThat(error.getMessage(), equalTo("a.b[1].x must be a 64-bit integer"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:17
+ {x: 1.2},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsLongThenGetLongReturnsValue() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {x : 2},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var result = object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLong("x");
+
+ assertThat(result, equalTo(2L));
+ }
+ @Test
+ public void whenMemberIsMissingThenGetLongOrNoneReturnsEmptyOptional() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var result = object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLongOrNone("x");
+
+ assertThat(result, equalTo(OptionalLong.empty()));
+ }
+
+ @Test
+ public void whenMemberIsNotLongThenGetLongOrNoneThrowsError() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {x: true},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLongOrNone("x")
+ );
+
+ assertThat(error.getMessage(), equalTo("Expected a.b[1].x to be finite number, but was boolean"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:17
+ {x: true},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsLongOrNoneThenGetLongReturnsValue() {
+ var source = Sources.string("""
+ {
+ a: {
+ b: [
+ {x: 1},
+ {x: 2},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var result = object
+ .getObject("a")
+ .orElseThrow()
+ .getArrayOfObjects("b")
+ .orElseThrow()
+ .get(1)
+ .getLongOrNone("x");
+
+ assertThat(result, equalTo(OptionalLong.of(2L)));
+ }
+
+ @Test
+ public void whenMemberIsMissingThenGetStringThrowsError() {
+ var source = Sources.string("""
+ {
+ shed: {
+ bins: [
+ {name: "one"},
+ {},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("shed")
+ .orElseThrow()
+ .getArrayOfObjects("bins")
+ .orElseThrow()
+ .get(1)
+ .getString("name")
+ );
+
+ assertThat(error.getMessage(), equalTo("shed.bins[1] is missing name"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:13
+ {},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsNotStringThenGetStringThrowsError() {
+ var source = Sources.string("""
+ {
+ shed: {
+ bins: [
+ {name: "one"},
+ {name: true},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("shed")
+ .orElseThrow()
+ .getArrayOfObjects("bins")
+ .orElseThrow()
+ .get(1)
+ .getString("name")
+ );
+
+ assertThat(error.getMessage(), equalTo("Expected shed.bins[1].name to be string, but was boolean"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:20
+ {name: true},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsStringThenGetStringReturnsValue() {
+ var source = Sources.string("""
+ {
+ shed: {
+ bins: [
+ {name: "one"},
+ {name: "two"},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var result = object
+ .getObject("shed")
+ .orElseThrow()
+ .getArrayOfObjects("bins")
+ .orElseThrow()
+ .get(1)
+ .getString("name");
+
+ assertThat(result.value(), equalTo("two"));
+ assertThat(result.source().describe(), equalTo(
+ """
+ <string>:5:20
+ {name: "two"},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsMissingThenGetStringOrNoneReturnsEmptyOptional() {
+ var source = Sources.string("""
+ {
+ shed: {
+ bins: [
+ {name: "one"},
+ {},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var result = object
+ .getObject("shed")
+ .orElseThrow()
+ .getArrayOfObjects("bins")
+ .orElseThrow()
+ .get(1)
+ .getStringOrNone("name");
+
+ assertThat(result, equalTo(Optional.empty()));
+ }
+
+ @Test
+ public void whenMemberIsNotStringThenGetStringOrNoneThrowsError() {
+ var source = Sources.string("""
+ {
+ shed: {
+ bins: [
+ {name: "one"},
+ {name: true},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var error = assertThrows(
+ ConfigError.class,
+ () -> object
+ .getObject("shed")
+ .orElseThrow()
+ .getArrayOfObjects("bins")
+ .orElseThrow()
+ .get(1)
+ .getStringOrNone("name")
+ );
+
+ assertThat(error.getMessage(), equalTo("Expected shed.bins[1].name to be string, but was boolean"));
+ assertThat(error.source().describe(), equalTo("""
+ <string>:5:20
+ {name: true},
+ ^"""
+ ));
+ }
+
+ @Test
+ public void whenMemberIsStringThenGetStringOrNoneReturnsValue() {
+ var source = Sources.string("""
+ {
+ shed: {
+ bins: [
+ {name: "one"},
+ {name: "two"},
+ ],
+ },
+ }
+ """);
+ var object = Json5ObjectWithSource.parse(source);
+
+ var result = object
+ .getObject("shed")
+ .orElseThrow()
+ .getArrayOfObjects("bins")
+ .orElseThrow()
+ .get(1)
+ .getStringOrNone("name");
+
+ assertThat(result.orElseThrow().value(), equalTo("two"));
+ assertThat(result.orElseThrow().source().describe(), equalTo(
+ """
+ <string>:5:20
+ {name: "two"},
+ ^"""
+ ));
+ }
+}
diff --git a/src/test/java/org/shedlang/compiler/config/toml/TomlTableWithSourceTests.java b/src/test/java/org/shedlang/compiler/config/toml/TomlTableWithSourceTests.java
deleted file mode 100644
index 1086671c..00000000
--- a/src/test/java/org/shedlang/compiler/config/toml/TomlTableWithSourceTests.java
+++ /dev/null
@@ -1,325 +0,0 @@
-package org.shedlang.compiler.config.toml;
-
-import org.junit.jupiter.api.Test;
-import org.shedlang.compiler.config.errors.ConfigError;
-import org.shedlang.compiler.sources.Sources;
-
-import java.util.Optional;
-import java.util.OptionalLong;
-
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.zwobble.precisely.AssertThat.assertThat;
-import static org.zwobble.precisely.Matchers.equalTo;
-
-public class TomlTableWithSourceTests {
- @Test
- public void whenKeyIsMissingThenGetLongThrowsError() {
- var source = Sources.string("""
- [[a.b]]
- x = 1
-
- [[a.b]]
- """);
- var table = TomlTableWithSource.parse(source);
-
- var error = assertThrows(
- ConfigError.class,
- () -> table
- .getTable("a")
- .orElseThrow()
- .getArrayOfTables("b")
- .orElseThrow()
- .get(1)
- .getLong("x")
- );
-
- assertThat(error.getMessage(), equalTo("a.b[1] is missing x"));
- assertThat(error.source().describe(), equalTo("""
- <string>:4:1
- [[a.b]]
- ^"""
- ));
- }
-
- @Test
- public void whenKeyIsNotLongThenGetLongThrowsError() {
- var source = Sources.string("""
- [[a.b]]
- x = 1
-
- [[a.b]]
- x = true
- """);
- var table = TomlTableWithSource.parse(source);
-
- var error = assertThrows(
- ConfigError.class,
- () -> table
- .getTable("a")
- .orElseThrow()
- .getArrayOfTables("b")
- .orElseThrow()
- .get(1)
- .getLong("x")
- );
-
- assertThat(error.getMessage(), equalTo("Expected a.b[1].x to be a long, but was Boolean"));
- assertThat(error.source().describe(), equalTo("""
- <string>:5:1
- x = true
- ^"""
- ));
- }
-
- @Test
- public void whenKeyIsLongThenGetLongReturnsValue() {
- var source = Sources.string("""
- [[a.b]]
- x = 1
-
- [[a.b]]
- x = 2
- """);
- var table = TomlTableWithSource.parse(source);
-
- var result = table
- .getTable("a")
- .orElseThrow()
- .getArrayOfTables("b")
- .orElseThrow()
- .get(1)
- .getLong("x");
-
- assertThat(result, equalTo(2L));
- }
- @Test
- public void whenKeyIsMissingThenGetLongOrNoneReturnsEmptyOptional() {
- var source = Sources.string("""
- [[a.b]]
- x = 1
-
- [[a.b]]
- """);
- var table = TomlTableWithSource.parse(source);
-
- var result = table
- .getTable("a")
- .orElseThrow()
- .getArrayOfTables("b")
- .orElseThrow()
- .get(1)
- .getLongOrNone("x");
-
- assertThat(result, equalTo(OptionalLong.empty()));
- }
-
- @Test
- public void whenKeyIsNotLongThenGetLongOrNoneThrowsError() {
- var source = Sources.string("""
- [[a.b]]
- x = 1
-
- [[a.b]]
- x = true
- """);
- var table = TomlTableWithSource.parse(source);
-
- var error = assertThrows(
- ConfigError.class,
- () -> table
- .getTable("a")
- .orElseThrow()
- .getArrayOfTables("b")
- .orElseThrow()
- .get(1)
- .getLongOrNone("x")
- );
-
- assertThat(error.getMessage(), equalTo("Expected a.b[1].x to be a long, but was Boolean"));
- assertThat(error.source().describe(), equalTo("""
- <string>:5:1
- x = true
- ^"""
- ));
- }
-
- @Test
- public void whenKeyIsLongOrNoneThenGetLongReturnsValue() {
- var source = Sources.string("""
- [[a.b]]
- x = 1
-
- [[a.b]]
- x = 2
- """);
- var table = TomlTableWithSource.parse(source);
-
- var result = table
- .getTable("a")
- .orElseThrow()
- .getArrayOfTables("b")
- .orElseThrow()
- .get(1)
- .getLongOrNone("x");
-
- assertThat(result, equalTo(OptionalLong.of(2L)));
- }
-
- @Test
- public void whenKeyIsMissingThenGetStringThrowsError() {
- var source = Sources.string("""
- [[shed.bins]]
- name = "one"
-
- [[shed.bins]]
- """);
- var table = TomlTableWithSource.parse(source);
-
- var error = assertThrows(
- ConfigError.class,
- () -> table
- .getTable("shed")
- .orElseThrow()
- .getArrayOfTables("bins")
- .orElseThrow()
- .get(1)
- .getString("name")
- );
-
- assertThat(error.getMessage(), equalTo("shed.bins[1] is missing name"));
- assertThat(error.source().describe(), equalTo("""
- <string>:4:1
- [[shed.bins]]
- ^"""
- ));
- }
-
- @Test
- public void whenKeyIsNotStringThenGetStringThrowsError() {
- var source = Sources.string("""
- [[shed.bins]]
- name = "one"
-
- [[shed.bins]]
- name = true
- """);
- var table = TomlTableWithSource.parse(source);
-
- var error = assertThrows(
- ConfigError.class,
- () -> table
- .getTable("shed")
- .orElseThrow()
- .getArrayOfTables("bins")
- .orElseThrow()
- .get(1)
- .getString("name")
- );
-
- assertThat(error.getMessage(), equalTo("Expected shed.bins[1].name to be a string, but was Boolean"));
- assertThat(error.source().describe(), equalTo("""
- <string>:5:1
- name = true
- ^"""
- ));
- }
-
- @Test
- public void whenKeyIsStringThenGetStringReturnsValue() {
- var source = Sources.string("""
- [[shed.bins]]
- name = "one"
-
- [[shed.bins]]
- name = "two"
- """);
- var table = TomlTableWithSource.parse(source);
-
- var result = table
- .getTable("shed")
- .orElseThrow()
- .getArrayOfTables("bins")
- .orElseThrow()
- .get(1)
- .getString("name");
-
- assertThat(result, equalTo(
- new TomlString("two", source.at(42, 42))
- ));
- }
-
- @Test
- public void whenKeyIsMissingThenGetStringOrNoneReturnsEmptyOptional() {
- var source = Sources.string("""
- [[shed.bins]]
- name = "one"
-
- [[shed.bins]]
- """);
- var table = TomlTableWithSource.parse(source);
-
- var result = table
- .getTable("shed")
- .orElseThrow()
- .getArrayOfTables("bins")
- .orElseThrow()
- .get(1)
- .getStringOrNone("name");
-
- assertThat(result, equalTo(Optional.empty()));
- }
-
- @Test
- public void whenKeyIsNotStringThenGetStringOrNoneThrowsError() {
- var source = Sources.string("""
- [[shed.bins]]
- name = "one"
-
- [[shed.bins]]
- name = true
- """);
- var table = TomlTableWithSource.parse(source);
-
- var error = assertThrows(
- ConfigError.class,
- () -> table
- .getTable("shed")
- .orElseThrow()
- .getArrayOfTables("bins")
- .orElseThrow()
- .get(1)
- .getStringOrNone("name")
- );
-
- assertThat(error.getMessage(), equalTo("Expected shed.bins[1].name to be a string, but was Boolean"));
- assertThat(error.source().describe(), equalTo("""
- <string>:5:1
- name = true
- ^"""
- ));
- }
-
- @Test
- public void whenKeyIsStringThenGetStringOrNoneReturnsValue() {
- var source = Sources.string("""
- [[shed.bins]]
- name = "one"
-
- [[shed.bins]]
- name = "two"
- """);
- var table = TomlTableWithSource.parse(source);
-
- var result = table
- .getTable("shed")
- .orElseThrow()
- .getArrayOfTables("bins")
- .orElseThrow()
- .get(1)
- .getStringOrNone("name");
-
- assertThat(result, equalTo(Optional.of(
- new TomlString("two", source.at(42, 42))
- )));
- }
-}