@kensnzk/koyu 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +2 -2
- package/README.md +3 -3
- package/dist/cli.js +156 -81
- package/dist/cli.js.map +1 -1
- package/dist/core/derive.d.ts +259 -0
- package/dist/core/derive.d.ts.map +1 -0
- package/dist/core/derive.js +570 -0
- package/dist/core/derive.js.map +1 -0
- package/dist/{check.d.ts → core/diagnose.d.ts} +11 -12
- package/dist/core/diagnose.d.ts.map +1 -0
- package/dist/{check.js → core/diagnose.js} +232 -221
- package/dist/core/diagnose.js.map +1 -0
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/{diff.js → core/diff.js} +84 -41
- package/dist/core/diff.js.map +1 -0
- package/dist/{fabric.d.ts → core/fabric.d.ts} +4 -0
- package/dist/core/fabric.d.ts.map +1 -0
- package/dist/{fabric.js → core/fabric.js} +4 -3
- package/dist/core/fabric.js.map +1 -0
- package/dist/{graph.d.ts → core/graph.d.ts} +1 -3
- package/dist/core/graph.d.ts.map +1 -0
- package/dist/{graph.js → core/graph.js} +43 -51
- package/dist/core/graph.js.map +1 -0
- package/dist/core/light.d.ts +24 -0
- package/dist/core/light.d.ts.map +1 -0
- package/dist/{light.js → core/light.js} +15 -10
- package/dist/core/light.js.map +1 -0
- package/dist/{model.d.ts → core/model.d.ts} +124 -13
- package/dist/core/model.d.ts.map +1 -0
- package/dist/{model.js → core/model.js} +186 -49
- package/dist/core/model.js.map +1 -0
- package/dist/core/parse.d.ts.map +1 -0
- package/dist/{parse.js → core/parse.js} +528 -116
- package/dist/core/parse.js.map +1 -0
- package/dist/{poly.d.ts → core/poly.d.ts} +3 -2
- package/dist/core/poly.d.ts.map +1 -0
- package/dist/{poly.js → core/poly.js} +8 -9
- package/dist/core/poly.js.map +1 -0
- package/dist/core/site.d.ts.map +1 -0
- package/dist/core/site.js.map +1 -0
- package/dist/core/tolerance.d.ts +26 -0
- package/dist/core/tolerance.d.ts.map +1 -0
- package/dist/core/tolerance.js +48 -0
- package/dist/core/tolerance.js.map +1 -0
- package/dist/{vertical.d.ts → core/vertical.d.ts} +41 -12
- package/dist/core/vertical.d.ts.map +1 -0
- package/dist/{vertical.js → core/vertical.js} +45 -104
- package/dist/core/vertical.js.map +1 -0
- package/dist/core/vocabulary.d.ts +40 -0
- package/dist/core/vocabulary.d.ts.map +1 -0
- package/dist/core/vocabulary.js +164 -0
- package/dist/core/vocabulary.js.map +1 -0
- package/dist/{axo.d.ts → draw/axo.d.ts} +1 -1
- package/dist/draw/axo.d.ts.map +1 -0
- package/dist/{axo.js → draw/axo.js} +53 -81
- package/dist/draw/axo.js.map +1 -0
- package/dist/draw/index.d.ts +3 -0
- package/dist/draw/index.d.ts.map +1 -0
- package/dist/draw/index.js +11 -0
- package/dist/draw/index.js.map +1 -0
- package/dist/draw/plan.d.ts +10 -0
- package/dist/draw/plan.d.ts.map +1 -0
- package/dist/draw/plan.js +284 -0
- package/dist/draw/plan.js.map +1 -0
- package/dist/index.d.ts +15 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +71 -40
- package/dist/mcp.js.map +1 -1
- package/dist/parse-file.d.ts +1 -1
- package/dist/parse-file.d.ts.map +1 -1
- package/dist/parse-file.js +1 -1
- package/dist/parse-file.js.map +1 -1
- package/dist/validate/access.d.ts +6 -0
- package/dist/validate/access.d.ts.map +1 -0
- package/dist/validate/access.js +238 -0
- package/dist/validate/access.js.map +1 -0
- package/dist/validate/envelope.d.ts +4 -0
- package/dist/validate/envelope.d.ts.map +1 -0
- package/dist/validate/envelope.js +55 -0
- package/dist/validate/envelope.js.map +1 -0
- package/dist/validate/index.d.ts +60 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +77 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/light.d.ts +6 -0
- package/dist/validate/light.d.ts.map +1 -0
- package/dist/validate/light.js +28 -0
- package/dist/validate/light.js.map +1 -0
- package/dist/validate/runs.d.ts +16 -0
- package/dist/validate/runs.d.ts.map +1 -0
- package/dist/validate/runs.js +60 -0
- package/dist/validate/runs.js.map +1 -0
- package/dist/validate/site.d.ts +6 -0
- package/dist/validate/site.d.ts.map +1 -0
- package/dist/validate/site.js +63 -0
- package/dist/validate/site.js.map +1 -0
- package/editors/vscode/.vscodeignore +2 -0
- package/editors/vscode/README.md +28 -0
- package/editors/vscode/extension.js +150 -0
- package/editors/vscode/language-configuration.json +19 -0
- package/editors/vscode/package.json +57 -0
- package/editors/vscode/syntaxes/koyu.tmLanguage.json +226 -0
- package/examples/basement/main.muro +1 -1
- package/examples/complex/main.muro +1 -1
- package/examples/house/main.muro +2 -2
- package/examples/house.muro +2 -2
- package/examples/mansion.muro +2 -2
- package/examples/office.muro +2 -2
- package/examples/steps/01-one-room.muro +1 -1
- package/examples/steps/02-two-rooms.muro +1 -1
- package/examples/steps/03-door.muro +1 -1
- package/examples/steps/04-exterior.muro +1 -1
- package/examples/steps/05-two-storeys.muro +1 -1
- package/examples/steps/06-finished.muro +2 -2
- package/examples/tower/main.muro +1 -1
- package/examples/twin/main.muro +2 -2
- package/examples/two-rooms.canonical.json +4 -2
- package/examples/two-rooms.muro +2 -2
- package/package.json +16 -1
- package/spec/README.md +28 -0
- package/spec/canonical-json.md +98 -0
- package/spec/composition.md +121 -0
- package/spec/derivation.md +393 -0
- package/spec/en/README.md +30 -0
- package/spec/en/canonical-json.md +101 -0
- package/spec/en/composition.md +121 -0
- package/spec/en/derivation.md +393 -0
- package/spec/en/language.md +164 -0
- package/spec/en/notation-v0.md +145 -0
- package/spec/en/scope.md +229 -0
- package/spec/en/semantics.md +132 -0
- package/spec/en/tools.md +108 -0
- package/spec/en/validation.md +79 -0
- package/spec/en/vocabulary.md +103 -0
- package/spec/language.md +163 -0
- package/spec/notation-v0.md +184 -0
- package/spec/scope.md +229 -0
- package/spec/semantics.md +130 -0
- package/spec/tools.md +106 -0
- package/spec/validation.md +79 -0
- package/spec/vocabulary.md +114 -0
- package/src/cli.ts +165 -80
- package/src/core/derive.ts +852 -0
- package/src/{check.ts → core/diagnose.ts} +260 -229
- package/src/{diff.ts → core/diff.ts} +84 -40
- package/src/{fabric.ts → core/fabric.ts} +4 -3
- package/src/{graph.ts → core/graph.ts} +47 -60
- package/src/core/light.ts +69 -0
- package/src/{model.ts → core/model.ts} +228 -51
- package/src/{parse.ts → core/parse.ts} +584 -116
- package/src/{poly.ts → core/poly.ts} +8 -9
- package/src/core/tolerance.ts +55 -0
- package/src/{vertical.ts → core/vertical.ts} +65 -115
- package/src/core/vocabulary.ts +197 -0
- package/src/{axo.ts → draw/axo.ts} +51 -94
- package/src/draw/index.ts +11 -0
- package/src/draw/plan.ts +344 -0
- package/src/index.ts +181 -35
- package/src/mcp.ts +76 -40
- package/src/parse-file.ts +2 -2
- package/src/validate/access.ts +279 -0
- package/src/validate/envelope.ts +59 -0
- package/src/validate/index.ts +107 -0
- package/src/validate/light.ts +43 -0
- package/src/validate/runs.ts +87 -0
- package/src/validate/site.ts +84 -0
- package/dist/axo.d.ts.map +0 -1
- package/dist/axo.js.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/check.js.map +0 -1
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js.map +0 -1
- package/dist/fabric.d.ts.map +0 -1
- package/dist/fabric.js.map +0 -1
- package/dist/graph.d.ts.map +0 -1
- package/dist/graph.js.map +0 -1
- package/dist/light.d.ts +0 -15
- package/dist/light.d.ts.map +0 -1
- package/dist/light.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/parse.d.ts.map +0 -1
- package/dist/parse.js.map +0 -1
- package/dist/plan.d.ts +0 -10
- package/dist/plan.d.ts.map +0 -1
- package/dist/plan.js +0 -354
- package/dist/plan.js.map +0 -1
- package/dist/poly.d.ts.map +0 -1
- package/dist/poly.js.map +0 -1
- package/dist/site.d.ts.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/vertical.d.ts.map +0 -1
- package/dist/vertical.js.map +0 -1
- package/src/light.ts +0 -63
- package/src/plan.ts +0 -472
- /package/dist/{diff.d.ts → core/diff.d.ts} +0 -0
- /package/dist/{parse.d.ts → core/parse.d.ts} +0 -0
- /package/dist/{site.d.ts → core/site.d.ts} +0 -0
- /package/dist/{site.js → core/site.js} +0 -0
- /package/src/{site.ts → core/site.ts} +0 -0
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
type Area,
|
|
8
|
+
type Asset,
|
|
8
9
|
type Attrs,
|
|
9
10
|
type AttrValue,
|
|
10
11
|
type Boundary,
|
|
11
12
|
DEFAULT_LANGUAGE_VERSION,
|
|
12
13
|
type Edge,
|
|
14
|
+
type Level,
|
|
13
15
|
type Model,
|
|
14
16
|
type Opening,
|
|
15
17
|
type Pt,
|
|
@@ -18,9 +20,13 @@ import {
|
|
|
18
20
|
SourceError,
|
|
19
21
|
type Space,
|
|
20
22
|
SUPPORTED_LANGUAGE_VERSIONS,
|
|
23
|
+
type Zone,
|
|
21
24
|
} from "./model.js";
|
|
22
25
|
import { deriveDefaultBoundaries, derivePieces } from "./graph.js";
|
|
23
26
|
|
|
27
|
+
/** 境界のトポロジー語 — 増やすのは最後の手段である (spec/vocabulary.md 規則1) */
|
|
28
|
+
const BOUNDARY_KINDS = new Set(["wall", "open", "stair", "shaft", "void"]);
|
|
29
|
+
|
|
24
30
|
const EDGES = new Set(["N", "E", "S", "W"]);
|
|
25
31
|
|
|
26
32
|
/**
|
|
@@ -64,6 +70,8 @@ function emptyModel(): Model {
|
|
|
64
70
|
polygons: new Map(),
|
|
65
71
|
columns: [],
|
|
66
72
|
layers: [],
|
|
73
|
+
attrSrc: new Map(),
|
|
74
|
+
compositionEdits: [],
|
|
67
75
|
};
|
|
68
76
|
}
|
|
69
77
|
|
|
@@ -77,7 +85,7 @@ export type LayerLoader = (
|
|
|
77
85
|
export function parse(source: string): Model {
|
|
78
86
|
const model = emptyModel();
|
|
79
87
|
ingest(model, source, undefined, new Set(), undefined);
|
|
80
|
-
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 /
|
|
88
|
+
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 / spec/derivation.md §1)。
|
|
81
89
|
// 逆順だと、線で接触が消えた組にも既定境界が生まれ、線分ゼロの境界に
|
|
82
90
|
// 出所の無い BND04 が出る — 書いていない関係を責めることになる
|
|
83
91
|
derivePieces(model);
|
|
@@ -92,10 +100,10 @@ export function parseWith(loader: LayerLoader, entry: string): Model {
|
|
|
92
100
|
try {
|
|
93
101
|
layer = loader(undefined, entry);
|
|
94
102
|
} catch {
|
|
95
|
-
throw new SourceError(0,
|
|
103
|
+
throw new SourceError(0, `Cannot read file: ${entry}`);
|
|
96
104
|
}
|
|
97
105
|
ingestLayer(model, layer.key, layer.src, new Set(), loader);
|
|
98
|
-
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 /
|
|
106
|
+
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 / spec/derivation.md §1)。
|
|
99
107
|
// 逆順だと、線で接触が消えた組にも既定境界が生まれ、線分ゼロの境界に
|
|
100
108
|
// 出所の無い BND04 が出る — 書いていない関係を責めることになる
|
|
101
109
|
derivePieces(model);
|
|
@@ -141,7 +149,9 @@ function ingestLayer(
|
|
|
141
149
|
): void {
|
|
142
150
|
if (seen.has(key)) return; // 同じレイヤーは一度だけ合成される (USDのsublayerと同じ)
|
|
143
151
|
seen.add(key);
|
|
144
|
-
|
|
152
|
+
// **この push の順序が層の強度順序である** (spec/composition.md 規則1)。
|
|
153
|
+
// entry が添字0で最も弱く、後の層ほど強い。同じ層が二度 import されても最初の位置を保つ
|
|
154
|
+
model.layers.push(key);
|
|
145
155
|
ingest(model, src, key, seen, loader);
|
|
146
156
|
}
|
|
147
157
|
|
|
@@ -152,10 +162,17 @@ function ingest(
|
|
|
152
162
|
seen: Set<string>,
|
|
153
163
|
loader: LayerLoader | undefined,
|
|
154
164
|
): void {
|
|
165
|
+
/** この層の強度。単一ソースの parse では層が無いので 0 とする */
|
|
166
|
+
const layer = file === undefined ? 0 : Math.max(0, model.layers.indexOf(file));
|
|
155
167
|
let current: Boundary[] = [];
|
|
156
168
|
let currentSpaces: Space[] = [];
|
|
169
|
+
let over: OverTarget | undefined;
|
|
157
170
|
let band: BandDecl | undefined; // 帯は次の非字下げ行か層の終わりで展開される (ADR-0019)
|
|
158
|
-
|
|
171
|
+
// **原本は NFC として読む** (ADR-0036)。`が` は一つの符号位置とも「か + 濁点」とも綴れ、
|
|
172
|
+
// 正規化しなければ同じに見える二つのパスが別の空間になり (パス重複のエラーも出ない)、
|
|
173
|
+
// 正準JSONには見分けのつかないキーが二つ並ぶ。同一性はここで一つに決める。
|
|
174
|
+
// NFKC は採らない — ㎡ や ① を書き換えてしまい、それは書かれた表記の保存に反する
|
|
175
|
+
const lines = source.normalize("NFC").split(/\r?\n/);
|
|
159
176
|
|
|
160
177
|
for (let i = 0; i < lines.length; i++) {
|
|
161
178
|
try {
|
|
@@ -167,45 +184,54 @@ function ingest(
|
|
|
167
184
|
const [head, ...rest] = tokens as [string, ...string[]];
|
|
168
185
|
|
|
169
186
|
if (indented) {
|
|
170
|
-
if (head === "
|
|
187
|
+
if (over && (head === "+" || head === "-" || head === "=")) {
|
|
188
|
+
// 1.0 の語である — 出所を残す (VER04。上書きの跡は合成後に残らない — ADR-0038)
|
|
189
|
+
model.compositionEdits.push({ word: head, subject: rest.join(" "), line: ln, file });
|
|
190
|
+
applySetEdit(model, over, head, rest, ln, layer);
|
|
191
|
+
} else if (over) {
|
|
192
|
+
throw new SourceError(
|
|
193
|
+
ln,
|
|
194
|
+
`Only + (add) / - (remove) / = (replace) may sit directly under over: ${head}`,
|
|
195
|
+
);
|
|
196
|
+
} else if (head === "door" || head === "window") {
|
|
171
197
|
if (current.length === 0) {
|
|
172
|
-
throw new SourceError(ln, `${head}
|
|
198
|
+
throw new SourceError(ln, `${head} is written indented directly under boundary`);
|
|
173
199
|
}
|
|
174
200
|
for (const b of current) b.openings.push(parseOpening(head, rest, ln, model));
|
|
175
201
|
} else if (head === "seg") {
|
|
176
202
|
if (current.length === 0) {
|
|
177
|
-
throw new SourceError(ln, "seg
|
|
203
|
+
throw new SourceError(ln, "seg is written indented directly under boundary");
|
|
178
204
|
}
|
|
179
205
|
for (const b of current) b.segs.push(parseSeg(rest, ln, model));
|
|
180
206
|
} else if (head === "line") {
|
|
181
207
|
// 描かれた線 (ADR-0022) — 境界の実現を、隣接からの導出ではなく設計の行為で与える
|
|
182
208
|
if (current.length === 0) {
|
|
183
|
-
throw new SourceError(ln, "line
|
|
209
|
+
throw new SourceError(ln, "line is written indented directly under boundary");
|
|
184
210
|
}
|
|
185
211
|
const drawn = parseDrawnLine(rest, ln, model);
|
|
186
212
|
for (const b of current) {
|
|
187
|
-
if (b.drawn) throw new SourceError(ln,
|
|
213
|
+
if (b.drawn) throw new SourceError(ln, `One boundary carries one line: ${b.a} | ${b.b}`);
|
|
188
214
|
b.drawn = { ...drawn };
|
|
189
215
|
}
|
|
190
216
|
} else if (head === "area") {
|
|
191
217
|
if (band) {
|
|
192
218
|
throw new SourceError(
|
|
193
219
|
ln,
|
|
194
|
-
"
|
|
220
|
+
"area may not be written on a band member (its region is derived — write a room that needs area by position)",
|
|
195
221
|
);
|
|
196
222
|
}
|
|
197
223
|
if (currentSpaces.length === 0) {
|
|
198
|
-
throw new SourceError(ln, "area
|
|
224
|
+
throw new SourceError(ln, "area is written indented directly under space");
|
|
199
225
|
}
|
|
200
226
|
for (const s of currentSpaces) s.areas.push(parseArea(rest, ln, model));
|
|
201
227
|
} else if (head === "space") {
|
|
202
228
|
// 帯の要素 — 領域の代わりに幅 w: を持つ space 行 (ADR-0019)
|
|
203
|
-
if (!band) throw new SourceError(ln, "
|
|
229
|
+
if (!band) throw new SourceError(ln, "an indented space is written directly under band");
|
|
204
230
|
band.members.push(parseBandMember(rest, ln));
|
|
205
231
|
} else {
|
|
206
232
|
throw new SourceError(
|
|
207
233
|
ln,
|
|
208
|
-
|
|
234
|
+
`Only door / window / seg / line / area / space (a band member) may sit on an indented line: ${head}`,
|
|
209
235
|
);
|
|
210
236
|
}
|
|
211
237
|
continue;
|
|
@@ -218,26 +244,27 @@ function ingest(
|
|
|
218
244
|
}
|
|
219
245
|
current = [];
|
|
220
246
|
currentSpaces = [];
|
|
247
|
+
over = undefined;
|
|
221
248
|
switch (head) {
|
|
222
249
|
case "koyu": {
|
|
223
250
|
const v = rest[0];
|
|
224
|
-
if (!v) throw new SourceError(ln, `koyu
|
|
251
|
+
if (!v) throw new SourceError(ln, `koyu takes a version: koyu ${DEFAULT_LANGUAGE_VERSION}`);
|
|
225
252
|
if (rest.length > 1) {
|
|
226
|
-
throw new SourceError(ln, `koyu
|
|
253
|
+
throw new SourceError(ln, `Extra tokens on the koyu version declaration: ${rest.slice(1).join(" ")}`);
|
|
227
254
|
}
|
|
228
255
|
if (!SUPPORTED_LANGUAGE_VERSIONS.includes(v)) {
|
|
229
256
|
throw new SourceError(
|
|
230
257
|
ln,
|
|
231
|
-
|
|
258
|
+
`Unsupported koyu version: ${v} (this tool supports ${SUPPORTED_LANGUAGE_VERSIONS.join(", ")})`,
|
|
232
259
|
);
|
|
233
260
|
}
|
|
234
261
|
// 版はbase層 (entry) でのみ・一度だけ宣言する — 合成順による黙った上書きを禁じる (ADR-0017)。
|
|
235
262
|
// gridの規律に合わせ、再宣言は同値でもエラー
|
|
236
263
|
if (file !== undefined && model.layers[0] !== file) {
|
|
237
|
-
throw new SourceError(ln, "koyu
|
|
264
|
+
throw new SourceError(ln, "The koyu version is declared only in the base layer (the entry)");
|
|
238
265
|
}
|
|
239
266
|
if (model.versionDeclared) {
|
|
240
|
-
throw new SourceError(ln, `koyu
|
|
267
|
+
throw new SourceError(ln, `The koyu version is declared once (already ${model.version})`);
|
|
241
268
|
}
|
|
242
269
|
model.version = v;
|
|
243
270
|
model.versionDeclared = true;
|
|
@@ -245,37 +272,72 @@ function ingest(
|
|
|
245
272
|
}
|
|
246
273
|
case "import": {
|
|
247
274
|
const rel = rest[0];
|
|
248
|
-
if (!rel) throw new SourceError(ln, "import
|
|
275
|
+
if (!rel) throw new SourceError(ln, "import takes a relative path: import ./assets.muro");
|
|
249
276
|
if (!loader) {
|
|
250
277
|
throw new SourceError(
|
|
251
278
|
ln,
|
|
252
|
-
"import
|
|
279
|
+
"import is available only in file composition (parseFile / parseFiles / CLI)",
|
|
253
280
|
);
|
|
254
281
|
}
|
|
255
282
|
let layer: { key: string; src: string };
|
|
256
283
|
try {
|
|
257
284
|
layer = loader(file, rel);
|
|
258
285
|
} catch {
|
|
259
|
-
throw new SourceError(ln,
|
|
286
|
+
throw new SourceError(ln, `Cannot read file: ${rel}`);
|
|
260
287
|
}
|
|
261
288
|
ingestLayer(model, layer.key, layer.src, seen, loader);
|
|
262
289
|
break;
|
|
263
290
|
}
|
|
291
|
+
case "over": {
|
|
292
|
+
// 上書き (合成の規則2・4)。**定義ではない** — 対象が既に無ければエラーである
|
|
293
|
+
model.compositionEdits.push({ word: "over", subject: rest.join(" "), line: ln, file });
|
|
294
|
+
over = resolveOverTarget(model, rest, ln);
|
|
295
|
+
const attrs = parseAttrs(rest.filter((t) => t.includes(":") && !t.startsWith("/")), ln);
|
|
296
|
+
const subject = overSubject(over);
|
|
297
|
+
for (const [key, v] of Object.entries(attrs)) {
|
|
298
|
+
switch (over.kind) {
|
|
299
|
+
case "space":
|
|
300
|
+
applyAttr(model, "space", subject, over.space.attrs, key, v, layer, ln, layerOf(model, over.space.file));
|
|
301
|
+
break;
|
|
302
|
+
case "zone":
|
|
303
|
+
applyAttr(model, "zone", subject, over.zone.attrs, key, v, layer, ln, layerOf(model, over.zone.file));
|
|
304
|
+
break;
|
|
305
|
+
case "asset":
|
|
306
|
+
applyAttr(model, "asset", subject, over.asset.attrs, key, v, layer, ln, layerOf(model, over.asset.file));
|
|
307
|
+
break;
|
|
308
|
+
case "level":
|
|
309
|
+
applyLevelAttr(model, over.level, key, v, layer, ln);
|
|
310
|
+
break;
|
|
311
|
+
case "boundary":
|
|
312
|
+
for (const b of over.boundaries) {
|
|
313
|
+
applyBoundaryAttr(model, b, key, v, layer, ln);
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
case "drop": {
|
|
321
|
+
// 集合からの削除 (合成の規則3)。暗黙の消滅は無い — 消すと書いたものだけが消える
|
|
322
|
+
model.compositionEdits.push({ word: "drop", subject: rest.join(" "), line: ln, file });
|
|
323
|
+
applyDrop(model, rest, ln);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
264
326
|
case "asset": {
|
|
265
327
|
// 建具アセット (RevitのFamily / USDのReference — ADR-0010)
|
|
266
328
|
const aname = rest[0];
|
|
267
329
|
const akind = rest[1];
|
|
268
330
|
if (!aname || aname.includes(":") || aname.startsWith("/")) {
|
|
269
|
-
throw new SourceError(ln, "asset
|
|
331
|
+
throw new SourceError(ln, "asset takes the form asset <name> door|window [attributes...]");
|
|
270
332
|
}
|
|
271
333
|
if (akind !== "door" && akind !== "window") {
|
|
272
|
-
throw new SourceError(ln, `asset
|
|
334
|
+
throw new SourceError(ln, `An asset kind is door / window: ${akind}`);
|
|
273
335
|
}
|
|
274
336
|
const prevA = model.assets.get(aname);
|
|
275
337
|
if (prevA) {
|
|
276
338
|
throw new SourceError(
|
|
277
339
|
ln,
|
|
278
|
-
|
|
340
|
+
`Duplicate asset name: ${aname} (first seen in ${prevA.file ?? "the same file"} at line ${prevA.line})`,
|
|
279
341
|
);
|
|
280
342
|
}
|
|
281
343
|
model.assets.set(aname, {
|
|
@@ -292,19 +354,19 @@ function ingest(
|
|
|
292
354
|
// polygon /site -2600,-7000 38000,-7000 38000,15600 2000,16800 -2600,12000
|
|
293
355
|
const ppath = rest[0];
|
|
294
356
|
if (!ppath || !ppath.startsWith("/")) {
|
|
295
|
-
throw new SourceError(ln, "polygon
|
|
357
|
+
throw new SourceError(ln, "polygon takes the form polygon /zone-path x,y x,y x,y ...");
|
|
296
358
|
}
|
|
297
359
|
const pts = rest.slice(1).map((tok) => {
|
|
298
360
|
const m = /^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(tok);
|
|
299
|
-
if (!m) throw new SourceError(ln,
|
|
361
|
+
if (!m) throw new SourceError(ln, `Cannot read the vertex (x,y in mm): ${tok}`);
|
|
300
362
|
return { x: Number(m[1]), y: Number(m[2]) };
|
|
301
363
|
});
|
|
302
|
-
if (pts.length < 3) throw new SourceError(ln, "polygon
|
|
364
|
+
if (pts.length < 3) throw new SourceError(ln, "polygon takes three or more vertices");
|
|
303
365
|
const prevP = model.polygons.get(ppath);
|
|
304
366
|
if (prevP) {
|
|
305
367
|
throw new SourceError(
|
|
306
368
|
ln,
|
|
307
|
-
|
|
369
|
+
`Duplicate site shape: ${ppath} (first seen in ${prevP.file ?? "the same file"} at line ${prevP.line})`,
|
|
308
370
|
);
|
|
309
371
|
}
|
|
310
372
|
model.polygons.set(ppath, {
|
|
@@ -317,30 +379,30 @@ function ingest(
|
|
|
317
379
|
}
|
|
318
380
|
case "name": {
|
|
319
381
|
const nm = rest.join(" ");
|
|
320
|
-
if (!nm) throw new SourceError(ln, "name
|
|
382
|
+
if (!nm) throw new SourceError(ln, "name takes a value");
|
|
321
383
|
if (model.name !== undefined && model.name !== nm) {
|
|
322
|
-
throw new SourceError(ln, `name
|
|
384
|
+
throw new SourceError(ln, `name is declared once (already "${model.name}" — in the base layer when composing)`);
|
|
323
385
|
}
|
|
324
386
|
model.name = nm;
|
|
325
387
|
break;
|
|
326
388
|
}
|
|
327
389
|
case "unit": {
|
|
328
|
-
if (rest[0] !== "mm") throw new SourceError(ln, `v0
|
|
390
|
+
if (rest[0] !== "mm") throw new SourceError(ln, `The only unit in v0 is mm: ${rest[0]}`);
|
|
329
391
|
break;
|
|
330
392
|
}
|
|
331
393
|
case "grid": {
|
|
332
394
|
const axis = rest[0];
|
|
333
395
|
if (axis !== "X" && axis !== "Y") {
|
|
334
|
-
throw new SourceError(ln, `grid
|
|
396
|
+
throw new SourceError(ln, `A grid axis is X or Y: ${axis}`);
|
|
335
397
|
}
|
|
336
398
|
if (model.grid[axis].coords.length > 0) {
|
|
337
|
-
throw new SourceError(ln, `grid ${axis}
|
|
399
|
+
throw new SourceError(ln, `grid ${axis} is declared once (in the base layer when composing)`);
|
|
338
400
|
}
|
|
339
|
-
const coords = rest.slice(1).map((t) => toNumber(t, ln, "grid
|
|
340
|
-
if (coords.length < 2) throw new SourceError(ln, "grid
|
|
401
|
+
const coords = rest.slice(1).map((t) => toNumber(t, ln, "The grid coordinate"));
|
|
402
|
+
if (coords.length < 2) throw new SourceError(ln, "grid takes two or more coordinates");
|
|
341
403
|
for (let k = 1; k < coords.length; k++) {
|
|
342
404
|
if (coords[k]! <= coords[k - 1]!) {
|
|
343
|
-
throw new SourceError(ln, "grid
|
|
405
|
+
throw new SourceError(ln, "grid coordinates are written in ascending order");
|
|
344
406
|
}
|
|
345
407
|
}
|
|
346
408
|
model.grid[axis] = {
|
|
@@ -351,15 +413,23 @@ function ingest(
|
|
|
351
413
|
}
|
|
352
414
|
case "level": {
|
|
353
415
|
const name = rest[0];
|
|
354
|
-
if (!name) throw new SourceError(ln, "level
|
|
355
|
-
const z = toNumber(rest[1] ?? "", ln, "level
|
|
416
|
+
if (!name) throw new SourceError(ln, "level requires a name");
|
|
417
|
+
const z = toNumber(rest[1] ?? "", ln, "The level height (z)");
|
|
356
418
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
357
419
|
const h = takeNumber(attrs, "h", ln);
|
|
358
420
|
const slab = takeNumber(attrs, "slab", ln);
|
|
359
421
|
const pitch = takeNumber(attrs, "pitch", ln);
|
|
360
422
|
const under = takeNumber(attrs, "underground", ln);
|
|
423
|
+
// **level は attrs を持たない。**残ったキーは正準JSONにも痕跡を残さず消えるので、
|
|
424
|
+
// ここで拒まないと `undergound:1` が黙って地上階になる (ADR-0033)
|
|
425
|
+
for (const key of Object.keys(attrs)) {
|
|
426
|
+
throw new SourceError(
|
|
427
|
+
ln,
|
|
428
|
+
`level carries ${key}:, which is not in the ledger (level reads h / slab / pitch / underground)`,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
361
431
|
if (under !== undefined && under !== 0 && under !== 1) {
|
|
362
|
-
throw new SourceError(ln, "underground
|
|
432
|
+
throw new SourceError(ln, "underground is given as 0 / 1 (1 = below ground)");
|
|
363
433
|
}
|
|
364
434
|
const ug = under === 1 ? { underground: true } : {};
|
|
365
435
|
|
|
@@ -368,14 +438,14 @@ function ingest(
|
|
|
368
438
|
if (range) {
|
|
369
439
|
const [, p1, n1, p2, n2] = range;
|
|
370
440
|
if (p1 !== p2 || Number(n1) >= Number(n2)) {
|
|
371
|
-
throw new SourceError(ln,
|
|
441
|
+
throw new SourceError(ln, `Cannot read the level range: ${name}`);
|
|
372
442
|
}
|
|
373
443
|
if (pitch === undefined || pitch <= 0) {
|
|
374
|
-
throw new SourceError(ln,
|
|
444
|
+
throw new SourceError(ln, `A level range requires pitch: (the storey height in mm): ${name}`);
|
|
375
445
|
}
|
|
376
446
|
for (let k = Number(n1); k <= Number(n2); k++) {
|
|
377
447
|
const nm = `${p1}${k}`;
|
|
378
|
-
if (model.levels[nm]) throw new SourceError(ln,
|
|
448
|
+
if (model.levels[nm]) throw new SourceError(ln, `Duplicate level: ${nm}`);
|
|
379
449
|
model.levels[nm] = {
|
|
380
450
|
name: nm,
|
|
381
451
|
z: z + pitch * (k - Number(n1)),
|
|
@@ -389,9 +459,9 @@ function ingest(
|
|
|
389
459
|
break;
|
|
390
460
|
}
|
|
391
461
|
if (pitch !== undefined) {
|
|
392
|
-
throw new SourceError(ln, "pitch
|
|
462
|
+
throw new SourceError(ln, "pitch is available only on a level range declaration (L?..L?)");
|
|
393
463
|
}
|
|
394
|
-
if (model.levels[name]) throw new SourceError(ln,
|
|
464
|
+
if (model.levels[name]) throw new SourceError(ln, `Duplicate level: ${name}`);
|
|
395
465
|
model.levels[name] = {
|
|
396
466
|
name,
|
|
397
467
|
z,
|
|
@@ -405,16 +475,16 @@ function ingest(
|
|
|
405
475
|
}
|
|
406
476
|
case "column": {
|
|
407
477
|
// 柱 (ADR-0023) — 寸法と階と通りだけを書く。位置は通り芯の交点から導出される
|
|
408
|
-
const size = toNumber(rest[0] ?? "", ln, "column
|
|
409
|
-
if (size <= 0) throw new SourceError(ln, "column
|
|
478
|
+
const size = toNumber(rest[0] ?? "", ln, "The column dimension");
|
|
479
|
+
if (size <= 0) throw new SourceError(ln, "A column dimension is written as a positive value in mm");
|
|
410
480
|
const span = rest[1];
|
|
411
481
|
if (!span) {
|
|
412
|
-
throw new SourceError(ln, "column
|
|
482
|
+
throw new SourceError(ln, "column takes the form column <size mm> <L?..L?|level name> [x:grid,..] [y:grid,..]");
|
|
413
483
|
}
|
|
414
484
|
const levels = /\.\./.test(span)
|
|
415
485
|
? resolveSpanLevels(model, span, ln)
|
|
416
486
|
: (() => {
|
|
417
|
-
if (!model.levels[span]) throw new SourceError(ln,
|
|
487
|
+
if (!model.levels[span]) throw new SourceError(ln, `Undeclared level: ${span}`);
|
|
418
488
|
return [span];
|
|
419
489
|
})();
|
|
420
490
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
@@ -425,10 +495,10 @@ function ingest(
|
|
|
425
495
|
const list = v.split(",").filter(Boolean);
|
|
426
496
|
for (const n of list) {
|
|
427
497
|
if (!model.grid[key === "x" ? "X" : "Y"].names.includes(n)) {
|
|
428
|
-
throw new SourceError(ln,
|
|
498
|
+
throw new SourceError(ln, `Undefined grid line name: ${n}`);
|
|
429
499
|
}
|
|
430
500
|
}
|
|
431
|
-
if (list.length === 0) throw new SourceError(ln, `${key}:
|
|
501
|
+
if (list.length === 0) throw new SourceError(ln, `${key}: takes grid line names`);
|
|
432
502
|
return list;
|
|
433
503
|
};
|
|
434
504
|
const xNames = names("x");
|
|
@@ -452,12 +522,12 @@ function ingest(
|
|
|
452
522
|
}
|
|
453
523
|
case "space": {
|
|
454
524
|
const path = rest[0];
|
|
455
|
-
if (!path) throw new SourceError(ln, "space
|
|
525
|
+
if (!path) throw new SourceError(ln, "space requires a path");
|
|
456
526
|
// w: は帯の要素の語 — 字下げを落とした要素が「領域なしの空間」として黙って通るのを防ぐ
|
|
457
527
|
if (rest.some((t) => t === "w:" || t.startsWith("w:"))) {
|
|
458
528
|
throw new SourceError(
|
|
459
529
|
ln,
|
|
460
|
-
"
|
|
530
|
+
"w: may not be written on space (a space written by width sits indented under band)",
|
|
461
531
|
);
|
|
462
532
|
}
|
|
463
533
|
for (const [p] of expandSpan(model, [path], ln)) {
|
|
@@ -466,7 +536,7 @@ function ingest(
|
|
|
466
536
|
if (prevS) {
|
|
467
537
|
throw new SourceError(
|
|
468
538
|
ln,
|
|
469
|
-
|
|
539
|
+
`Duplicate space path: ${space.path} (first seen in ${prevS.file ?? "the same file"} at line ${prevS.line})`,
|
|
470
540
|
);
|
|
471
541
|
}
|
|
472
542
|
if (file) space.file = file;
|
|
@@ -479,7 +549,7 @@ function ingest(
|
|
|
479
549
|
const pa = rest[0];
|
|
480
550
|
const pb = rest[1];
|
|
481
551
|
if (!pa || !pb) {
|
|
482
|
-
throw new SourceError(ln, "boundary
|
|
552
|
+
throw new SourceError(ln, "boundary takes the form boundary /pathA /pathB [attributes...]");
|
|
483
553
|
}
|
|
484
554
|
for (const [ea, eb] of expandSpan(model, [pa, pb], ln)) {
|
|
485
555
|
const b = parseBoundary([ea!, eb!, ...rest.slice(2)], ln);
|
|
@@ -493,14 +563,14 @@ function ingest(
|
|
|
493
563
|
// 数える集約 — 住戸・部門など。幾何は持たず、パス接頭辞で空間を束ねる
|
|
494
564
|
const zpath = rest[0];
|
|
495
565
|
if (!zpath || !zpath.startsWith("/")) {
|
|
496
|
-
throw new SourceError(ln, "zone
|
|
566
|
+
throw new SourceError(ln, "zone takes the form zone /path [attributes...]");
|
|
497
567
|
}
|
|
498
568
|
for (const [p] of expandSpan(model, [zpath], ln)) {
|
|
499
569
|
const prevZ = model.zones.get(p!);
|
|
500
570
|
if (prevZ) {
|
|
501
571
|
throw new SourceError(
|
|
502
572
|
ln,
|
|
503
|
-
|
|
573
|
+
`Duplicate zone path: ${p} (first seen in ${prevZ.file ?? "the same file"} at line ${prevZ.line})`,
|
|
504
574
|
);
|
|
505
575
|
}
|
|
506
576
|
model.zones.set(p!, {
|
|
@@ -517,13 +587,13 @@ function ingest(
|
|
|
517
587
|
const leaf = rest[0];
|
|
518
588
|
const span = rest[1];
|
|
519
589
|
if (!leaf || leaf.startsWith("/") || !span) {
|
|
520
|
-
throw new SourceError(ln, "stack
|
|
590
|
+
throw new SourceError(ln, "stack takes the form stack <name> <L?..L?> type:stair|shaft");
|
|
521
591
|
}
|
|
522
592
|
const levels = resolveSpanLevels(model, span, ln);
|
|
523
593
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
524
594
|
const kind = takeString(attrs, "type");
|
|
525
595
|
if (kind !== "stair" && kind !== "shaft" && kind !== "void") {
|
|
526
|
-
throw new SourceError(ln, `stack
|
|
596
|
+
throw new SourceError(ln, `A stack type is stair / shaft / void: ${kind}`);
|
|
527
597
|
}
|
|
528
598
|
for (let i = 0; i + 1 < levels.length; i++) {
|
|
529
599
|
const b: Boundary = {
|
|
@@ -542,7 +612,7 @@ function ingest(
|
|
|
542
612
|
break;
|
|
543
613
|
}
|
|
544
614
|
default:
|
|
545
|
-
throw new SourceError(ln,
|
|
615
|
+
throw new SourceError(ln, `Unknown keyword: ${head}`);
|
|
546
616
|
}
|
|
547
617
|
} catch (e) {
|
|
548
618
|
// 合成時はどのファイルのエラーかを言葉にする
|
|
@@ -570,10 +640,11 @@ function ingest(
|
|
|
570
640
|
function parseSpace(rest: string[], ln: number, model: Model): Space {
|
|
571
641
|
const path = rest[0];
|
|
572
642
|
if (!path || !path.startsWith("/")) {
|
|
573
|
-
throw new SourceError(ln, "space
|
|
643
|
+
throw new SourceError(ln, "space takes the form space /path type [X?..X? Y?..Y? [+ ...]]");
|
|
574
644
|
}
|
|
575
645
|
const type = rest[1];
|
|
576
|
-
if (!type) throw new SourceError(ln, `space ${path}
|
|
646
|
+
if (!type) throw new SourceError(ln, `space ${path} requires a type (a word from the vocabulary)`);
|
|
647
|
+
guardStructuralType(type, ln);
|
|
577
648
|
|
|
578
649
|
// 領域は「+」区切りで複数書ける (L字などの合併)
|
|
579
650
|
const groups: string[][] = [[]];
|
|
@@ -592,7 +663,7 @@ function parseSpace(rest: string[], ln: number, model: Model): Space {
|
|
|
592
663
|
// レベルは既定でパス先頭から読む。階を跨ぐくくり (メゾネット等) は level: で明示する
|
|
593
664
|
const explicit = takeString(attrs, "level");
|
|
594
665
|
if (explicit !== undefined && !model.levels[explicit]) {
|
|
595
|
-
throw new SourceError(ln,
|
|
666
|
+
throw new SourceError(ln, `Undeclared level: level:${explicit}`);
|
|
596
667
|
}
|
|
597
668
|
const seg = path.split("/")[1];
|
|
598
669
|
const level = explicit ?? (seg && model.levels[seg] ? seg : undefined);
|
|
@@ -625,7 +696,7 @@ function parseBandHead(rest: string[], ln: number, model: Model): BandDecl {
|
|
|
625
696
|
if (axis !== "X" && axis !== "Y") {
|
|
626
697
|
throw new SourceError(
|
|
627
698
|
ln,
|
|
628
|
-
`band
|
|
699
|
+
`A band divides along X or Y: ${axis ?? "(none)"} (it takes the form band X X1..X2 Y1..Y2)`,
|
|
629
700
|
);
|
|
630
701
|
}
|
|
631
702
|
const tail = rest.slice(1);
|
|
@@ -633,19 +704,19 @@ function parseBandHead(rest: string[], ln: number, model: Model): BandDecl {
|
|
|
633
704
|
if (extra.length > 0) {
|
|
634
705
|
throw new SourceError(
|
|
635
706
|
ln,
|
|
636
|
-
`band
|
|
707
|
+
`Only the axis and the extent may be written on a band line (attributes go on the member space lines): ${extra.join(" ")}`,
|
|
637
708
|
);
|
|
638
709
|
}
|
|
639
710
|
// 逆順表記は space では同じ矩形の別綴りだが、帯では並びの向きが意味を持つので許さない
|
|
640
711
|
for (const t of tail) {
|
|
641
712
|
const [p, q] = t.split("..");
|
|
642
|
-
if (!p || !q) throw new SourceError(ln,
|
|
713
|
+
if (!p || !q) throw new SourceError(ln, `Cannot read the region: ${t}`);
|
|
643
714
|
const rp = resolveRef(model, p, ln);
|
|
644
715
|
const rq = resolveRef(model, q, ln);
|
|
645
716
|
if (rp.axis === rq.axis && rp.coord > rq.coord) {
|
|
646
717
|
throw new SourceError(
|
|
647
718
|
ln,
|
|
648
|
-
`band
|
|
719
|
+
`A band range is written in ascending order (members run west to east / south to north): ${t}`,
|
|
649
720
|
);
|
|
650
721
|
}
|
|
651
722
|
}
|
|
@@ -667,37 +738,38 @@ function parseBandHead(rest: string[], ln: number, model: Model): BandDecl {
|
|
|
667
738
|
function parseBandMember(rest: string[], ln: number): BandMember {
|
|
668
739
|
const path = rest[0];
|
|
669
740
|
if (!path?.startsWith("/")) {
|
|
670
|
-
throw new SourceError(ln, "band
|
|
741
|
+
throw new SourceError(ln, "A band member takes the form space /path type w:(mm)");
|
|
671
742
|
}
|
|
672
743
|
const type = rest[1];
|
|
673
744
|
// 型の位置に k:v が来たら「型の書き忘れ」— 幅の欠落として誤報しない
|
|
674
745
|
if (!type || type.includes(":")) {
|
|
675
|
-
throw new SourceError(ln, `band
|
|
746
|
+
throw new SourceError(ln, `The band member ${path} requires a type (a word from the vocabulary)`);
|
|
676
747
|
}
|
|
748
|
+
guardStructuralType(type, ln);
|
|
677
749
|
let w: number | "rest" | undefined;
|
|
678
750
|
const attrTokens: string[] = [];
|
|
679
751
|
for (const t of rest.slice(2)) {
|
|
680
752
|
if (t === "+" || t.includes("..")) {
|
|
681
|
-
throw new SourceError(ln, `band
|
|
753
|
+
throw new SourceError(ln, `A region may not be written on a band member (the band and w: give it): ${t}`);
|
|
682
754
|
}
|
|
683
755
|
if (t.startsWith("level:")) {
|
|
684
756
|
throw new SourceError(
|
|
685
757
|
ln,
|
|
686
|
-
`band
|
|
758
|
+
`level: may not be written on a band member (a band is a run on one level): ${t}`,
|
|
687
759
|
);
|
|
688
760
|
}
|
|
689
761
|
if (t.startsWith("w:")) {
|
|
690
|
-
if (w !== undefined) throw new SourceError(ln, "
|
|
762
|
+
if (w !== undefined) throw new SourceError(ln, "Duplicate attribute key: w");
|
|
691
763
|
const v = t.slice(2);
|
|
692
764
|
if (v === "rest") w = "rest";
|
|
693
765
|
else if (/^\d+$/.test(v) && Number(v) > 0) w = Number(v);
|
|
694
|
-
else throw new SourceError(ln, `band
|
|
766
|
+
else throw new SourceError(ln, `A band member width is written as a positive integer in mm, or as rest: ${t}`);
|
|
695
767
|
continue;
|
|
696
768
|
}
|
|
697
769
|
attrTokens.push(t);
|
|
698
770
|
}
|
|
699
771
|
if (w === undefined) {
|
|
700
|
-
throw new SourceError(ln, `band
|
|
772
|
+
throw new SourceError(ln, `A band member requires a width, w:(mm) or w:rest: ${path}`);
|
|
701
773
|
}
|
|
702
774
|
return { path, type, w, attrTokens, line: ln };
|
|
703
775
|
}
|
|
@@ -710,7 +782,7 @@ function parseBandMember(rest: string[], ln: number): BandMember {
|
|
|
710
782
|
function spellRef(model: Model, axis: "X" | "Y", c: number, ln: number): string {
|
|
711
783
|
const g = model.grid[axis];
|
|
712
784
|
if (!Number.isInteger(c)) {
|
|
713
|
-
throw new SourceError(ln,
|
|
785
|
+
throw new SourceError(ln, `The derived cut position is not an integer in mm: ${c}`);
|
|
714
786
|
}
|
|
715
787
|
let i = 0;
|
|
716
788
|
for (let k = 0; k < g.coords.length; k++) if (g.coords[k]! <= c) i = k;
|
|
@@ -723,7 +795,7 @@ function spellRef(model: Model, axis: "X" | "Y", c: number, ln: number): string
|
|
|
723
795
|
function expandBand(model: Model, band: BandDecl, file: string | undefined): void {
|
|
724
796
|
const { axis, lo, hi, members } = band;
|
|
725
797
|
if (members.length === 0) {
|
|
726
|
-
throw new SourceError(band.line, "band
|
|
798
|
+
throw new SourceError(band.line, "band takes one or more indented space lines below it");
|
|
727
799
|
}
|
|
728
800
|
const extent = hi - lo;
|
|
729
801
|
let sum = 0;
|
|
@@ -734,7 +806,7 @@ function expandBand(model: Model, band: BandDecl, file: string | undefined): voi
|
|
|
734
806
|
if (restAt >= 0) {
|
|
735
807
|
throw new SourceError(
|
|
736
808
|
m.line,
|
|
737
|
-
|
|
809
|
+
`Only one member per band absorbs the remainder (w:rest): ${members[restAt]!.path}, ${m.path}`,
|
|
738
810
|
);
|
|
739
811
|
}
|
|
740
812
|
restAt = k;
|
|
@@ -744,7 +816,7 @@ function expandBand(model: Model, band: BandDecl, file: string | undefined): voi
|
|
|
744
816
|
if (sum > extent) {
|
|
745
817
|
throw new SourceError(
|
|
746
818
|
band.line,
|
|
747
|
-
|
|
819
|
+
`The dimensions sum to ${sum}mm against a band width of ${extent}mm, ${sum - extent}mm over\n${list}`,
|
|
748
820
|
);
|
|
749
821
|
}
|
|
750
822
|
const widths = members.map((m) => (m.w === "rest" ? 0 : m.w));
|
|
@@ -752,15 +824,15 @@ function expandBand(model: Model, band: BandDecl, file: string | undefined): voi
|
|
|
752
824
|
if (sum === extent) {
|
|
753
825
|
throw new SourceError(
|
|
754
826
|
members[restAt]!.line,
|
|
755
|
-
|
|
827
|
+
`The other dimensions use up the band width of ${extent}mm, leaving zero for ${members[restAt]!.path} (w:rest)`,
|
|
756
828
|
);
|
|
757
829
|
}
|
|
758
830
|
widths[restAt] = extent - sum;
|
|
759
831
|
} else if (sum < extent) {
|
|
760
832
|
throw new SourceError(
|
|
761
833
|
band.line,
|
|
762
|
-
|
|
763
|
-
`(
|
|
834
|
+
`The dimensions sum to ${sum}mm against a band width of ${extent}mm, ${extent - sum}mm short ` +
|
|
835
|
+
`(fix a dimension, or make one of them w:rest)\n${list}`,
|
|
764
836
|
);
|
|
765
837
|
}
|
|
766
838
|
|
|
@@ -771,7 +843,7 @@ function expandBand(model: Model, band: BandDecl, file: string | undefined): voi
|
|
|
771
843
|
if (lv.size > 1) {
|
|
772
844
|
throw new SourceError(
|
|
773
845
|
band.line,
|
|
774
|
-
|
|
846
|
+
`Band members expand onto the same level: ${it.map((p) => `${p} → ${p.split("/")[1]}`).join(", ")}`,
|
|
775
847
|
);
|
|
776
848
|
}
|
|
777
849
|
}
|
|
@@ -795,7 +867,7 @@ function expandBand(model: Model, band: BandDecl, file: string | undefined): voi
|
|
|
795
867
|
if (prev) {
|
|
796
868
|
throw new SourceError(
|
|
797
869
|
m.line,
|
|
798
|
-
|
|
870
|
+
`Duplicate space path: ${space.path} (first seen in ${prev.file ?? "the same file"} at line ${prev.line})`,
|
|
799
871
|
);
|
|
800
872
|
}
|
|
801
873
|
if (file) space.file = file;
|
|
@@ -811,7 +883,7 @@ function parseRegion(
|
|
|
811
883
|
model: Model,
|
|
812
884
|
): { grid: { xa: string; xb: string; ya: string; yb: string }; rect: Rect } {
|
|
813
885
|
if (regionTokens.length !== 2) {
|
|
814
|
-
throw new SourceError(ln, "
|
|
886
|
+
throw new SourceError(ln, "A region is given as two ranges, X?..X? and Y?..Y?");
|
|
815
887
|
}
|
|
816
888
|
let xr: [number, number] | undefined;
|
|
817
889
|
let yr: [number, number] | undefined;
|
|
@@ -819,11 +891,11 @@ function parseRegion(
|
|
|
819
891
|
let yg: [string, string] | undefined;
|
|
820
892
|
for (const t of regionTokens) {
|
|
821
893
|
const [p, q] = t.split("..");
|
|
822
|
-
if (!p || !q) throw new SourceError(ln,
|
|
894
|
+
if (!p || !q) throw new SourceError(ln, `Cannot read the region: ${t}`);
|
|
823
895
|
const rp = resolveRef(model, p, ln);
|
|
824
896
|
const rq = resolveRef(model, q, ln);
|
|
825
897
|
if (rp.axis !== rq.axis) {
|
|
826
|
-
throw new SourceError(ln,
|
|
898
|
+
throw new SourceError(ln, `Both ends of a range are grid lines on the same axis: ${t}`);
|
|
827
899
|
}
|
|
828
900
|
// 逆順表記 (X2..X1) は同じ矩形の別綴り — 座標昇順に正規化して保存する (正準JSON・diffが揃う)
|
|
829
901
|
const [lo, hi] = rp.coord <= rq.coord ? [[rp.coord, p] as const, [rq.coord, q] as const]
|
|
@@ -837,9 +909,9 @@ function parseRegion(
|
|
|
837
909
|
}
|
|
838
910
|
}
|
|
839
911
|
if (!xr || !yr || !xg || !yg) {
|
|
840
|
-
throw new SourceError(ln, "
|
|
912
|
+
throw new SourceError(ln, "A region uses one X range and one Y range");
|
|
841
913
|
}
|
|
842
|
-
if (xr[0] === xr[1] || yr[0] === yr[1]) throw new SourceError(ln, "
|
|
914
|
+
if (xr[0] === xr[1] || yr[0] === yr[1]) throw new SourceError(ln, "The region has zero width");
|
|
843
915
|
return {
|
|
844
916
|
grid: { xa: xg[0], xb: xg[1], ya: yg[0], yb: yg[1] },
|
|
845
917
|
rect: {
|
|
@@ -862,13 +934,13 @@ function parseDrawnLine(
|
|
|
862
934
|
model: Model,
|
|
863
935
|
): { aRef: string; bRef: string; a: Pt; b: Pt; line: number } {
|
|
864
936
|
if (rest.length !== 2) {
|
|
865
|
-
throw new SourceError(ln, "line
|
|
937
|
+
throw new SourceError(ln, "line takes the form line <start> <end> (for example line X3,Y1 X4,Y3)");
|
|
866
938
|
}
|
|
867
939
|
const [aRef, bRef] = rest as [string, string];
|
|
868
940
|
const a = resolvePoint(model, aRef, ln);
|
|
869
941
|
const b = resolvePoint(model, bRef, ln);
|
|
870
942
|
if (Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5) {
|
|
871
|
-
throw new SourceError(ln, `line
|
|
943
|
+
throw new SourceError(ln, `Both ends of the line are the same point: ${aRef}`);
|
|
872
944
|
}
|
|
873
945
|
return { aRef, bRef, a, b, line: ln };
|
|
874
946
|
}
|
|
@@ -877,12 +949,12 @@ function parseDrawnLine(
|
|
|
877
949
|
function resolvePoint(model: Model, token: string, ln: number): Pt {
|
|
878
950
|
const parts = token.split(",");
|
|
879
951
|
if (parts.length !== 2) {
|
|
880
|
-
throw new SourceError(ln,
|
|
952
|
+
throw new SourceError(ln, `A point takes the form <X grid line>,<Y grid line>: ${token}`);
|
|
881
953
|
}
|
|
882
954
|
const p = resolveRef(model, parts[0]!, ln);
|
|
883
955
|
const q = resolveRef(model, parts[1]!, ln);
|
|
884
956
|
if (p.axis !== "X" || q.axis !== "Y") {
|
|
885
|
-
throw new SourceError(ln,
|
|
957
|
+
throw new SourceError(ln, `A point is written X grid line first, then Y: ${token}`);
|
|
886
958
|
}
|
|
887
959
|
return { x: p.coord, y: q.coord };
|
|
888
960
|
}
|
|
@@ -900,7 +972,7 @@ function parseSeg(rest: string[], ln: number, model: Model): Seg {
|
|
|
900
972
|
const attrs = parseAttrs(rest, ln);
|
|
901
973
|
const w = takeNumber(attrs, "w", ln);
|
|
902
974
|
if (w === undefined || w <= 0) {
|
|
903
|
-
throw new SourceError(ln, "seg
|
|
975
|
+
throw new SourceError(ln, "seg requires a width w:(mm)");
|
|
904
976
|
}
|
|
905
977
|
const at = parseAt(attrs, ln, model);
|
|
906
978
|
const edge = takeEdge(attrs, ln);
|
|
@@ -921,7 +993,7 @@ function parseAt(
|
|
|
921
993
|
delete attrs["at"];
|
|
922
994
|
if (typeof v === "number") {
|
|
923
995
|
if (v < 0 || v > 1) {
|
|
924
|
-
throw new SourceError(ln, "at
|
|
996
|
+
throw new SourceError(ln, "at is given as a ratio in 0..1, or as a grid reference (at:X2+450)");
|
|
925
997
|
}
|
|
926
998
|
return { at: v };
|
|
927
999
|
}
|
|
@@ -932,13 +1004,13 @@ function parseAt(
|
|
|
932
1004
|
/** レベルのスパン (L2..L9) を、宣言済みレベルのz順の並びに解決する */
|
|
933
1005
|
function resolveSpanLevels(model: Model, token: string, ln: number): string[] {
|
|
934
1006
|
const m = /^([A-Za-z]+\d+)\.\.([A-Za-z]+\d+)$/.exec(token);
|
|
935
|
-
if (!m) throw new SourceError(ln,
|
|
1007
|
+
if (!m) throw new SourceError(ln, `Cannot read the level range: ${token}`);
|
|
936
1008
|
const from = model.levels[m[1]!];
|
|
937
1009
|
const to = model.levels[m[2]!];
|
|
938
1010
|
if (!from || !to) {
|
|
939
|
-
throw new SourceError(ln,
|
|
1011
|
+
throw new SourceError(ln, `The range includes an undeclared level (declare level first): ${token}`);
|
|
940
1012
|
}
|
|
941
|
-
if (from.z >= to.z) throw new SourceError(ln,
|
|
1013
|
+
if (from.z >= to.z) throw new SourceError(ln, `The range runs backwards: ${token}`);
|
|
942
1014
|
return Object.values(model.levels)
|
|
943
1015
|
.filter((l) => l.z >= from.z && l.z <= to.z)
|
|
944
1016
|
.sort((a, b) => a.z - b.z)
|
|
@@ -957,7 +1029,7 @@ function expandSpan(model: Model, paths: string[], ln: number): string[][] {
|
|
|
957
1029
|
}
|
|
958
1030
|
if (spans.size === 0) return [paths];
|
|
959
1031
|
if (spans.size > 1) {
|
|
960
|
-
throw new SourceError(ln,
|
|
1032
|
+
throw new SourceError(ln, `Level ranges on one line must agree: ${[...spans].join(", ")}`);
|
|
961
1033
|
}
|
|
962
1034
|
const span = [...spans][0]!;
|
|
963
1035
|
const levels = resolveSpanLevels(model, span, ln);
|
|
@@ -973,7 +1045,7 @@ function expandSpan(model: Model, paths: string[], ln: number): string[][] {
|
|
|
973
1045
|
/** 通り参照 (X2, X2+600, Y3-150 など) を軸と座標mmに解決する */
|
|
974
1046
|
function resolveRef(model: Model, token: string, ln: number): { axis: "X" | "Y"; coord: number } {
|
|
975
1047
|
const m = /^([XY]\d+)([+-]\d+)?$/.exec(token);
|
|
976
|
-
if (!m) throw new SourceError(ln,
|
|
1048
|
+
if (!m) throw new SourceError(ln, `Undefined grid line name: ${token}`);
|
|
977
1049
|
const name = m[1]!;
|
|
978
1050
|
const offset = m[2] ? Number(m[2]) : 0;
|
|
979
1051
|
for (const axis of ["X", "Y"] as const) {
|
|
@@ -981,27 +1053,27 @@ function resolveRef(model: Model, token: string, ln: number): { axis: "X" | "Y";
|
|
|
981
1053
|
const i = g.names.indexOf(name);
|
|
982
1054
|
if (i >= 0) return { axis, coord: g.coords[i]! + offset };
|
|
983
1055
|
}
|
|
984
|
-
throw new SourceError(ln,
|
|
1056
|
+
throw new SourceError(ln, `Undefined grid line name: ${token}`);
|
|
985
1057
|
}
|
|
986
1058
|
|
|
987
1059
|
function parseBoundary(rest: string[], ln: number): Boundary {
|
|
988
1060
|
const a = rest[0];
|
|
989
1061
|
const b = rest[1];
|
|
990
1062
|
if (!a?.startsWith("/") || !b?.startsWith("/")) {
|
|
991
|
-
throw new SourceError(ln, "boundary
|
|
1063
|
+
throw new SourceError(ln, "boundary takes the form boundary /pathA /pathB [attributes...]");
|
|
992
1064
|
}
|
|
993
1065
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
994
1066
|
const t = takeNumber(attrs, "t", ln);
|
|
995
1067
|
const kindRaw = takeString(attrs, "type") ?? "wall";
|
|
996
|
-
if (!
|
|
1068
|
+
if (!BOUNDARY_KINDS.has(kindRaw)) {
|
|
997
1069
|
throw new SourceError(
|
|
998
1070
|
ln,
|
|
999
|
-
`boundary
|
|
1071
|
+
`A boundary type is ${[...BOUNDARY_KINDS].join(" / ")}: ${kindRaw}`,
|
|
1000
1072
|
);
|
|
1001
1073
|
}
|
|
1002
1074
|
const air = takeNumber(attrs, "air", ln);
|
|
1003
1075
|
if (air !== undefined && air !== 0 && air !== 1) {
|
|
1004
|
-
throw new SourceError(ln, "air
|
|
1076
|
+
throw new SourceError(ln, "air is given as 0 / 1 (1 = it does not block air or light: a railing, a fence)");
|
|
1005
1077
|
}
|
|
1006
1078
|
const edge = takeEdge(attrs, ln);
|
|
1007
1079
|
return {
|
|
@@ -1035,9 +1107,9 @@ function parseOpening(
|
|
|
1035
1107
|
const attrs: Attrs = {};
|
|
1036
1108
|
if (ref) {
|
|
1037
1109
|
const asset = model.assets.get(ref);
|
|
1038
|
-
if (!asset) throw new SourceError(ln,
|
|
1110
|
+
if (!asset) throw new SourceError(ln, `Undefined opening asset: ${ref}`);
|
|
1039
1111
|
if (asset.kind !== kind) {
|
|
1040
|
-
throw new SourceError(ln,
|
|
1112
|
+
throw new SourceError(ln, `The asset ${ref} is a ${asset.kind} (it cannot be used as a ${kind})`);
|
|
1041
1113
|
}
|
|
1042
1114
|
Object.assign(attrs, asset.attrs);
|
|
1043
1115
|
}
|
|
@@ -1045,18 +1117,18 @@ function parseOpening(
|
|
|
1045
1117
|
|
|
1046
1118
|
const w = takeNumber(attrs, "w", ln);
|
|
1047
1119
|
if (w === undefined || w <= 0) {
|
|
1048
|
-
throw new SourceError(ln, `${kind}
|
|
1120
|
+
throw new SourceError(ln, `${kind} requires a width w:(mm) (the asset may supply it)`);
|
|
1049
1121
|
}
|
|
1050
1122
|
const h = takeNumber(attrs, "h", ln);
|
|
1051
1123
|
const at = parseAt(attrs, ln, model);
|
|
1052
1124
|
const edge = takeEdge(attrs, ln);
|
|
1053
1125
|
const hingeRaw = takeString(attrs, "hinge");
|
|
1054
1126
|
if (hingeRaw !== undefined && !EDGES.has(hingeRaw)) {
|
|
1055
|
-
throw new SourceError(ln, `hinge
|
|
1127
|
+
throw new SourceError(ln, `hinge is given as N/E/S/W: ${hingeRaw}`);
|
|
1056
1128
|
}
|
|
1057
1129
|
const swingRaw = takeString(attrs, "swing");
|
|
1058
1130
|
if (swingRaw !== undefined && swingRaw !== "a" && swingRaw !== "b") {
|
|
1059
|
-
throw new SourceError(ln, `swing
|
|
1131
|
+
throw new SourceError(ln, `swing is a / b, the side of the boundary it opens toward: ${swingRaw}`);
|
|
1060
1132
|
}
|
|
1061
1133
|
return {
|
|
1062
1134
|
kind,
|
|
@@ -1092,22 +1164,418 @@ export function tokenize(line: string, ln: number): string[] {
|
|
|
1092
1164
|
}
|
|
1093
1165
|
cur += ch;
|
|
1094
1166
|
}
|
|
1095
|
-
if (inQuote) throw new SourceError(ln, "
|
|
1167
|
+
if (inQuote) throw new SourceError(ln, "Unclosed quote");
|
|
1096
1168
|
if (cur) tokens.push(cur);
|
|
1097
1169
|
return tokens;
|
|
1098
1170
|
}
|
|
1099
1171
|
|
|
1172
|
+
/**
|
|
1173
|
+
* 型として構造的に解釈される二語 (spec/vocabulary.md 規則1)。
|
|
1174
|
+
* `exterior` は「外部」、`void` は「床面積に算入しない」— どちらも構成の事実である。
|
|
1175
|
+
*/
|
|
1176
|
+
const STRUCTURAL_TYPES = ["exterior", "void"];
|
|
1177
|
+
|
|
1178
|
+
/** 編集距離が1以内か (挿入・削除・置換をそれぞれ1と数える) */
|
|
1179
|
+
function nearBy1(a: string, b: string): boolean {
|
|
1180
|
+
if (a === b) return false;
|
|
1181
|
+
if (Math.abs(a.length - b.length) > 1) return false;
|
|
1182
|
+
let i = 0;
|
|
1183
|
+
let j = 0;
|
|
1184
|
+
let diff = 0;
|
|
1185
|
+
while (i < a.length && j < b.length) {
|
|
1186
|
+
if (a[i] === b[j]) {
|
|
1187
|
+
i++;
|
|
1188
|
+
j++;
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
if (++diff > 1) return false;
|
|
1192
|
+
if (a.length > b.length) i++;
|
|
1193
|
+
else if (a.length < b.length) j++;
|
|
1194
|
+
else {
|
|
1195
|
+
i++;
|
|
1196
|
+
j++;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return diff + (a.length - i) + (b.length - j) <= 1;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* 型の綴りを守る (ADR-0033)。**型の語彙は開いている** — `room` も `ldk` も `厨房` も自由である。
|
|
1204
|
+
* だが構造として解釈される二語だけは、一字違いが黙って意味を変える:
|
|
1205
|
+
* `exteriorr` と書けば外部でなくなり、延床が倍になる。check は緑のままだった。
|
|
1206
|
+
*
|
|
1207
|
+
* 開かれた語彙を殺さずにこれを塞ぐ唯一の形が、**二語の近傍だけを拒むこと**である。
|
|
1208
|
+
* 遠い語 (room / yard / ldk) は何も言われない。
|
|
1209
|
+
*/
|
|
1210
|
+
function guardStructuralType(type: string, ln: number): void {
|
|
1211
|
+
for (const w of STRUCTURAL_TYPES) {
|
|
1212
|
+
if (nearBy1(type.toLowerCase(), w)) {
|
|
1213
|
+
throw new SourceError(
|
|
1214
|
+
ln,
|
|
1215
|
+
`The type ${type} looks like a misspelling of ${w} (${w} is read structurally — if a different word was meant, spell it further away)`,
|
|
1216
|
+
);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* 上書きの対象 (合成の規則4 — 定義と上書きの区別)。
|
|
1223
|
+
* `space` / `boundary` は**定義**であり、重複はエラーである。`over` は**上書き**であり、
|
|
1224
|
+
* 対象が既に定義されていなければエラーである。二つは別の文であって、書き方から区別がつく。
|
|
1225
|
+
*/
|
|
1226
|
+
type OverTarget =
|
|
1227
|
+
| { kind: "space"; space: Space }
|
|
1228
|
+
| { kind: "zone"; zone: Zone }
|
|
1229
|
+
| { kind: "boundary"; boundaries: Boundary[] }
|
|
1230
|
+
| { kind: "level"; level: Level }
|
|
1231
|
+
| { kind: "asset"; asset: Asset };
|
|
1232
|
+
|
|
1233
|
+
/** その要素を定義した層の添字 (出所が無ければ 0 = 最も弱い) */
|
|
1234
|
+
function layerOf(model: Model, file: string | undefined): number {
|
|
1235
|
+
if (file === undefined) return 0;
|
|
1236
|
+
const i = model.layers.indexOf(file);
|
|
1237
|
+
return i < 0 ? 0 : i;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
/** 出所の鍵 — `<種別>:<対象>:<属性キー>` */
|
|
1241
|
+
function srcKey(kind: string, subject: string, key: string): string {
|
|
1242
|
+
return `${kind}:${subject}:${key}`;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/** その対象の、出所を記録するときの名前 */
|
|
1246
|
+
function overSubject(t: OverTarget): string {
|
|
1247
|
+
switch (t.kind) {
|
|
1248
|
+
case "space":
|
|
1249
|
+
return t.space.path;
|
|
1250
|
+
case "zone":
|
|
1251
|
+
return t.zone.path;
|
|
1252
|
+
case "level":
|
|
1253
|
+
return t.level.name;
|
|
1254
|
+
case "asset":
|
|
1255
|
+
return t.asset.name;
|
|
1256
|
+
case "boundary":
|
|
1257
|
+
return t.boundaries.map((b) => `${b.a}|${b.b}`).join(",");
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* 属性を一つ、強度の規則に従って書き込む (合成の規則2 — 単一の値は最も強い層の意見が勝つ)。
|
|
1263
|
+
*
|
|
1264
|
+
* **走査の順ではなく強度で決める。**entry は添字0で最も弱いが、その行が
|
|
1265
|
+
* import より後に書かれていれば走査としては最後に来る。順序で決めると、
|
|
1266
|
+
* import 行を上下に動かしただけで結果が変わってしまう。
|
|
1267
|
+
*
|
|
1268
|
+
* 同じ層が同じ属性に二度意見を持つのは矛盾なのでエラーにする (`>=` ではなく `>`)。
|
|
1269
|
+
*/
|
|
1270
|
+
function applyAttr(
|
|
1271
|
+
model: Model,
|
|
1272
|
+
kind: string,
|
|
1273
|
+
subject: string,
|
|
1274
|
+
into: Attrs,
|
|
1275
|
+
key: string,
|
|
1276
|
+
value: AttrValue,
|
|
1277
|
+
layer: number,
|
|
1278
|
+
ln: number,
|
|
1279
|
+
defLayer = 0,
|
|
1280
|
+
): void {
|
|
1281
|
+
const k = srcKey(kind, subject, key);
|
|
1282
|
+
// 出所が記録されていなければ、値は**定義した層**が与えたものである。
|
|
1283
|
+
// entry (添字0) が import より後ろに over を書いても、定義した層の方が強ければ通らない —
|
|
1284
|
+
// 強度は走査の順ではなく宣言された順序で決まる (規則1)
|
|
1285
|
+
const prev = model.attrSrc.get(k) ?? (into[key] !== undefined ? defLayer : undefined);
|
|
1286
|
+
if (prev !== undefined) {
|
|
1287
|
+
if (prev > layer) return; // 強い層が既に決めている — 弱い層の意見は通らない
|
|
1288
|
+
if (prev === layer) {
|
|
1289
|
+
throw new SourceError(
|
|
1290
|
+
ln,
|
|
1291
|
+
`One layer holds two opinions about ${key} on ${subject} (which one wins is undetermined)`,
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
into[key] = value;
|
|
1296
|
+
model.attrSrc.set(k, layer);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
/** 定義された属性の出所を、その層のものとして記録する */
|
|
1300
|
+
function recordAttrs(model: Model, kind: string, subject: string, attrs: Attrs, layer: number): void {
|
|
1301
|
+
for (const key of Object.keys(attrs)) model.attrSrc.set(srcKey(kind, subject, key), layer);
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/** 集合の要素を名で引く (合成の規則3 — 同一性は「含む対象 + その中で一意な名」) */
|
|
1305
|
+
function findNamed<T extends { attrs: Attrs }>(list: T[], name: string): T[] {
|
|
1306
|
+
return list.filter((x) => String(x.attrs["name"] ?? "") === name);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* `over` の対象を解く。**書き方から種別が決まる** — 先頭のトークンが指す先で分かれる。
|
|
1311
|
+
*
|
|
1312
|
+
* over /L5/A/ldk h:2600 空間 (パス1つ)
|
|
1313
|
+
* over /site area:1100.20 ゾーン (パス1つ・空間が無ければゾーン)
|
|
1314
|
+
* over /L5/A/hall /L5/corridor 境界 (パス2つ)
|
|
1315
|
+
* over level L3 h:2600 レベル
|
|
1316
|
+
* over asset SD1 w:900 アセット
|
|
1317
|
+
*
|
|
1318
|
+
* 対象が存在しなければエラーである。**上書きは定義ではない** — 存在しないものに
|
|
1319
|
+
* 意見だけを足すのは、たいてい綴り違いか、層の順序の思い違いである。
|
|
1320
|
+
*/
|
|
1321
|
+
function resolveOverTarget(model: Model, rest: string[], ln: number): OverTarget {
|
|
1322
|
+
const head = rest[0];
|
|
1323
|
+
if (head === "level") {
|
|
1324
|
+
const name = rest[1];
|
|
1325
|
+
const lv = name ? model.levels[name] : undefined;
|
|
1326
|
+
if (!lv) throw new SourceError(ln, `No such level for over: ${name ?? "(no name)"}`);
|
|
1327
|
+
return { kind: "level", level: lv };
|
|
1328
|
+
}
|
|
1329
|
+
if (head === "asset") {
|
|
1330
|
+
const name = rest[1];
|
|
1331
|
+
const a = name ? model.assets.get(name) : undefined;
|
|
1332
|
+
if (!a) throw new SourceError(ln, `No such asset for over: ${name ?? "(no name)"}`);
|
|
1333
|
+
return { kind: "asset", asset: a };
|
|
1334
|
+
}
|
|
1335
|
+
const paths = rest.filter((t) => t.startsWith("/"));
|
|
1336
|
+
if (paths.length === 0) {
|
|
1337
|
+
throw new SourceError(
|
|
1338
|
+
ln,
|
|
1339
|
+
"over takes the form over /path … / over /pathA /pathB … / over level <name> … / over asset <name> …",
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
if (paths.length === 1) {
|
|
1343
|
+
const path = paths[0]!;
|
|
1344
|
+
const sp = model.spaces.get(path);
|
|
1345
|
+
if (sp) return { kind: "space", space: sp };
|
|
1346
|
+
const zn = model.zones.get(path);
|
|
1347
|
+
if (zn) return { kind: "zone", zone: zn };
|
|
1348
|
+
throw new SourceError(ln, `No such target for over: ${path} (place it after the layer that defines it)`);
|
|
1349
|
+
}
|
|
1350
|
+
if (paths.length > 2) {
|
|
1351
|
+
throw new SourceError(ln, `Too many paths on the over target: ${paths.join(" ")}`);
|
|
1352
|
+
}
|
|
1353
|
+
const [a, b] = paths as [string, string];
|
|
1354
|
+
const hit = model.boundaries.filter(
|
|
1355
|
+
(x) => (x.a === a && x.b === b) || (x.a === b && x.b === a),
|
|
1356
|
+
);
|
|
1357
|
+
if (hit.length === 0) {
|
|
1358
|
+
throw new SourceError(ln, `No such boundary for over: ${a} | ${b}`);
|
|
1359
|
+
}
|
|
1360
|
+
return { kind: "boundary", boundaries: hit };
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/** レベルの上書き — typed field なので属性の器を持たない。台帳の四語だけを受ける */
|
|
1364
|
+
function applyLevelAttr(
|
|
1365
|
+
model: Model,
|
|
1366
|
+
lv: Level,
|
|
1367
|
+
key: string,
|
|
1368
|
+
v: AttrValue,
|
|
1369
|
+
layer: number,
|
|
1370
|
+
ln: number,
|
|
1371
|
+
): void {
|
|
1372
|
+
const k = srcKey("level", lv.name, key);
|
|
1373
|
+
const prev = model.attrSrc.get(k) ?? layerOf(model, lv.file);
|
|
1374
|
+
if (prev > layer) return;
|
|
1375
|
+
if (prev === layer) {
|
|
1376
|
+
throw new SourceError(ln, `One layer holds two opinions about ${key} on level ${lv.name}`);
|
|
1377
|
+
}
|
|
1378
|
+
if (key === "h" || key === "slab") {
|
|
1379
|
+
if (typeof v !== "number" || !(v > 0)) {
|
|
1380
|
+
throw new SourceError(ln, `A level ${key} is written as a positive number: ${key}:${v}`);
|
|
1381
|
+
}
|
|
1382
|
+
lv[key] = v;
|
|
1383
|
+
} else if (key === "underground") {
|
|
1384
|
+
if (v !== 0 && v !== 1) throw new SourceError(ln, "underground is given as 0 / 1");
|
|
1385
|
+
lv.underground = v === 1;
|
|
1386
|
+
} else {
|
|
1387
|
+
throw new SourceError(ln, `Only h / slab / underground may be overridden on a level: ${key}`);
|
|
1388
|
+
}
|
|
1389
|
+
model.attrSrc.set(k, layer);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
/** 境界の上書き — typed field (type/t/air/edge) と自由属性の両方を受ける */
|
|
1393
|
+
function applyBoundaryAttr(
|
|
1394
|
+
model: Model,
|
|
1395
|
+
b: Boundary,
|
|
1396
|
+
key: string,
|
|
1397
|
+
v: AttrValue,
|
|
1398
|
+
layer: number,
|
|
1399
|
+
ln: number,
|
|
1400
|
+
): void {
|
|
1401
|
+
const subject = `${b.a}|${b.b}`;
|
|
1402
|
+
const k = srcKey("boundary", subject, key);
|
|
1403
|
+
const prev = model.attrSrc.get(k) ?? layerOf(model, b.file);
|
|
1404
|
+
if (prev > layer) return;
|
|
1405
|
+
if (prev === layer) {
|
|
1406
|
+
throw new SourceError(ln, `One layer holds two opinions about ${key} on boundary ${subject}`);
|
|
1407
|
+
}
|
|
1408
|
+
if (key === "type") {
|
|
1409
|
+
const kind = String(v);
|
|
1410
|
+
if (!BOUNDARY_KINDS.has(kind)) {
|
|
1411
|
+
throw new SourceError(ln, `A boundary type is ${[...BOUNDARY_KINDS].join(" / ")}: ${kind}`);
|
|
1412
|
+
}
|
|
1413
|
+
b.kind = kind as Boundary["kind"];
|
|
1414
|
+
} else if (key === "t") {
|
|
1415
|
+
if (typeof v !== "number" || !(v > 0)) throw new SourceError(ln, `t is written as a positive number: t:${v}`);
|
|
1416
|
+
b.t = v;
|
|
1417
|
+
} else if (key === "air") {
|
|
1418
|
+
b.air = v === 1 ? true : undefined;
|
|
1419
|
+
} else if (key === "edge") {
|
|
1420
|
+
if (!EDGES.has(String(v))) throw new SourceError(ln, `edge is given as N/E/S/W: ${v}`);
|
|
1421
|
+
b.edge = String(v) as Edge;
|
|
1422
|
+
} else {
|
|
1423
|
+
b.attrs[key] = v;
|
|
1424
|
+
}
|
|
1425
|
+
model.attrSrc.set(k, layer);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* 集合の編集 (合成の規則3 — 追加 / 削除 / 置換)。**暗黙のマージをしない。**
|
|
1430
|
+
*
|
|
1431
|
+
* + door SD1 w:900 at:X4 name:D9 追加
|
|
1432
|
+
* - door D9 削除 (名で指す)
|
|
1433
|
+
* = door D9 w:1200 置換 (名で指し、書いた属性だけを差し替える)
|
|
1434
|
+
*
|
|
1435
|
+
* 同一性は「含む対象 + その中で一意な名」である (spec/scope.md §5)。
|
|
1436
|
+
* 名を持たない要素は編集の対象にできない — 指す言葉が無いからである。
|
|
1437
|
+
*/
|
|
1438
|
+
function applySetEdit(
|
|
1439
|
+
model: Model,
|
|
1440
|
+
target: OverTarget,
|
|
1441
|
+
op: "+" | "-" | "=",
|
|
1442
|
+
rest: string[],
|
|
1443
|
+
ln: number,
|
|
1444
|
+
layer: number,
|
|
1445
|
+
): void {
|
|
1446
|
+
const what = rest[0];
|
|
1447
|
+
if (!what) throw new SourceError(ln, `${op} takes door / window / seg / area after it`);
|
|
1448
|
+
const args = rest.slice(1);
|
|
1449
|
+
|
|
1450
|
+
if (target.kind === "space") {
|
|
1451
|
+
if (what !== "area") {
|
|
1452
|
+
throw new SourceError(ln, `over on a space edits area: ${what}`);
|
|
1453
|
+
}
|
|
1454
|
+
editList(model, target.space.areas, op, args, ln, () => parseArea(args, ln, model), "area");
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
if (target.kind !== "boundary") {
|
|
1458
|
+
throw new SourceError(ln, `over on ${target.kind} has no set edits`);
|
|
1459
|
+
}
|
|
1460
|
+
for (const b of target.boundaries) {
|
|
1461
|
+
if (what === "door" || what === "window") {
|
|
1462
|
+
editList(model, b.openings, op, args, ln, () => parseOpening(what, args, ln, model), what);
|
|
1463
|
+
} else if (what === "seg") {
|
|
1464
|
+
editList(model, b.segs, op, args, ln, () => parseSeg(args, ln, model), "seg");
|
|
1465
|
+
} else {
|
|
1466
|
+
throw new SourceError(ln, `over on a boundary edits door / window / seg: ${what}`);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
/** 一つの集合に対する追加・削除・置換 */
|
|
1472
|
+
function editList<T extends { attrs: Attrs }>(
|
|
1473
|
+
model: Model,
|
|
1474
|
+
list: T[],
|
|
1475
|
+
op: "+" | "-" | "=",
|
|
1476
|
+
args: string[],
|
|
1477
|
+
ln: number,
|
|
1478
|
+
make: () => T,
|
|
1479
|
+
what: string,
|
|
1480
|
+
): void {
|
|
1481
|
+
if (op === "+") {
|
|
1482
|
+
const made = make();
|
|
1483
|
+
if (String(made.attrs["name"] ?? "") === "") {
|
|
1484
|
+
throw new SourceError(ln, `A ${what} added with + requires name: (it is the name later statements point to)`);
|
|
1485
|
+
}
|
|
1486
|
+
if (findNamed(list, String(made.attrs["name"])).length > 0) {
|
|
1487
|
+
throw new SourceError(ln, `Duplicate ${what} name: ${made.attrs["name"]}`);
|
|
1488
|
+
}
|
|
1489
|
+
list.push(made);
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
const name = args[0];
|
|
1493
|
+
if (!name || name.includes(":")) {
|
|
1494
|
+
throw new SourceError(ln, `${op} ${what} takes the name it points to (${op} ${what} D1)`);
|
|
1495
|
+
}
|
|
1496
|
+
const hit = findNamed(list, name);
|
|
1497
|
+
if (hit.length === 0) throw new SourceError(ln, `No such ${what}: ${name}`);
|
|
1498
|
+
if (hit.length > 1) throw new SourceError(ln, `The ${what} name ${name} is not unique`);
|
|
1499
|
+
const idx = list.indexOf(hit[0]!);
|
|
1500
|
+
if (op === "-") {
|
|
1501
|
+
list.splice(idx, 1);
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
// = は書いた属性だけを差し替える (全置換ではない — 名は残る)
|
|
1505
|
+
const patch = parseAttrs(args.slice(1), ln);
|
|
1506
|
+
Object.assign(list[idx]!.attrs, patch);
|
|
1507
|
+
applyTypedPatch(list[idx]!, patch, ln);
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
/** 置換で typed field (w/h/at) に触れたぶんを反映する */
|
|
1511
|
+
function applyTypedPatch(item: { attrs: Attrs } & Record<string, unknown>, patch: Attrs, ln: number): void {
|
|
1512
|
+
for (const key of ["w", "h"]) {
|
|
1513
|
+
const v = patch[key];
|
|
1514
|
+
if (v === undefined) continue;
|
|
1515
|
+
if (typeof v !== "number" || !(v > 0)) {
|
|
1516
|
+
throw new SourceError(ln, `${key} is written as a positive number: ${key}:${v}`);
|
|
1517
|
+
}
|
|
1518
|
+
item[key] = v;
|
|
1519
|
+
delete item.attrs[key];
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* 削除 (合成の規則3)。**消えるのは、消すと書いたものだけである。**
|
|
1525
|
+
*
|
|
1526
|
+
* drop /L5/A/store 空間 (その空間に繋がる境界も一緒に消える)
|
|
1527
|
+
* drop /L5/a /L5/b 境界
|
|
1528
|
+
* drop column <名> 柱の宣言
|
|
1529
|
+
*/
|
|
1530
|
+
function applyDrop(model: Model, rest: string[], ln: number): void {
|
|
1531
|
+
if (rest[0] === "column") {
|
|
1532
|
+
const name = rest[1];
|
|
1533
|
+
if (!name) throw new SourceError(ln, "drop column takes the name of a column");
|
|
1534
|
+
const hit = findNamed(model.columns, name);
|
|
1535
|
+
if (hit.length === 0) throw new SourceError(ln, `No such column: ${name}`);
|
|
1536
|
+
// **消えるのは、消すと書いたものだけである。**名が二本の柱を指しているなら
|
|
1537
|
+
// どちらを消すのかは書かれていない — 黙って両方消さずに拒む (ADR-0039)。
|
|
1538
|
+
// 開口・seg の集合編集 (editList) と同じ規律である
|
|
1539
|
+
if (hit.length > 1) throw new SourceError(ln, `The column name ${name} is not unique`);
|
|
1540
|
+
model.columns = model.columns.filter((c) => c !== hit[0]);
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
const paths = rest.filter((t) => t.startsWith("/"));
|
|
1544
|
+
if (paths.length === 1) {
|
|
1545
|
+
const path = paths[0]!;
|
|
1546
|
+
if (model.spaces.delete(path)) {
|
|
1547
|
+
// 空間が消えれば、その空間を端に持つ関係も消える — 関係は空間の間にしか無い
|
|
1548
|
+
model.boundaries = model.boundaries.filter((b) => b.a !== path && b.b !== path);
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1551
|
+
if (model.zones.delete(path)) return;
|
|
1552
|
+
throw new SourceError(ln, `No such target for drop: ${path}`);
|
|
1553
|
+
}
|
|
1554
|
+
if (paths.length === 2) {
|
|
1555
|
+
const [a, b] = paths as [string, string];
|
|
1556
|
+
const before = model.boundaries.length;
|
|
1557
|
+
model.boundaries = model.boundaries.filter(
|
|
1558
|
+
(x) => !((x.a === a && x.b === b) || (x.a === b && x.b === a)),
|
|
1559
|
+
);
|
|
1560
|
+
if (model.boundaries.length === before) {
|
|
1561
|
+
throw new SourceError(ln, `No such boundary for drop: ${a} | ${b}`);
|
|
1562
|
+
}
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
throw new SourceError(ln, "drop takes the form drop /path / drop /pathA /pathB / drop column <name>");
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1100
1568
|
function parseAttrs(tokens: string[], ln: number): Attrs {
|
|
1101
1569
|
const attrs: Attrs = {};
|
|
1102
1570
|
for (const t of tokens) {
|
|
1103
1571
|
const idx = t.indexOf(":");
|
|
1104
|
-
if (idx <= 0) throw new SourceError(ln,
|
|
1572
|
+
if (idx <= 0) throw new SourceError(ln, `An attribute is written key:value: ${t}`);
|
|
1105
1573
|
const key = t.slice(0, idx);
|
|
1106
1574
|
const rawVal = t.slice(idx + 1);
|
|
1107
|
-
if (rawVal === "") throw new SourceError(ln,
|
|
1575
|
+
if (rawVal === "") throw new SourceError(ln, `The attribute ${key} has no value`);
|
|
1108
1576
|
if (attrs[key] !== undefined) {
|
|
1109
1577
|
// 後勝ちの黙認はtypoとマージ事故を隠す — 同一行内の重複はエラー (ADR-0013)
|
|
1110
|
-
throw new SourceError(ln,
|
|
1578
|
+
throw new SourceError(ln, `Duplicate attribute key: ${key}`);
|
|
1111
1579
|
}
|
|
1112
1580
|
attrs[key] = maybeNumber(rawVal);
|
|
1113
1581
|
}
|
|
@@ -1119,7 +1587,7 @@ function maybeNumber(v: string): AttrValue {
|
|
|
1119
1587
|
}
|
|
1120
1588
|
|
|
1121
1589
|
function toNumber(v: string, ln: number, what: string): number {
|
|
1122
|
-
if (!/^-?\d+(\.\d+)?$/.test(v)) throw new SourceError(ln, `${what}
|
|
1590
|
+
if (!/^-?\d+(\.\d+)?$/.test(v)) throw new SourceError(ln, `${what} is not a number: ${v}`);
|
|
1123
1591
|
return Number(v);
|
|
1124
1592
|
}
|
|
1125
1593
|
|
|
@@ -1129,7 +1597,7 @@ function takeNumber(attrs: Attrs, key: string, ln: number): number | undefined {
|
|
|
1129
1597
|
delete attrs[key];
|
|
1130
1598
|
if (typeof v !== "number") {
|
|
1131
1599
|
// NaNの黙認はcheck緑のまま導出を壊す (typo h:24O0 など) — その場のエラーにする
|
|
1132
|
-
throw new SourceError(ln,
|
|
1600
|
+
throw new SourceError(ln, `The attribute ${key} is written as a number: ${v}`);
|
|
1133
1601
|
}
|
|
1134
1602
|
return v;
|
|
1135
1603
|
}
|
|
@@ -1144,6 +1612,6 @@ function takeString(attrs: Attrs, key: string): string | undefined {
|
|
|
1144
1612
|
function takeEdge(attrs: Attrs, ln: number): Edge | undefined {
|
|
1145
1613
|
const v = takeString(attrs, "edge");
|
|
1146
1614
|
if (v === undefined) return undefined;
|
|
1147
|
-
if (!EDGES.has(v)) throw new SourceError(ln, `edge
|
|
1615
|
+
if (!EDGES.has(v)) throw new SourceError(ln, `edge is given as N/E/S/W: ${v}`);
|
|
1148
1616
|
return v as Edge;
|
|
1149
1617
|
}
|