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