Skip to content

Commit f97980b

Browse files
committed
Changed outputs spec
1 parent 1e202b9 commit f97980b

3 files changed

Lines changed: 15 additions & 128 deletions

File tree

solves/src/_unused/parse-simple-template.ts

Lines changed: 0 additions & 94 deletions
This file was deleted.

solves/src/spec-parse.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ function ensureNum(obj: any, argName: string): number {
2222
throw new Error(`'${argName}' spec key is not a number.`);
2323
}
2424

25-
/*
26-
* Ensures that the field IDs match what's actually found in the template.
27-
* Throws human-readable exceptions if errors are found.
28-
*/
29-
function validateOutputPartialSpec(o: OutputPartialSpec): void {
30-
const fields: Set<string> = new Set(Object.keys(o.fields));
31-
console.assert(fields.size === Object.keys(o.fields).length);
32-
33-
// TODO: Length of fields?
34-
}
35-
3625
function inputTransform(obj: any) {
3726
// TODO: Simplify this later.
3827
const title: string = ensureStr(obj.title, "input[].title");
@@ -48,6 +37,9 @@ function inputTransform(obj: any) {
4837

4938
/********************************************************************/
5039

40+
interface OutputFieldSpec {
41+
label: string;
42+
}
5143

5244
interface InputPartialSpec {
5345
title: string;
@@ -57,9 +49,7 @@ interface InputPartialSpec {
5749

5850
interface OutputPartialSpec {
5951
title: string;
60-
fields: {[key: string]: {
61-
title: string;
62-
}};
52+
fields: OutputFieldSpec[];
6353
}
6454

6555
export interface SpecValues {
@@ -107,24 +97,16 @@ export function getSpecValues(specPath: string): SpecValues {
10797

10898
output: objectValueMap(output, (obj: any) => {
10999
const title: string = ensureStr(obj.title, "output[].title");
110-
const fields: any = obj.fields;
111-
if (typeof fields !== "object") {
112-
throw new Error(`Output ${obj.title} must provide a fields specification object.`);
100+
const fieldLabels: any = obj.fieldLabels;
101+
if (!Array.isArray(fieldLabels)) {
102+
throw new Error(`Output ${obj.title} must provide a fields specification array.`);
113103
}
114104

115-
const newFieldsEntries = Object.fromEntries(Object.entries(fields).map(
116-
([k, v]) => {
117-
const fieldKey: string = ensureStr(k, `output[].fields.${title} key`);
118-
const fieldTitle: string = ensureStr(v, `output[].fields.${title} value`);
119-
return [fieldKey, {title: fieldTitle}];
120-
}
121-
));
122-
123-
const outputObj = {
124-
title,
125-
fields: newFieldsEntries,
126-
};
127-
validateOutputPartialSpec(outputObj);
105+
const fields: OutputFieldSpec[] = fieldLabels.map(
106+
x => ({label: ensureStr(x, `output[].fields[].label`)})
107+
);
108+
109+
const outputObj = {title, fields};
128110
return outputObj;
129111
}),
130112
};

solves/test/sample-spec.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ constraints: |
3434
output:
3535
color:
3636
title: Colourings
37-
#params: 2
38-
fields:
39-
vertex: Vertex
40-
colour: Colour
37+
fieldLabels:
38+
- Vertex
39+
- Colour
4140

4241
encoding: |
4342
{ solution(color(V,C)) } :- base(vertex, V), base(colour, C).

0 commit comments

Comments
 (0)