@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
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// 分担して書き、合成時のコンフリクト (パス・アセット・グリッドの重複) は言葉のエラーになる。
|
|
5
5
|
import { DEFAULT_LANGUAGE_VERSION, SourceError, SUPPORTED_LANGUAGE_VERSIONS, } from "./model.js";
|
|
6
6
|
import { deriveDefaultBoundaries, derivePieces } from "./graph.js";
|
|
7
|
+
/** 境界のトポロジー語 — 増やすのは最後の手段である (spec/vocabulary.md 規則1) */
|
|
8
|
+
const BOUNDARY_KINDS = new Set(["wall", "open", "stair", "shaft", "void"]);
|
|
7
9
|
const EDGES = new Set(["N", "E", "S", "W"]);
|
|
8
10
|
function emptyModel() {
|
|
9
11
|
return {
|
|
@@ -18,12 +20,14 @@ function emptyModel() {
|
|
|
18
20
|
polygons: new Map(),
|
|
19
21
|
columns: [],
|
|
20
22
|
layers: [],
|
|
23
|
+
attrSrc: new Map(),
|
|
24
|
+
compositionEdits: [],
|
|
21
25
|
};
|
|
22
26
|
}
|
|
23
27
|
export function parse(source) {
|
|
24
28
|
const model = emptyModel();
|
|
25
29
|
ingest(model, source, undefined, new Set(), undefined);
|
|
26
|
-
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 /
|
|
30
|
+
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 / spec/derivation.md §1)。
|
|
27
31
|
// 逆順だと、線で接触が消えた組にも既定境界が生まれ、線分ゼロの境界に
|
|
28
32
|
// 出所の無い BND04 が出る — 書いていない関係を責めることになる
|
|
29
33
|
derivePieces(model);
|
|
@@ -38,10 +42,10 @@ export function parseWith(loader, entry) {
|
|
|
38
42
|
layer = loader(undefined, entry);
|
|
39
43
|
}
|
|
40
44
|
catch {
|
|
41
|
-
throw new SourceError(0,
|
|
45
|
+
throw new SourceError(0, `Cannot read file: ${entry}`);
|
|
42
46
|
}
|
|
43
47
|
ingestLayer(model, layer.key, layer.src, new Set(), loader);
|
|
44
|
-
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 /
|
|
48
|
+
// 描かれた線で領域を切り分けてから、既定の壁を導く (ADR-0022 / spec/derivation.md §1)。
|
|
45
49
|
// 逆順だと、線で接触が消えた組にも既定境界が生まれ、線分ゼロの境界に
|
|
46
50
|
// 出所の無い BND04 が出る — 書いていない関係を責めることになる
|
|
47
51
|
derivePieces(model);
|
|
@@ -83,14 +87,23 @@ function ingestLayer(model, key, src, seen, loader) {
|
|
|
83
87
|
if (seen.has(key))
|
|
84
88
|
return; // 同じレイヤーは一度だけ合成される (USDのsublayerと同じ)
|
|
85
89
|
seen.add(key);
|
|
86
|
-
|
|
90
|
+
// **この push の順序が層の強度順序である** (spec/composition.md 規則1)。
|
|
91
|
+
// entry が添字0で最も弱く、後の層ほど強い。同じ層が二度 import されても最初の位置を保つ
|
|
92
|
+
model.layers.push(key);
|
|
87
93
|
ingest(model, src, key, seen, loader);
|
|
88
94
|
}
|
|
89
95
|
function ingest(model, source, file, seen, loader) {
|
|
96
|
+
/** この層の強度。単一ソースの parse では層が無いので 0 とする */
|
|
97
|
+
const layer = file === undefined ? 0 : Math.max(0, model.layers.indexOf(file));
|
|
90
98
|
let current = [];
|
|
91
99
|
let currentSpaces = [];
|
|
100
|
+
let over;
|
|
92
101
|
let band; // 帯は次の非字下げ行か層の終わりで展開される (ADR-0019)
|
|
93
|
-
|
|
102
|
+
// **原本は NFC として読む** (ADR-0036)。`が` は一つの符号位置とも「か + 濁点」とも綴れ、
|
|
103
|
+
// 正規化しなければ同じに見える二つのパスが別の空間になり (パス重複のエラーも出ない)、
|
|
104
|
+
// 正準JSONには見分けのつかないキーが二つ並ぶ。同一性はここで一つに決める。
|
|
105
|
+
// NFKC は採らない — ㎡ や ① を書き換えてしまい、それは書かれた表記の保存に反する
|
|
106
|
+
const lines = source.normalize("NFC").split(/\r?\n/);
|
|
94
107
|
for (let i = 0; i < lines.length; i++) {
|
|
95
108
|
try {
|
|
96
109
|
const raw = lines[i];
|
|
@@ -101,16 +114,24 @@ function ingest(model, source, file, seen, loader) {
|
|
|
101
114
|
const indented = /^\s/.test(raw);
|
|
102
115
|
const [head, ...rest] = tokens;
|
|
103
116
|
if (indented) {
|
|
104
|
-
if (head === "
|
|
117
|
+
if (over && (head === "+" || head === "-" || head === "=")) {
|
|
118
|
+
// 1.0 の語である — 出所を残す (VER04。上書きの跡は合成後に残らない — ADR-0038)
|
|
119
|
+
model.compositionEdits.push({ word: head, subject: rest.join(" "), line: ln, file });
|
|
120
|
+
applySetEdit(model, over, head, rest, ln, layer);
|
|
121
|
+
}
|
|
122
|
+
else if (over) {
|
|
123
|
+
throw new SourceError(ln, `Only + (add) / - (remove) / = (replace) may sit directly under over: ${head}`);
|
|
124
|
+
}
|
|
125
|
+
else if (head === "door" || head === "window") {
|
|
105
126
|
if (current.length === 0) {
|
|
106
|
-
throw new SourceError(ln, `${head}
|
|
127
|
+
throw new SourceError(ln, `${head} is written indented directly under boundary`);
|
|
107
128
|
}
|
|
108
129
|
for (const b of current)
|
|
109
130
|
b.openings.push(parseOpening(head, rest, ln, model));
|
|
110
131
|
}
|
|
111
132
|
else if (head === "seg") {
|
|
112
133
|
if (current.length === 0) {
|
|
113
|
-
throw new SourceError(ln, "seg
|
|
134
|
+
throw new SourceError(ln, "seg is written indented directly under boundary");
|
|
114
135
|
}
|
|
115
136
|
for (const b of current)
|
|
116
137
|
b.segs.push(parseSeg(rest, ln, model));
|
|
@@ -118,21 +139,21 @@ function ingest(model, source, file, seen, loader) {
|
|
|
118
139
|
else if (head === "line") {
|
|
119
140
|
// 描かれた線 (ADR-0022) — 境界の実現を、隣接からの導出ではなく設計の行為で与える
|
|
120
141
|
if (current.length === 0) {
|
|
121
|
-
throw new SourceError(ln, "line
|
|
142
|
+
throw new SourceError(ln, "line is written indented directly under boundary");
|
|
122
143
|
}
|
|
123
144
|
const drawn = parseDrawnLine(rest, ln, model);
|
|
124
145
|
for (const b of current) {
|
|
125
146
|
if (b.drawn)
|
|
126
|
-
throw new SourceError(ln,
|
|
147
|
+
throw new SourceError(ln, `One boundary carries one line: ${b.a} | ${b.b}`);
|
|
127
148
|
b.drawn = { ...drawn };
|
|
128
149
|
}
|
|
129
150
|
}
|
|
130
151
|
else if (head === "area") {
|
|
131
152
|
if (band) {
|
|
132
|
-
throw new SourceError(ln, "
|
|
153
|
+
throw new SourceError(ln, "area may not be written on a band member (its region is derived — write a room that needs area by position)");
|
|
133
154
|
}
|
|
134
155
|
if (currentSpaces.length === 0) {
|
|
135
|
-
throw new SourceError(ln, "area
|
|
156
|
+
throw new SourceError(ln, "area is written indented directly under space");
|
|
136
157
|
}
|
|
137
158
|
for (const s of currentSpaces)
|
|
138
159
|
s.areas.push(parseArea(rest, ln, model));
|
|
@@ -140,11 +161,11 @@ function ingest(model, source, file, seen, loader) {
|
|
|
140
161
|
else if (head === "space") {
|
|
141
162
|
// 帯の要素 — 領域の代わりに幅 w: を持つ space 行 (ADR-0019)
|
|
142
163
|
if (!band)
|
|
143
|
-
throw new SourceError(ln, "
|
|
164
|
+
throw new SourceError(ln, "an indented space is written directly under band");
|
|
144
165
|
band.members.push(parseBandMember(rest, ln));
|
|
145
166
|
}
|
|
146
167
|
else {
|
|
147
|
-
throw new SourceError(ln,
|
|
168
|
+
throw new SourceError(ln, `Only door / window / seg / line / area / space (a band member) may sit on an indented line: ${head}`);
|
|
148
169
|
}
|
|
149
170
|
continue;
|
|
150
171
|
}
|
|
@@ -155,24 +176,25 @@ function ingest(model, source, file, seen, loader) {
|
|
|
155
176
|
}
|
|
156
177
|
current = [];
|
|
157
178
|
currentSpaces = [];
|
|
179
|
+
over = undefined;
|
|
158
180
|
switch (head) {
|
|
159
181
|
case "koyu": {
|
|
160
182
|
const v = rest[0];
|
|
161
183
|
if (!v)
|
|
162
|
-
throw new SourceError(ln, `koyu
|
|
184
|
+
throw new SourceError(ln, `koyu takes a version: koyu ${DEFAULT_LANGUAGE_VERSION}`);
|
|
163
185
|
if (rest.length > 1) {
|
|
164
|
-
throw new SourceError(ln, `koyu
|
|
186
|
+
throw new SourceError(ln, `Extra tokens on the koyu version declaration: ${rest.slice(1).join(" ")}`);
|
|
165
187
|
}
|
|
166
188
|
if (!SUPPORTED_LANGUAGE_VERSIONS.includes(v)) {
|
|
167
|
-
throw new SourceError(ln,
|
|
189
|
+
throw new SourceError(ln, `Unsupported koyu version: ${v} (this tool supports ${SUPPORTED_LANGUAGE_VERSIONS.join(", ")})`);
|
|
168
190
|
}
|
|
169
191
|
// 版はbase層 (entry) でのみ・一度だけ宣言する — 合成順による黙った上書きを禁じる (ADR-0017)。
|
|
170
192
|
// gridの規律に合わせ、再宣言は同値でもエラー
|
|
171
193
|
if (file !== undefined && model.layers[0] !== file) {
|
|
172
|
-
throw new SourceError(ln, "koyu
|
|
194
|
+
throw new SourceError(ln, "The koyu version is declared only in the base layer (the entry)");
|
|
173
195
|
}
|
|
174
196
|
if (model.versionDeclared) {
|
|
175
|
-
throw new SourceError(ln, `koyu
|
|
197
|
+
throw new SourceError(ln, `The koyu version is declared once (already ${model.version})`);
|
|
176
198
|
}
|
|
177
199
|
model.version = v;
|
|
178
200
|
model.versionDeclared = true;
|
|
@@ -181,33 +203,68 @@ function ingest(model, source, file, seen, loader) {
|
|
|
181
203
|
case "import": {
|
|
182
204
|
const rel = rest[0];
|
|
183
205
|
if (!rel)
|
|
184
|
-
throw new SourceError(ln, "import
|
|
206
|
+
throw new SourceError(ln, "import takes a relative path: import ./assets.muro");
|
|
185
207
|
if (!loader) {
|
|
186
|
-
throw new SourceError(ln, "import
|
|
208
|
+
throw new SourceError(ln, "import is available only in file composition (parseFile / parseFiles / CLI)");
|
|
187
209
|
}
|
|
188
210
|
let layer;
|
|
189
211
|
try {
|
|
190
212
|
layer = loader(file, rel);
|
|
191
213
|
}
|
|
192
214
|
catch {
|
|
193
|
-
throw new SourceError(ln,
|
|
215
|
+
throw new SourceError(ln, `Cannot read file: ${rel}`);
|
|
194
216
|
}
|
|
195
217
|
ingestLayer(model, layer.key, layer.src, seen, loader);
|
|
196
218
|
break;
|
|
197
219
|
}
|
|
220
|
+
case "over": {
|
|
221
|
+
// 上書き (合成の規則2・4)。**定義ではない** — 対象が既に無ければエラーである
|
|
222
|
+
model.compositionEdits.push({ word: "over", subject: rest.join(" "), line: ln, file });
|
|
223
|
+
over = resolveOverTarget(model, rest, ln);
|
|
224
|
+
const attrs = parseAttrs(rest.filter((t) => t.includes(":") && !t.startsWith("/")), ln);
|
|
225
|
+
const subject = overSubject(over);
|
|
226
|
+
for (const [key, v] of Object.entries(attrs)) {
|
|
227
|
+
switch (over.kind) {
|
|
228
|
+
case "space":
|
|
229
|
+
applyAttr(model, "space", subject, over.space.attrs, key, v, layer, ln, layerOf(model, over.space.file));
|
|
230
|
+
break;
|
|
231
|
+
case "zone":
|
|
232
|
+
applyAttr(model, "zone", subject, over.zone.attrs, key, v, layer, ln, layerOf(model, over.zone.file));
|
|
233
|
+
break;
|
|
234
|
+
case "asset":
|
|
235
|
+
applyAttr(model, "asset", subject, over.asset.attrs, key, v, layer, ln, layerOf(model, over.asset.file));
|
|
236
|
+
break;
|
|
237
|
+
case "level":
|
|
238
|
+
applyLevelAttr(model, over.level, key, v, layer, ln);
|
|
239
|
+
break;
|
|
240
|
+
case "boundary":
|
|
241
|
+
for (const b of over.boundaries) {
|
|
242
|
+
applyBoundaryAttr(model, b, key, v, layer, ln);
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "drop": {
|
|
250
|
+
// 集合からの削除 (合成の規則3)。暗黙の消滅は無い — 消すと書いたものだけが消える
|
|
251
|
+
model.compositionEdits.push({ word: "drop", subject: rest.join(" "), line: ln, file });
|
|
252
|
+
applyDrop(model, rest, ln);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
198
255
|
case "asset": {
|
|
199
256
|
// 建具アセット (RevitのFamily / USDのReference — ADR-0010)
|
|
200
257
|
const aname = rest[0];
|
|
201
258
|
const akind = rest[1];
|
|
202
259
|
if (!aname || aname.includes(":") || aname.startsWith("/")) {
|
|
203
|
-
throw new SourceError(ln, "asset
|
|
260
|
+
throw new SourceError(ln, "asset takes the form asset <name> door|window [attributes...]");
|
|
204
261
|
}
|
|
205
262
|
if (akind !== "door" && akind !== "window") {
|
|
206
|
-
throw new SourceError(ln, `asset
|
|
263
|
+
throw new SourceError(ln, `An asset kind is door / window: ${akind}`);
|
|
207
264
|
}
|
|
208
265
|
const prevA = model.assets.get(aname);
|
|
209
266
|
if (prevA) {
|
|
210
|
-
throw new SourceError(ln,
|
|
267
|
+
throw new SourceError(ln, `Duplicate asset name: ${aname} (first seen in ${prevA.file ?? "the same file"} at line ${prevA.line})`);
|
|
211
268
|
}
|
|
212
269
|
model.assets.set(aname, {
|
|
213
270
|
name: aname,
|
|
@@ -223,19 +280,19 @@ function ingest(model, source, file, seen, loader) {
|
|
|
223
280
|
// polygon /site -2600,-7000 38000,-7000 38000,15600 2000,16800 -2600,12000
|
|
224
281
|
const ppath = rest[0];
|
|
225
282
|
if (!ppath || !ppath.startsWith("/")) {
|
|
226
|
-
throw new SourceError(ln, "polygon
|
|
283
|
+
throw new SourceError(ln, "polygon takes the form polygon /zone-path x,y x,y x,y ...");
|
|
227
284
|
}
|
|
228
285
|
const pts = rest.slice(1).map((tok) => {
|
|
229
286
|
const m = /^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(tok);
|
|
230
287
|
if (!m)
|
|
231
|
-
throw new SourceError(ln,
|
|
288
|
+
throw new SourceError(ln, `Cannot read the vertex (x,y in mm): ${tok}`);
|
|
232
289
|
return { x: Number(m[1]), y: Number(m[2]) };
|
|
233
290
|
});
|
|
234
291
|
if (pts.length < 3)
|
|
235
|
-
throw new SourceError(ln, "polygon
|
|
292
|
+
throw new SourceError(ln, "polygon takes three or more vertices");
|
|
236
293
|
const prevP = model.polygons.get(ppath);
|
|
237
294
|
if (prevP) {
|
|
238
|
-
throw new SourceError(ln,
|
|
295
|
+
throw new SourceError(ln, `Duplicate site shape: ${ppath} (first seen in ${prevP.file ?? "the same file"} at line ${prevP.line})`);
|
|
239
296
|
}
|
|
240
297
|
model.polygons.set(ppath, {
|
|
241
298
|
path: ppath,
|
|
@@ -248,32 +305,32 @@ function ingest(model, source, file, seen, loader) {
|
|
|
248
305
|
case "name": {
|
|
249
306
|
const nm = rest.join(" ");
|
|
250
307
|
if (!nm)
|
|
251
|
-
throw new SourceError(ln, "name
|
|
308
|
+
throw new SourceError(ln, "name takes a value");
|
|
252
309
|
if (model.name !== undefined && model.name !== nm) {
|
|
253
|
-
throw new SourceError(ln, `name
|
|
310
|
+
throw new SourceError(ln, `name is declared once (already "${model.name}" — in the base layer when composing)`);
|
|
254
311
|
}
|
|
255
312
|
model.name = nm;
|
|
256
313
|
break;
|
|
257
314
|
}
|
|
258
315
|
case "unit": {
|
|
259
316
|
if (rest[0] !== "mm")
|
|
260
|
-
throw new SourceError(ln, `v0
|
|
317
|
+
throw new SourceError(ln, `The only unit in v0 is mm: ${rest[0]}`);
|
|
261
318
|
break;
|
|
262
319
|
}
|
|
263
320
|
case "grid": {
|
|
264
321
|
const axis = rest[0];
|
|
265
322
|
if (axis !== "X" && axis !== "Y") {
|
|
266
|
-
throw new SourceError(ln, `grid
|
|
323
|
+
throw new SourceError(ln, `A grid axis is X or Y: ${axis}`);
|
|
267
324
|
}
|
|
268
325
|
if (model.grid[axis].coords.length > 0) {
|
|
269
|
-
throw new SourceError(ln, `grid ${axis}
|
|
326
|
+
throw new SourceError(ln, `grid ${axis} is declared once (in the base layer when composing)`);
|
|
270
327
|
}
|
|
271
|
-
const coords = rest.slice(1).map((t) => toNumber(t, ln, "grid
|
|
328
|
+
const coords = rest.slice(1).map((t) => toNumber(t, ln, "The grid coordinate"));
|
|
272
329
|
if (coords.length < 2)
|
|
273
|
-
throw new SourceError(ln, "grid
|
|
330
|
+
throw new SourceError(ln, "grid takes two or more coordinates");
|
|
274
331
|
for (let k = 1; k < coords.length; k++) {
|
|
275
332
|
if (coords[k] <= coords[k - 1]) {
|
|
276
|
-
throw new SourceError(ln, "grid
|
|
333
|
+
throw new SourceError(ln, "grid coordinates are written in ascending order");
|
|
277
334
|
}
|
|
278
335
|
}
|
|
279
336
|
model.grid[axis] = {
|
|
@@ -285,15 +342,20 @@ function ingest(model, source, file, seen, loader) {
|
|
|
285
342
|
case "level": {
|
|
286
343
|
const name = rest[0];
|
|
287
344
|
if (!name)
|
|
288
|
-
throw new SourceError(ln, "level
|
|
289
|
-
const z = toNumber(rest[1] ?? "", ln, "level
|
|
345
|
+
throw new SourceError(ln, "level requires a name");
|
|
346
|
+
const z = toNumber(rest[1] ?? "", ln, "The level height (z)");
|
|
290
347
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
291
348
|
const h = takeNumber(attrs, "h", ln);
|
|
292
349
|
const slab = takeNumber(attrs, "slab", ln);
|
|
293
350
|
const pitch = takeNumber(attrs, "pitch", ln);
|
|
294
351
|
const under = takeNumber(attrs, "underground", ln);
|
|
352
|
+
// **level は attrs を持たない。**残ったキーは正準JSONにも痕跡を残さず消えるので、
|
|
353
|
+
// ここで拒まないと `undergound:1` が黙って地上階になる (ADR-0033)
|
|
354
|
+
for (const key of Object.keys(attrs)) {
|
|
355
|
+
throw new SourceError(ln, `level carries ${key}:, which is not in the ledger (level reads h / slab / pitch / underground)`);
|
|
356
|
+
}
|
|
295
357
|
if (under !== undefined && under !== 0 && under !== 1) {
|
|
296
|
-
throw new SourceError(ln, "underground
|
|
358
|
+
throw new SourceError(ln, "underground is given as 0 / 1 (1 = below ground)");
|
|
297
359
|
}
|
|
298
360
|
const ug = under === 1 ? { underground: true } : {};
|
|
299
361
|
// 範囲宣言: level L3..L9 6700 pitch:2900 — 基準階のレベルを一度に宣言する
|
|
@@ -301,15 +363,15 @@ function ingest(model, source, file, seen, loader) {
|
|
|
301
363
|
if (range) {
|
|
302
364
|
const [, p1, n1, p2, n2] = range;
|
|
303
365
|
if (p1 !== p2 || Number(n1) >= Number(n2)) {
|
|
304
|
-
throw new SourceError(ln,
|
|
366
|
+
throw new SourceError(ln, `Cannot read the level range: ${name}`);
|
|
305
367
|
}
|
|
306
368
|
if (pitch === undefined || pitch <= 0) {
|
|
307
|
-
throw new SourceError(ln,
|
|
369
|
+
throw new SourceError(ln, `A level range requires pitch: (the storey height in mm): ${name}`);
|
|
308
370
|
}
|
|
309
371
|
for (let k = Number(n1); k <= Number(n2); k++) {
|
|
310
372
|
const nm = `${p1}${k}`;
|
|
311
373
|
if (model.levels[nm])
|
|
312
|
-
throw new SourceError(ln,
|
|
374
|
+
throw new SourceError(ln, `Duplicate level: ${nm}`);
|
|
313
375
|
model.levels[nm] = {
|
|
314
376
|
name: nm,
|
|
315
377
|
z: z + pitch * (k - Number(n1)),
|
|
@@ -323,10 +385,10 @@ function ingest(model, source, file, seen, loader) {
|
|
|
323
385
|
break;
|
|
324
386
|
}
|
|
325
387
|
if (pitch !== undefined) {
|
|
326
|
-
throw new SourceError(ln, "pitch
|
|
388
|
+
throw new SourceError(ln, "pitch is available only on a level range declaration (L?..L?)");
|
|
327
389
|
}
|
|
328
390
|
if (model.levels[name])
|
|
329
|
-
throw new SourceError(ln,
|
|
391
|
+
throw new SourceError(ln, `Duplicate level: ${name}`);
|
|
330
392
|
model.levels[name] = {
|
|
331
393
|
name,
|
|
332
394
|
z,
|
|
@@ -340,18 +402,18 @@ function ingest(model, source, file, seen, loader) {
|
|
|
340
402
|
}
|
|
341
403
|
case "column": {
|
|
342
404
|
// 柱 (ADR-0023) — 寸法と階と通りだけを書く。位置は通り芯の交点から導出される
|
|
343
|
-
const size = toNumber(rest[0] ?? "", ln, "column
|
|
405
|
+
const size = toNumber(rest[0] ?? "", ln, "The column dimension");
|
|
344
406
|
if (size <= 0)
|
|
345
|
-
throw new SourceError(ln, "column
|
|
407
|
+
throw new SourceError(ln, "A column dimension is written as a positive value in mm");
|
|
346
408
|
const span = rest[1];
|
|
347
409
|
if (!span) {
|
|
348
|
-
throw new SourceError(ln, "column
|
|
410
|
+
throw new SourceError(ln, "column takes the form column <size mm> <L?..L?|level name> [x:grid,..] [y:grid,..]");
|
|
349
411
|
}
|
|
350
412
|
const levels = /\.\./.test(span)
|
|
351
413
|
? resolveSpanLevels(model, span, ln)
|
|
352
414
|
: (() => {
|
|
353
415
|
if (!model.levels[span])
|
|
354
|
-
throw new SourceError(ln,
|
|
416
|
+
throw new SourceError(ln, `Undeclared level: ${span}`);
|
|
355
417
|
return [span];
|
|
356
418
|
})();
|
|
357
419
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
@@ -363,11 +425,11 @@ function ingest(model, source, file, seen, loader) {
|
|
|
363
425
|
const list = v.split(",").filter(Boolean);
|
|
364
426
|
for (const n of list) {
|
|
365
427
|
if (!model.grid[key === "x" ? "X" : "Y"].names.includes(n)) {
|
|
366
|
-
throw new SourceError(ln,
|
|
428
|
+
throw new SourceError(ln, `Undefined grid line name: ${n}`);
|
|
367
429
|
}
|
|
368
430
|
}
|
|
369
431
|
if (list.length === 0)
|
|
370
|
-
throw new SourceError(ln, `${key}:
|
|
432
|
+
throw new SourceError(ln, `${key}: takes grid line names`);
|
|
371
433
|
return list;
|
|
372
434
|
};
|
|
373
435
|
const xNames = names("x");
|
|
@@ -392,16 +454,16 @@ function ingest(model, source, file, seen, loader) {
|
|
|
392
454
|
case "space": {
|
|
393
455
|
const path = rest[0];
|
|
394
456
|
if (!path)
|
|
395
|
-
throw new SourceError(ln, "space
|
|
457
|
+
throw new SourceError(ln, "space requires a path");
|
|
396
458
|
// w: は帯の要素の語 — 字下げを落とした要素が「領域なしの空間」として黙って通るのを防ぐ
|
|
397
459
|
if (rest.some((t) => t === "w:" || t.startsWith("w:"))) {
|
|
398
|
-
throw new SourceError(ln, "
|
|
460
|
+
throw new SourceError(ln, "w: may not be written on space (a space written by width sits indented under band)");
|
|
399
461
|
}
|
|
400
462
|
for (const [p] of expandSpan(model, [path], ln)) {
|
|
401
463
|
const space = parseSpace([p, ...rest.slice(1)], ln, model);
|
|
402
464
|
const prevS = model.spaces.get(space.path);
|
|
403
465
|
if (prevS) {
|
|
404
|
-
throw new SourceError(ln,
|
|
466
|
+
throw new SourceError(ln, `Duplicate space path: ${space.path} (first seen in ${prevS.file ?? "the same file"} at line ${prevS.line})`);
|
|
405
467
|
}
|
|
406
468
|
if (file)
|
|
407
469
|
space.file = file;
|
|
@@ -414,7 +476,7 @@ function ingest(model, source, file, seen, loader) {
|
|
|
414
476
|
const pa = rest[0];
|
|
415
477
|
const pb = rest[1];
|
|
416
478
|
if (!pa || !pb) {
|
|
417
|
-
throw new SourceError(ln, "boundary
|
|
479
|
+
throw new SourceError(ln, "boundary takes the form boundary /pathA /pathB [attributes...]");
|
|
418
480
|
}
|
|
419
481
|
for (const [ea, eb] of expandSpan(model, [pa, pb], ln)) {
|
|
420
482
|
const b = parseBoundary([ea, eb, ...rest.slice(2)], ln);
|
|
@@ -429,12 +491,12 @@ function ingest(model, source, file, seen, loader) {
|
|
|
429
491
|
// 数える集約 — 住戸・部門など。幾何は持たず、パス接頭辞で空間を束ねる
|
|
430
492
|
const zpath = rest[0];
|
|
431
493
|
if (!zpath || !zpath.startsWith("/")) {
|
|
432
|
-
throw new SourceError(ln, "zone
|
|
494
|
+
throw new SourceError(ln, "zone takes the form zone /path [attributes...]");
|
|
433
495
|
}
|
|
434
496
|
for (const [p] of expandSpan(model, [zpath], ln)) {
|
|
435
497
|
const prevZ = model.zones.get(p);
|
|
436
498
|
if (prevZ) {
|
|
437
|
-
throw new SourceError(ln,
|
|
499
|
+
throw new SourceError(ln, `Duplicate zone path: ${p} (first seen in ${prevZ.file ?? "the same file"} at line ${prevZ.line})`);
|
|
438
500
|
}
|
|
439
501
|
model.zones.set(p, {
|
|
440
502
|
path: p,
|
|
@@ -450,13 +512,13 @@ function ingest(model, source, file, seen, loader) {
|
|
|
450
512
|
const leaf = rest[0];
|
|
451
513
|
const span = rest[1];
|
|
452
514
|
if (!leaf || leaf.startsWith("/") || !span) {
|
|
453
|
-
throw new SourceError(ln, "stack
|
|
515
|
+
throw new SourceError(ln, "stack takes the form stack <name> <L?..L?> type:stair|shaft");
|
|
454
516
|
}
|
|
455
517
|
const levels = resolveSpanLevels(model, span, ln);
|
|
456
518
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
457
519
|
const kind = takeString(attrs, "type");
|
|
458
520
|
if (kind !== "stair" && kind !== "shaft" && kind !== "void") {
|
|
459
|
-
throw new SourceError(ln, `stack
|
|
521
|
+
throw new SourceError(ln, `A stack type is stair / shaft / void: ${kind}`);
|
|
460
522
|
}
|
|
461
523
|
for (let i = 0; i + 1 < levels.length; i++) {
|
|
462
524
|
const b = {
|
|
@@ -475,7 +537,7 @@ function ingest(model, source, file, seen, loader) {
|
|
|
475
537
|
break;
|
|
476
538
|
}
|
|
477
539
|
default:
|
|
478
|
-
throw new SourceError(ln,
|
|
540
|
+
throw new SourceError(ln, `Unknown keyword: ${head}`);
|
|
479
541
|
}
|
|
480
542
|
}
|
|
481
543
|
catch (e) {
|
|
@@ -503,11 +565,12 @@ function ingest(model, source, file, seen, loader) {
|
|
|
503
565
|
function parseSpace(rest, ln, model) {
|
|
504
566
|
const path = rest[0];
|
|
505
567
|
if (!path || !path.startsWith("/")) {
|
|
506
|
-
throw new SourceError(ln, "space
|
|
568
|
+
throw new SourceError(ln, "space takes the form space /path type [X?..X? Y?..Y? [+ ...]]");
|
|
507
569
|
}
|
|
508
570
|
const type = rest[1];
|
|
509
571
|
if (!type)
|
|
510
|
-
throw new SourceError(ln, `space ${path}
|
|
572
|
+
throw new SourceError(ln, `space ${path} requires a type (a word from the vocabulary)`);
|
|
573
|
+
guardStructuralType(type, ln);
|
|
511
574
|
// 領域は「+」区切りで複数書ける (L字などの合併)
|
|
512
575
|
const groups = [[]];
|
|
513
576
|
const attrTokens = [];
|
|
@@ -526,7 +589,7 @@ function parseSpace(rest, ln, model) {
|
|
|
526
589
|
// レベルは既定でパス先頭から読む。階を跨ぐくくり (メゾネット等) は level: で明示する
|
|
527
590
|
const explicit = takeString(attrs, "level");
|
|
528
591
|
if (explicit !== undefined && !model.levels[explicit]) {
|
|
529
|
-
throw new SourceError(ln,
|
|
592
|
+
throw new SourceError(ln, `Undeclared level: level:${explicit}`);
|
|
530
593
|
}
|
|
531
594
|
const seg = path.split("/")[1];
|
|
532
595
|
const level = explicit ?? (seg && model.levels[seg] ? seg : undefined);
|
|
@@ -555,22 +618,22 @@ function parseSpace(rest, ln, model) {
|
|
|
555
618
|
function parseBandHead(rest, ln, model) {
|
|
556
619
|
const axis = rest[0];
|
|
557
620
|
if (axis !== "X" && axis !== "Y") {
|
|
558
|
-
throw new SourceError(ln, `band
|
|
621
|
+
throw new SourceError(ln, `A band divides along X or Y: ${axis ?? "(none)"} (it takes the form band X X1..X2 Y1..Y2)`);
|
|
559
622
|
}
|
|
560
623
|
const tail = rest.slice(1);
|
|
561
624
|
const extra = tail.filter((t) => !t.includes(".."));
|
|
562
625
|
if (extra.length > 0) {
|
|
563
|
-
throw new SourceError(ln, `band
|
|
626
|
+
throw new SourceError(ln, `Only the axis and the extent may be written on a band line (attributes go on the member space lines): ${extra.join(" ")}`);
|
|
564
627
|
}
|
|
565
628
|
// 逆順表記は space では同じ矩形の別綴りだが、帯では並びの向きが意味を持つので許さない
|
|
566
629
|
for (const t of tail) {
|
|
567
630
|
const [p, q] = t.split("..");
|
|
568
631
|
if (!p || !q)
|
|
569
|
-
throw new SourceError(ln,
|
|
632
|
+
throw new SourceError(ln, `Cannot read the region: ${t}`);
|
|
570
633
|
const rp = resolveRef(model, p, ln);
|
|
571
634
|
const rq = resolveRef(model, q, ln);
|
|
572
635
|
if (rp.axis === rq.axis && rp.coord > rq.coord) {
|
|
573
|
-
throw new SourceError(ln, `band
|
|
636
|
+
throw new SourceError(ln, `A band range is written in ascending order (members run west to east / south to north): ${t}`);
|
|
574
637
|
}
|
|
575
638
|
}
|
|
576
639
|
const r = parseRegion(tail, ln, model); // 軸の対・幅ゼロ・未定義の通り名は既存の言葉で弾かれる
|
|
@@ -590,38 +653,39 @@ function parseBandHead(rest, ln, model) {
|
|
|
590
653
|
function parseBandMember(rest, ln) {
|
|
591
654
|
const path = rest[0];
|
|
592
655
|
if (!path?.startsWith("/")) {
|
|
593
|
-
throw new SourceError(ln, "band
|
|
656
|
+
throw new SourceError(ln, "A band member takes the form space /path type w:(mm)");
|
|
594
657
|
}
|
|
595
658
|
const type = rest[1];
|
|
596
659
|
// 型の位置に k:v が来たら「型の書き忘れ」— 幅の欠落として誤報しない
|
|
597
660
|
if (!type || type.includes(":")) {
|
|
598
|
-
throw new SourceError(ln, `band
|
|
661
|
+
throw new SourceError(ln, `The band member ${path} requires a type (a word from the vocabulary)`);
|
|
599
662
|
}
|
|
663
|
+
guardStructuralType(type, ln);
|
|
600
664
|
let w;
|
|
601
665
|
const attrTokens = [];
|
|
602
666
|
for (const t of rest.slice(2)) {
|
|
603
667
|
if (t === "+" || t.includes("..")) {
|
|
604
|
-
throw new SourceError(ln, `band
|
|
668
|
+
throw new SourceError(ln, `A region may not be written on a band member (the band and w: give it): ${t}`);
|
|
605
669
|
}
|
|
606
670
|
if (t.startsWith("level:")) {
|
|
607
|
-
throw new SourceError(ln, `band
|
|
671
|
+
throw new SourceError(ln, `level: may not be written on a band member (a band is a run on one level): ${t}`);
|
|
608
672
|
}
|
|
609
673
|
if (t.startsWith("w:")) {
|
|
610
674
|
if (w !== undefined)
|
|
611
|
-
throw new SourceError(ln, "
|
|
675
|
+
throw new SourceError(ln, "Duplicate attribute key: w");
|
|
612
676
|
const v = t.slice(2);
|
|
613
677
|
if (v === "rest")
|
|
614
678
|
w = "rest";
|
|
615
679
|
else if (/^\d+$/.test(v) && Number(v) > 0)
|
|
616
680
|
w = Number(v);
|
|
617
681
|
else
|
|
618
|
-
throw new SourceError(ln, `band
|
|
682
|
+
throw new SourceError(ln, `A band member width is written as a positive integer in mm, or as rest: ${t}`);
|
|
619
683
|
continue;
|
|
620
684
|
}
|
|
621
685
|
attrTokens.push(t);
|
|
622
686
|
}
|
|
623
687
|
if (w === undefined) {
|
|
624
|
-
throw new SourceError(ln, `band
|
|
688
|
+
throw new SourceError(ln, `A band member requires a width, w:(mm) or w:rest: ${path}`);
|
|
625
689
|
}
|
|
626
690
|
return { path, type, w, attrTokens, line: ln };
|
|
627
691
|
}
|
|
@@ -633,7 +697,7 @@ function parseBandMember(rest, ln) {
|
|
|
633
697
|
function spellRef(model, axis, c, ln) {
|
|
634
698
|
const g = model.grid[axis];
|
|
635
699
|
if (!Number.isInteger(c)) {
|
|
636
|
-
throw new SourceError(ln,
|
|
700
|
+
throw new SourceError(ln, `The derived cut position is not an integer in mm: ${c}`);
|
|
637
701
|
}
|
|
638
702
|
let i = 0;
|
|
639
703
|
for (let k = 0; k < g.coords.length; k++)
|
|
@@ -648,7 +712,7 @@ function spellRef(model, axis, c, ln) {
|
|
|
648
712
|
function expandBand(model, band, file) {
|
|
649
713
|
const { axis, lo, hi, members } = band;
|
|
650
714
|
if (members.length === 0) {
|
|
651
|
-
throw new SourceError(band.line, "band
|
|
715
|
+
throw new SourceError(band.line, "band takes one or more indented space lines below it");
|
|
652
716
|
}
|
|
653
717
|
const extent = hi - lo;
|
|
654
718
|
let sum = 0;
|
|
@@ -657,7 +721,7 @@ function expandBand(model, band, file) {
|
|
|
657
721
|
const m = members[k];
|
|
658
722
|
if (m.w === "rest") {
|
|
659
723
|
if (restAt >= 0) {
|
|
660
|
-
throw new SourceError(m.line,
|
|
724
|
+
throw new SourceError(m.line, `Only one member per band absorbs the remainder (w:rest): ${members[restAt].path}, ${m.path}`);
|
|
661
725
|
}
|
|
662
726
|
restAt = k;
|
|
663
727
|
}
|
|
@@ -666,25 +730,25 @@ function expandBand(model, band, file) {
|
|
|
666
730
|
}
|
|
667
731
|
const list = members.map((m) => ` ${m.path} w:${m.w}`).join("\n");
|
|
668
732
|
if (sum > extent) {
|
|
669
|
-
throw new SourceError(band.line,
|
|
733
|
+
throw new SourceError(band.line, `The dimensions sum to ${sum}mm against a band width of ${extent}mm, ${sum - extent}mm over\n${list}`);
|
|
670
734
|
}
|
|
671
735
|
const widths = members.map((m) => (m.w === "rest" ? 0 : m.w));
|
|
672
736
|
if (restAt >= 0) {
|
|
673
737
|
if (sum === extent) {
|
|
674
|
-
throw new SourceError(members[restAt].line,
|
|
738
|
+
throw new SourceError(members[restAt].line, `The other dimensions use up the band width of ${extent}mm, leaving zero for ${members[restAt].path} (w:rest)`);
|
|
675
739
|
}
|
|
676
740
|
widths[restAt] = extent - sum;
|
|
677
741
|
}
|
|
678
742
|
else if (sum < extent) {
|
|
679
|
-
throw new SourceError(band.line,
|
|
680
|
-
`(
|
|
743
|
+
throw new SourceError(band.line, `The dimensions sum to ${sum}mm against a band width of ${extent}mm, ${extent - sum}mm short ` +
|
|
744
|
+
`(fix a dimension, or make one of them w:rest)\n${list}`);
|
|
681
745
|
}
|
|
682
746
|
// レベルスパンは全要素をまとめて一度だけ展開する (帯の中で揃っていることを先に確かめる)
|
|
683
747
|
const iterations = expandSpan(model, members.map((m) => m.path), band.line);
|
|
684
748
|
for (const it of iterations) {
|
|
685
749
|
const lv = new Set(it.map((p) => p.split("/")[1]));
|
|
686
750
|
if (lv.size > 1) {
|
|
687
|
-
throw new SourceError(band.line,
|
|
751
|
+
throw new SourceError(band.line, `Band members expand onto the same level: ${it.map((p) => `${p} → ${p.split("/")[1]}`).join(", ")}`);
|
|
688
752
|
}
|
|
689
753
|
}
|
|
690
754
|
for (const it of iterations) {
|
|
@@ -704,7 +768,7 @@ function expandBand(model, band, file) {
|
|
|
704
768
|
const space = parseSpace([it[k], m.type, xTok, yTok, ...m.attrTokens], m.line, model);
|
|
705
769
|
const prev = model.spaces.get(space.path);
|
|
706
770
|
if (prev) {
|
|
707
|
-
throw new SourceError(m.line,
|
|
771
|
+
throw new SourceError(m.line, `Duplicate space path: ${space.path} (first seen in ${prev.file ?? "the same file"} at line ${prev.line})`);
|
|
708
772
|
}
|
|
709
773
|
if (file)
|
|
710
774
|
space.file = file;
|
|
@@ -715,7 +779,7 @@ function expandBand(model, band, file) {
|
|
|
715
779
|
/** 領域指定 (X?..X? Y?..Y?) をグリッド参照とmm矩形に解決する */
|
|
716
780
|
function parseRegion(regionTokens, ln, model) {
|
|
717
781
|
if (regionTokens.length !== 2) {
|
|
718
|
-
throw new SourceError(ln, "
|
|
782
|
+
throw new SourceError(ln, "A region is given as two ranges, X?..X? and Y?..Y?");
|
|
719
783
|
}
|
|
720
784
|
let xr;
|
|
721
785
|
let yr;
|
|
@@ -724,11 +788,11 @@ function parseRegion(regionTokens, ln, model) {
|
|
|
724
788
|
for (const t of regionTokens) {
|
|
725
789
|
const [p, q] = t.split("..");
|
|
726
790
|
if (!p || !q)
|
|
727
|
-
throw new SourceError(ln,
|
|
791
|
+
throw new SourceError(ln, `Cannot read the region: ${t}`);
|
|
728
792
|
const rp = resolveRef(model, p, ln);
|
|
729
793
|
const rq = resolveRef(model, q, ln);
|
|
730
794
|
if (rp.axis !== rq.axis) {
|
|
731
|
-
throw new SourceError(ln,
|
|
795
|
+
throw new SourceError(ln, `Both ends of a range are grid lines on the same axis: ${t}`);
|
|
732
796
|
}
|
|
733
797
|
// 逆順表記 (X2..X1) は同じ矩形の別綴り — 座標昇順に正規化して保存する (正準JSON・diffが揃う)
|
|
734
798
|
const [lo, hi] = rp.coord <= rq.coord ? [[rp.coord, p], [rq.coord, q]]
|
|
@@ -743,10 +807,10 @@ function parseRegion(regionTokens, ln, model) {
|
|
|
743
807
|
}
|
|
744
808
|
}
|
|
745
809
|
if (!xr || !yr || !xg || !yg) {
|
|
746
|
-
throw new SourceError(ln, "
|
|
810
|
+
throw new SourceError(ln, "A region uses one X range and one Y range");
|
|
747
811
|
}
|
|
748
812
|
if (xr[0] === xr[1] || yr[0] === yr[1])
|
|
749
|
-
throw new SourceError(ln, "
|
|
813
|
+
throw new SourceError(ln, "The region has zero width");
|
|
750
814
|
return {
|
|
751
815
|
grid: { xa: xg[0], xb: xg[1], ya: yg[0], yb: yg[1] },
|
|
752
816
|
rect: {
|
|
@@ -764,13 +828,13 @@ function parseRegion(regionTokens, ln, model) {
|
|
|
764
828
|
*/
|
|
765
829
|
function parseDrawnLine(rest, ln, model) {
|
|
766
830
|
if (rest.length !== 2) {
|
|
767
|
-
throw new SourceError(ln, "line
|
|
831
|
+
throw new SourceError(ln, "line takes the form line <start> <end> (for example line X3,Y1 X4,Y3)");
|
|
768
832
|
}
|
|
769
833
|
const [aRef, bRef] = rest;
|
|
770
834
|
const a = resolvePoint(model, aRef, ln);
|
|
771
835
|
const b = resolvePoint(model, bRef, ln);
|
|
772
836
|
if (Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5) {
|
|
773
|
-
throw new SourceError(ln, `line
|
|
837
|
+
throw new SourceError(ln, `Both ends of the line are the same point: ${aRef}`);
|
|
774
838
|
}
|
|
775
839
|
return { aRef, bRef, a, b, line: ln };
|
|
776
840
|
}
|
|
@@ -778,12 +842,12 @@ function parseDrawnLine(rest, ln, model) {
|
|
|
778
842
|
function resolvePoint(model, token, ln) {
|
|
779
843
|
const parts = token.split(",");
|
|
780
844
|
if (parts.length !== 2) {
|
|
781
|
-
throw new SourceError(ln,
|
|
845
|
+
throw new SourceError(ln, `A point takes the form <X grid line>,<Y grid line>: ${token}`);
|
|
782
846
|
}
|
|
783
847
|
const p = resolveRef(model, parts[0], ln);
|
|
784
848
|
const q = resolveRef(model, parts[1], ln);
|
|
785
849
|
if (p.axis !== "X" || q.axis !== "Y") {
|
|
786
|
-
throw new SourceError(ln,
|
|
850
|
+
throw new SourceError(ln, `A point is written X grid line first, then Y: ${token}`);
|
|
787
851
|
}
|
|
788
852
|
return { x: p.coord, y: q.coord };
|
|
789
853
|
}
|
|
@@ -799,7 +863,7 @@ function parseSeg(rest, ln, model) {
|
|
|
799
863
|
const attrs = parseAttrs(rest, ln);
|
|
800
864
|
const w = takeNumber(attrs, "w", ln);
|
|
801
865
|
if (w === undefined || w <= 0) {
|
|
802
|
-
throw new SourceError(ln, "seg
|
|
866
|
+
throw new SourceError(ln, "seg requires a width w:(mm)");
|
|
803
867
|
}
|
|
804
868
|
const at = parseAt(attrs, ln, model);
|
|
805
869
|
const edge = takeEdge(attrs, ln);
|
|
@@ -816,7 +880,7 @@ function parseAt(attrs, ln, model) {
|
|
|
816
880
|
delete attrs["at"];
|
|
817
881
|
if (typeof v === "number") {
|
|
818
882
|
if (v < 0 || v > 1) {
|
|
819
|
-
throw new SourceError(ln, "at
|
|
883
|
+
throw new SourceError(ln, "at is given as a ratio in 0..1, or as a grid reference (at:X2+450)");
|
|
820
884
|
}
|
|
821
885
|
return { at: v };
|
|
822
886
|
}
|
|
@@ -827,14 +891,14 @@ function parseAt(attrs, ln, model) {
|
|
|
827
891
|
function resolveSpanLevels(model, token, ln) {
|
|
828
892
|
const m = /^([A-Za-z]+\d+)\.\.([A-Za-z]+\d+)$/.exec(token);
|
|
829
893
|
if (!m)
|
|
830
|
-
throw new SourceError(ln,
|
|
894
|
+
throw new SourceError(ln, `Cannot read the level range: ${token}`);
|
|
831
895
|
const from = model.levels[m[1]];
|
|
832
896
|
const to = model.levels[m[2]];
|
|
833
897
|
if (!from || !to) {
|
|
834
|
-
throw new SourceError(ln,
|
|
898
|
+
throw new SourceError(ln, `The range includes an undeclared level (declare level first): ${token}`);
|
|
835
899
|
}
|
|
836
900
|
if (from.z >= to.z)
|
|
837
|
-
throw new SourceError(ln,
|
|
901
|
+
throw new SourceError(ln, `The range runs backwards: ${token}`);
|
|
838
902
|
return Object.values(model.levels)
|
|
839
903
|
.filter((l) => l.z >= from.z && l.z <= to.z)
|
|
840
904
|
.sort((a, b) => a.z - b.z)
|
|
@@ -854,7 +918,7 @@ function expandSpan(model, paths, ln) {
|
|
|
854
918
|
if (spans.size === 0)
|
|
855
919
|
return [paths];
|
|
856
920
|
if (spans.size > 1) {
|
|
857
|
-
throw new SourceError(ln,
|
|
921
|
+
throw new SourceError(ln, `Level ranges on one line must agree: ${[...spans].join(", ")}`);
|
|
858
922
|
}
|
|
859
923
|
const span = [...spans][0];
|
|
860
924
|
const levels = resolveSpanLevels(model, span, ln);
|
|
@@ -869,7 +933,7 @@ function expandSpan(model, paths, ln) {
|
|
|
869
933
|
function resolveRef(model, token, ln) {
|
|
870
934
|
const m = /^([XY]\d+)([+-]\d+)?$/.exec(token);
|
|
871
935
|
if (!m)
|
|
872
|
-
throw new SourceError(ln,
|
|
936
|
+
throw new SourceError(ln, `Undefined grid line name: ${token}`);
|
|
873
937
|
const name = m[1];
|
|
874
938
|
const offset = m[2] ? Number(m[2]) : 0;
|
|
875
939
|
for (const axis of ["X", "Y"]) {
|
|
@@ -878,23 +942,23 @@ function resolveRef(model, token, ln) {
|
|
|
878
942
|
if (i >= 0)
|
|
879
943
|
return { axis, coord: g.coords[i] + offset };
|
|
880
944
|
}
|
|
881
|
-
throw new SourceError(ln,
|
|
945
|
+
throw new SourceError(ln, `Undefined grid line name: ${token}`);
|
|
882
946
|
}
|
|
883
947
|
function parseBoundary(rest, ln) {
|
|
884
948
|
const a = rest[0];
|
|
885
949
|
const b = rest[1];
|
|
886
950
|
if (!a?.startsWith("/") || !b?.startsWith("/")) {
|
|
887
|
-
throw new SourceError(ln, "boundary
|
|
951
|
+
throw new SourceError(ln, "boundary takes the form boundary /pathA /pathB [attributes...]");
|
|
888
952
|
}
|
|
889
953
|
const attrs = parseAttrs(rest.slice(2), ln);
|
|
890
954
|
const t = takeNumber(attrs, "t", ln);
|
|
891
955
|
const kindRaw = takeString(attrs, "type") ?? "wall";
|
|
892
|
-
if (!
|
|
893
|
-
throw new SourceError(ln, `boundary
|
|
956
|
+
if (!BOUNDARY_KINDS.has(kindRaw)) {
|
|
957
|
+
throw new SourceError(ln, `A boundary type is ${[...BOUNDARY_KINDS].join(" / ")}: ${kindRaw}`);
|
|
894
958
|
}
|
|
895
959
|
const air = takeNumber(attrs, "air", ln);
|
|
896
960
|
if (air !== undefined && air !== 0 && air !== 1) {
|
|
897
|
-
throw new SourceError(ln, "air
|
|
961
|
+
throw new SourceError(ln, "air is given as 0 / 1 (1 = it does not block air or light: a railing, a fence)");
|
|
898
962
|
}
|
|
899
963
|
const edge = takeEdge(attrs, ln);
|
|
900
964
|
return {
|
|
@@ -923,27 +987,27 @@ function parseOpening(kind, rest, ln, model) {
|
|
|
923
987
|
if (ref) {
|
|
924
988
|
const asset = model.assets.get(ref);
|
|
925
989
|
if (!asset)
|
|
926
|
-
throw new SourceError(ln,
|
|
990
|
+
throw new SourceError(ln, `Undefined opening asset: ${ref}`);
|
|
927
991
|
if (asset.kind !== kind) {
|
|
928
|
-
throw new SourceError(ln,
|
|
992
|
+
throw new SourceError(ln, `The asset ${ref} is a ${asset.kind} (it cannot be used as a ${kind})`);
|
|
929
993
|
}
|
|
930
994
|
Object.assign(attrs, asset.attrs);
|
|
931
995
|
}
|
|
932
996
|
Object.assign(attrs, parseAttrs(tokens, ln));
|
|
933
997
|
const w = takeNumber(attrs, "w", ln);
|
|
934
998
|
if (w === undefined || w <= 0) {
|
|
935
|
-
throw new SourceError(ln, `${kind}
|
|
999
|
+
throw new SourceError(ln, `${kind} requires a width w:(mm) (the asset may supply it)`);
|
|
936
1000
|
}
|
|
937
1001
|
const h = takeNumber(attrs, "h", ln);
|
|
938
1002
|
const at = parseAt(attrs, ln, model);
|
|
939
1003
|
const edge = takeEdge(attrs, ln);
|
|
940
1004
|
const hingeRaw = takeString(attrs, "hinge");
|
|
941
1005
|
if (hingeRaw !== undefined && !EDGES.has(hingeRaw)) {
|
|
942
|
-
throw new SourceError(ln, `hinge
|
|
1006
|
+
throw new SourceError(ln, `hinge is given as N/E/S/W: ${hingeRaw}`);
|
|
943
1007
|
}
|
|
944
1008
|
const swingRaw = takeString(attrs, "swing");
|
|
945
1009
|
if (swingRaw !== undefined && swingRaw !== "a" && swingRaw !== "b") {
|
|
946
|
-
throw new SourceError(ln, `swing
|
|
1010
|
+
throw new SourceError(ln, `swing is a / b, the side of the boundary it opens toward: ${swingRaw}`);
|
|
947
1011
|
}
|
|
948
1012
|
return {
|
|
949
1013
|
kind,
|
|
@@ -980,24 +1044,372 @@ export function tokenize(line, ln) {
|
|
|
980
1044
|
cur += ch;
|
|
981
1045
|
}
|
|
982
1046
|
if (inQuote)
|
|
983
|
-
throw new SourceError(ln, "
|
|
1047
|
+
throw new SourceError(ln, "Unclosed quote");
|
|
984
1048
|
if (cur)
|
|
985
1049
|
tokens.push(cur);
|
|
986
1050
|
return tokens;
|
|
987
1051
|
}
|
|
1052
|
+
/**
|
|
1053
|
+
* 型として構造的に解釈される二語 (spec/vocabulary.md 規則1)。
|
|
1054
|
+
* `exterior` は「外部」、`void` は「床面積に算入しない」— どちらも構成の事実である。
|
|
1055
|
+
*/
|
|
1056
|
+
const STRUCTURAL_TYPES = ["exterior", "void"];
|
|
1057
|
+
/** 編集距離が1以内か (挿入・削除・置換をそれぞれ1と数える) */
|
|
1058
|
+
function nearBy1(a, b) {
|
|
1059
|
+
if (a === b)
|
|
1060
|
+
return false;
|
|
1061
|
+
if (Math.abs(a.length - b.length) > 1)
|
|
1062
|
+
return false;
|
|
1063
|
+
let i = 0;
|
|
1064
|
+
let j = 0;
|
|
1065
|
+
let diff = 0;
|
|
1066
|
+
while (i < a.length && j < b.length) {
|
|
1067
|
+
if (a[i] === b[j]) {
|
|
1068
|
+
i++;
|
|
1069
|
+
j++;
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
if (++diff > 1)
|
|
1073
|
+
return false;
|
|
1074
|
+
if (a.length > b.length)
|
|
1075
|
+
i++;
|
|
1076
|
+
else if (a.length < b.length)
|
|
1077
|
+
j++;
|
|
1078
|
+
else {
|
|
1079
|
+
i++;
|
|
1080
|
+
j++;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return diff + (a.length - i) + (b.length - j) <= 1;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* 型の綴りを守る (ADR-0033)。**型の語彙は開いている** — `room` も `ldk` も `厨房` も自由である。
|
|
1087
|
+
* だが構造として解釈される二語だけは、一字違いが黙って意味を変える:
|
|
1088
|
+
* `exteriorr` と書けば外部でなくなり、延床が倍になる。check は緑のままだった。
|
|
1089
|
+
*
|
|
1090
|
+
* 開かれた語彙を殺さずにこれを塞ぐ唯一の形が、**二語の近傍だけを拒むこと**である。
|
|
1091
|
+
* 遠い語 (room / yard / ldk) は何も言われない。
|
|
1092
|
+
*/
|
|
1093
|
+
function guardStructuralType(type, ln) {
|
|
1094
|
+
for (const w of STRUCTURAL_TYPES) {
|
|
1095
|
+
if (nearBy1(type.toLowerCase(), w)) {
|
|
1096
|
+
throw new SourceError(ln, `The type ${type} looks like a misspelling of ${w} (${w} is read structurally — if a different word was meant, spell it further away)`);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
/** その要素を定義した層の添字 (出所が無ければ 0 = 最も弱い) */
|
|
1101
|
+
function layerOf(model, file) {
|
|
1102
|
+
if (file === undefined)
|
|
1103
|
+
return 0;
|
|
1104
|
+
const i = model.layers.indexOf(file);
|
|
1105
|
+
return i < 0 ? 0 : i;
|
|
1106
|
+
}
|
|
1107
|
+
/** 出所の鍵 — `<種別>:<対象>:<属性キー>` */
|
|
1108
|
+
function srcKey(kind, subject, key) {
|
|
1109
|
+
return `${kind}:${subject}:${key}`;
|
|
1110
|
+
}
|
|
1111
|
+
/** その対象の、出所を記録するときの名前 */
|
|
1112
|
+
function overSubject(t) {
|
|
1113
|
+
switch (t.kind) {
|
|
1114
|
+
case "space":
|
|
1115
|
+
return t.space.path;
|
|
1116
|
+
case "zone":
|
|
1117
|
+
return t.zone.path;
|
|
1118
|
+
case "level":
|
|
1119
|
+
return t.level.name;
|
|
1120
|
+
case "asset":
|
|
1121
|
+
return t.asset.name;
|
|
1122
|
+
case "boundary":
|
|
1123
|
+
return t.boundaries.map((b) => `${b.a}|${b.b}`).join(",");
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* 属性を一つ、強度の規則に従って書き込む (合成の規則2 — 単一の値は最も強い層の意見が勝つ)。
|
|
1128
|
+
*
|
|
1129
|
+
* **走査の順ではなく強度で決める。**entry は添字0で最も弱いが、その行が
|
|
1130
|
+
* import より後に書かれていれば走査としては最後に来る。順序で決めると、
|
|
1131
|
+
* import 行を上下に動かしただけで結果が変わってしまう。
|
|
1132
|
+
*
|
|
1133
|
+
* 同じ層が同じ属性に二度意見を持つのは矛盾なのでエラーにする (`>=` ではなく `>`)。
|
|
1134
|
+
*/
|
|
1135
|
+
function applyAttr(model, kind, subject, into, key, value, layer, ln, defLayer = 0) {
|
|
1136
|
+
const k = srcKey(kind, subject, key);
|
|
1137
|
+
// 出所が記録されていなければ、値は**定義した層**が与えたものである。
|
|
1138
|
+
// entry (添字0) が import より後ろに over を書いても、定義した層の方が強ければ通らない —
|
|
1139
|
+
// 強度は走査の順ではなく宣言された順序で決まる (規則1)
|
|
1140
|
+
const prev = model.attrSrc.get(k) ?? (into[key] !== undefined ? defLayer : undefined);
|
|
1141
|
+
if (prev !== undefined) {
|
|
1142
|
+
if (prev > layer)
|
|
1143
|
+
return; // 強い層が既に決めている — 弱い層の意見は通らない
|
|
1144
|
+
if (prev === layer) {
|
|
1145
|
+
throw new SourceError(ln, `One layer holds two opinions about ${key} on ${subject} (which one wins is undetermined)`);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
into[key] = value;
|
|
1149
|
+
model.attrSrc.set(k, layer);
|
|
1150
|
+
}
|
|
1151
|
+
/** 定義された属性の出所を、その層のものとして記録する */
|
|
1152
|
+
function recordAttrs(model, kind, subject, attrs, layer) {
|
|
1153
|
+
for (const key of Object.keys(attrs))
|
|
1154
|
+
model.attrSrc.set(srcKey(kind, subject, key), layer);
|
|
1155
|
+
}
|
|
1156
|
+
/** 集合の要素を名で引く (合成の規則3 — 同一性は「含む対象 + その中で一意な名」) */
|
|
1157
|
+
function findNamed(list, name) {
|
|
1158
|
+
return list.filter((x) => String(x.attrs["name"] ?? "") === name);
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* `over` の対象を解く。**書き方から種別が決まる** — 先頭のトークンが指す先で分かれる。
|
|
1162
|
+
*
|
|
1163
|
+
* over /L5/A/ldk h:2600 空間 (パス1つ)
|
|
1164
|
+
* over /site area:1100.20 ゾーン (パス1つ・空間が無ければゾーン)
|
|
1165
|
+
* over /L5/A/hall /L5/corridor 境界 (パス2つ)
|
|
1166
|
+
* over level L3 h:2600 レベル
|
|
1167
|
+
* over asset SD1 w:900 アセット
|
|
1168
|
+
*
|
|
1169
|
+
* 対象が存在しなければエラーである。**上書きは定義ではない** — 存在しないものに
|
|
1170
|
+
* 意見だけを足すのは、たいてい綴り違いか、層の順序の思い違いである。
|
|
1171
|
+
*/
|
|
1172
|
+
function resolveOverTarget(model, rest, ln) {
|
|
1173
|
+
const head = rest[0];
|
|
1174
|
+
if (head === "level") {
|
|
1175
|
+
const name = rest[1];
|
|
1176
|
+
const lv = name ? model.levels[name] : undefined;
|
|
1177
|
+
if (!lv)
|
|
1178
|
+
throw new SourceError(ln, `No such level for over: ${name ?? "(no name)"}`);
|
|
1179
|
+
return { kind: "level", level: lv };
|
|
1180
|
+
}
|
|
1181
|
+
if (head === "asset") {
|
|
1182
|
+
const name = rest[1];
|
|
1183
|
+
const a = name ? model.assets.get(name) : undefined;
|
|
1184
|
+
if (!a)
|
|
1185
|
+
throw new SourceError(ln, `No such asset for over: ${name ?? "(no name)"}`);
|
|
1186
|
+
return { kind: "asset", asset: a };
|
|
1187
|
+
}
|
|
1188
|
+
const paths = rest.filter((t) => t.startsWith("/"));
|
|
1189
|
+
if (paths.length === 0) {
|
|
1190
|
+
throw new SourceError(ln, "over takes the form over /path … / over /pathA /pathB … / over level <name> … / over asset <name> …");
|
|
1191
|
+
}
|
|
1192
|
+
if (paths.length === 1) {
|
|
1193
|
+
const path = paths[0];
|
|
1194
|
+
const sp = model.spaces.get(path);
|
|
1195
|
+
if (sp)
|
|
1196
|
+
return { kind: "space", space: sp };
|
|
1197
|
+
const zn = model.zones.get(path);
|
|
1198
|
+
if (zn)
|
|
1199
|
+
return { kind: "zone", zone: zn };
|
|
1200
|
+
throw new SourceError(ln, `No such target for over: ${path} (place it after the layer that defines it)`);
|
|
1201
|
+
}
|
|
1202
|
+
if (paths.length > 2) {
|
|
1203
|
+
throw new SourceError(ln, `Too many paths on the over target: ${paths.join(" ")}`);
|
|
1204
|
+
}
|
|
1205
|
+
const [a, b] = paths;
|
|
1206
|
+
const hit = model.boundaries.filter((x) => (x.a === a && x.b === b) || (x.a === b && x.b === a));
|
|
1207
|
+
if (hit.length === 0) {
|
|
1208
|
+
throw new SourceError(ln, `No such boundary for over: ${a} | ${b}`);
|
|
1209
|
+
}
|
|
1210
|
+
return { kind: "boundary", boundaries: hit };
|
|
1211
|
+
}
|
|
1212
|
+
/** レベルの上書き — typed field なので属性の器を持たない。台帳の四語だけを受ける */
|
|
1213
|
+
function applyLevelAttr(model, lv, key, v, layer, ln) {
|
|
1214
|
+
const k = srcKey("level", lv.name, key);
|
|
1215
|
+
const prev = model.attrSrc.get(k) ?? layerOf(model, lv.file);
|
|
1216
|
+
if (prev > layer)
|
|
1217
|
+
return;
|
|
1218
|
+
if (prev === layer) {
|
|
1219
|
+
throw new SourceError(ln, `One layer holds two opinions about ${key} on level ${lv.name}`);
|
|
1220
|
+
}
|
|
1221
|
+
if (key === "h" || key === "slab") {
|
|
1222
|
+
if (typeof v !== "number" || !(v > 0)) {
|
|
1223
|
+
throw new SourceError(ln, `A level ${key} is written as a positive number: ${key}:${v}`);
|
|
1224
|
+
}
|
|
1225
|
+
lv[key] = v;
|
|
1226
|
+
}
|
|
1227
|
+
else if (key === "underground") {
|
|
1228
|
+
if (v !== 0 && v !== 1)
|
|
1229
|
+
throw new SourceError(ln, "underground is given as 0 / 1");
|
|
1230
|
+
lv.underground = v === 1;
|
|
1231
|
+
}
|
|
1232
|
+
else {
|
|
1233
|
+
throw new SourceError(ln, `Only h / slab / underground may be overridden on a level: ${key}`);
|
|
1234
|
+
}
|
|
1235
|
+
model.attrSrc.set(k, layer);
|
|
1236
|
+
}
|
|
1237
|
+
/** 境界の上書き — typed field (type/t/air/edge) と自由属性の両方を受ける */
|
|
1238
|
+
function applyBoundaryAttr(model, b, key, v, layer, ln) {
|
|
1239
|
+
const subject = `${b.a}|${b.b}`;
|
|
1240
|
+
const k = srcKey("boundary", subject, key);
|
|
1241
|
+
const prev = model.attrSrc.get(k) ?? layerOf(model, b.file);
|
|
1242
|
+
if (prev > layer)
|
|
1243
|
+
return;
|
|
1244
|
+
if (prev === layer) {
|
|
1245
|
+
throw new SourceError(ln, `One layer holds two opinions about ${key} on boundary ${subject}`);
|
|
1246
|
+
}
|
|
1247
|
+
if (key === "type") {
|
|
1248
|
+
const kind = String(v);
|
|
1249
|
+
if (!BOUNDARY_KINDS.has(kind)) {
|
|
1250
|
+
throw new SourceError(ln, `A boundary type is ${[...BOUNDARY_KINDS].join(" / ")}: ${kind}`);
|
|
1251
|
+
}
|
|
1252
|
+
b.kind = kind;
|
|
1253
|
+
}
|
|
1254
|
+
else if (key === "t") {
|
|
1255
|
+
if (typeof v !== "number" || !(v > 0))
|
|
1256
|
+
throw new SourceError(ln, `t is written as a positive number: t:${v}`);
|
|
1257
|
+
b.t = v;
|
|
1258
|
+
}
|
|
1259
|
+
else if (key === "air") {
|
|
1260
|
+
b.air = v === 1 ? true : undefined;
|
|
1261
|
+
}
|
|
1262
|
+
else if (key === "edge") {
|
|
1263
|
+
if (!EDGES.has(String(v)))
|
|
1264
|
+
throw new SourceError(ln, `edge is given as N/E/S/W: ${v}`);
|
|
1265
|
+
b.edge = String(v);
|
|
1266
|
+
}
|
|
1267
|
+
else {
|
|
1268
|
+
b.attrs[key] = v;
|
|
1269
|
+
}
|
|
1270
|
+
model.attrSrc.set(k, layer);
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* 集合の編集 (合成の規則3 — 追加 / 削除 / 置換)。**暗黙のマージをしない。**
|
|
1274
|
+
*
|
|
1275
|
+
* + door SD1 w:900 at:X4 name:D9 追加
|
|
1276
|
+
* - door D9 削除 (名で指す)
|
|
1277
|
+
* = door D9 w:1200 置換 (名で指し、書いた属性だけを差し替える)
|
|
1278
|
+
*
|
|
1279
|
+
* 同一性は「含む対象 + その中で一意な名」である (spec/scope.md §5)。
|
|
1280
|
+
* 名を持たない要素は編集の対象にできない — 指す言葉が無いからである。
|
|
1281
|
+
*/
|
|
1282
|
+
function applySetEdit(model, target, op, rest, ln, layer) {
|
|
1283
|
+
const what = rest[0];
|
|
1284
|
+
if (!what)
|
|
1285
|
+
throw new SourceError(ln, `${op} takes door / window / seg / area after it`);
|
|
1286
|
+
const args = rest.slice(1);
|
|
1287
|
+
if (target.kind === "space") {
|
|
1288
|
+
if (what !== "area") {
|
|
1289
|
+
throw new SourceError(ln, `over on a space edits area: ${what}`);
|
|
1290
|
+
}
|
|
1291
|
+
editList(model, target.space.areas, op, args, ln, () => parseArea(args, ln, model), "area");
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (target.kind !== "boundary") {
|
|
1295
|
+
throw new SourceError(ln, `over on ${target.kind} has no set edits`);
|
|
1296
|
+
}
|
|
1297
|
+
for (const b of target.boundaries) {
|
|
1298
|
+
if (what === "door" || what === "window") {
|
|
1299
|
+
editList(model, b.openings, op, args, ln, () => parseOpening(what, args, ln, model), what);
|
|
1300
|
+
}
|
|
1301
|
+
else if (what === "seg") {
|
|
1302
|
+
editList(model, b.segs, op, args, ln, () => parseSeg(args, ln, model), "seg");
|
|
1303
|
+
}
|
|
1304
|
+
else {
|
|
1305
|
+
throw new SourceError(ln, `over on a boundary edits door / window / seg: ${what}`);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
/** 一つの集合に対する追加・削除・置換 */
|
|
1310
|
+
function editList(model, list, op, args, ln, make, what) {
|
|
1311
|
+
if (op === "+") {
|
|
1312
|
+
const made = make();
|
|
1313
|
+
if (String(made.attrs["name"] ?? "") === "") {
|
|
1314
|
+
throw new SourceError(ln, `A ${what} added with + requires name: (it is the name later statements point to)`);
|
|
1315
|
+
}
|
|
1316
|
+
if (findNamed(list, String(made.attrs["name"])).length > 0) {
|
|
1317
|
+
throw new SourceError(ln, `Duplicate ${what} name: ${made.attrs["name"]}`);
|
|
1318
|
+
}
|
|
1319
|
+
list.push(made);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
const name = args[0];
|
|
1323
|
+
if (!name || name.includes(":")) {
|
|
1324
|
+
throw new SourceError(ln, `${op} ${what} takes the name it points to (${op} ${what} D1)`);
|
|
1325
|
+
}
|
|
1326
|
+
const hit = findNamed(list, name);
|
|
1327
|
+
if (hit.length === 0)
|
|
1328
|
+
throw new SourceError(ln, `No such ${what}: ${name}`);
|
|
1329
|
+
if (hit.length > 1)
|
|
1330
|
+
throw new SourceError(ln, `The ${what} name ${name} is not unique`);
|
|
1331
|
+
const idx = list.indexOf(hit[0]);
|
|
1332
|
+
if (op === "-") {
|
|
1333
|
+
list.splice(idx, 1);
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
// = は書いた属性だけを差し替える (全置換ではない — 名は残る)
|
|
1337
|
+
const patch = parseAttrs(args.slice(1), ln);
|
|
1338
|
+
Object.assign(list[idx].attrs, patch);
|
|
1339
|
+
applyTypedPatch(list[idx], patch, ln);
|
|
1340
|
+
}
|
|
1341
|
+
/** 置換で typed field (w/h/at) に触れたぶんを反映する */
|
|
1342
|
+
function applyTypedPatch(item, patch, ln) {
|
|
1343
|
+
for (const key of ["w", "h"]) {
|
|
1344
|
+
const v = patch[key];
|
|
1345
|
+
if (v === undefined)
|
|
1346
|
+
continue;
|
|
1347
|
+
if (typeof v !== "number" || !(v > 0)) {
|
|
1348
|
+
throw new SourceError(ln, `${key} is written as a positive number: ${key}:${v}`);
|
|
1349
|
+
}
|
|
1350
|
+
item[key] = v;
|
|
1351
|
+
delete item.attrs[key];
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* 削除 (合成の規則3)。**消えるのは、消すと書いたものだけである。**
|
|
1356
|
+
*
|
|
1357
|
+
* drop /L5/A/store 空間 (その空間に繋がる境界も一緒に消える)
|
|
1358
|
+
* drop /L5/a /L5/b 境界
|
|
1359
|
+
* drop column <名> 柱の宣言
|
|
1360
|
+
*/
|
|
1361
|
+
function applyDrop(model, rest, ln) {
|
|
1362
|
+
if (rest[0] === "column") {
|
|
1363
|
+
const name = rest[1];
|
|
1364
|
+
if (!name)
|
|
1365
|
+
throw new SourceError(ln, "drop column takes the name of a column");
|
|
1366
|
+
const hit = findNamed(model.columns, name);
|
|
1367
|
+
if (hit.length === 0)
|
|
1368
|
+
throw new SourceError(ln, `No such column: ${name}`);
|
|
1369
|
+
// **消えるのは、消すと書いたものだけである。**名が二本の柱を指しているなら
|
|
1370
|
+
// どちらを消すのかは書かれていない — 黙って両方消さずに拒む (ADR-0039)。
|
|
1371
|
+
// 開口・seg の集合編集 (editList) と同じ規律である
|
|
1372
|
+
if (hit.length > 1)
|
|
1373
|
+
throw new SourceError(ln, `The column name ${name} is not unique`);
|
|
1374
|
+
model.columns = model.columns.filter((c) => c !== hit[0]);
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
const paths = rest.filter((t) => t.startsWith("/"));
|
|
1378
|
+
if (paths.length === 1) {
|
|
1379
|
+
const path = paths[0];
|
|
1380
|
+
if (model.spaces.delete(path)) {
|
|
1381
|
+
// 空間が消えれば、その空間を端に持つ関係も消える — 関係は空間の間にしか無い
|
|
1382
|
+
model.boundaries = model.boundaries.filter((b) => b.a !== path && b.b !== path);
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
if (model.zones.delete(path))
|
|
1386
|
+
return;
|
|
1387
|
+
throw new SourceError(ln, `No such target for drop: ${path}`);
|
|
1388
|
+
}
|
|
1389
|
+
if (paths.length === 2) {
|
|
1390
|
+
const [a, b] = paths;
|
|
1391
|
+
const before = model.boundaries.length;
|
|
1392
|
+
model.boundaries = model.boundaries.filter((x) => !((x.a === a && x.b === b) || (x.a === b && x.b === a)));
|
|
1393
|
+
if (model.boundaries.length === before) {
|
|
1394
|
+
throw new SourceError(ln, `No such boundary for drop: ${a} | ${b}`);
|
|
1395
|
+
}
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
throw new SourceError(ln, "drop takes the form drop /path / drop /pathA /pathB / drop column <name>");
|
|
1399
|
+
}
|
|
988
1400
|
function parseAttrs(tokens, ln) {
|
|
989
1401
|
const attrs = {};
|
|
990
1402
|
for (const t of tokens) {
|
|
991
1403
|
const idx = t.indexOf(":");
|
|
992
1404
|
if (idx <= 0)
|
|
993
|
-
throw new SourceError(ln,
|
|
1405
|
+
throw new SourceError(ln, `An attribute is written key:value: ${t}`);
|
|
994
1406
|
const key = t.slice(0, idx);
|
|
995
1407
|
const rawVal = t.slice(idx + 1);
|
|
996
1408
|
if (rawVal === "")
|
|
997
|
-
throw new SourceError(ln,
|
|
1409
|
+
throw new SourceError(ln, `The attribute ${key} has no value`);
|
|
998
1410
|
if (attrs[key] !== undefined) {
|
|
999
1411
|
// 後勝ちの黙認はtypoとマージ事故を隠す — 同一行内の重複はエラー (ADR-0013)
|
|
1000
|
-
throw new SourceError(ln,
|
|
1412
|
+
throw new SourceError(ln, `Duplicate attribute key: ${key}`);
|
|
1001
1413
|
}
|
|
1002
1414
|
attrs[key] = maybeNumber(rawVal);
|
|
1003
1415
|
}
|
|
@@ -1008,7 +1420,7 @@ function maybeNumber(v) {
|
|
|
1008
1420
|
}
|
|
1009
1421
|
function toNumber(v, ln, what) {
|
|
1010
1422
|
if (!/^-?\d+(\.\d+)?$/.test(v))
|
|
1011
|
-
throw new SourceError(ln, `${what}
|
|
1423
|
+
throw new SourceError(ln, `${what} is not a number: ${v}`);
|
|
1012
1424
|
return Number(v);
|
|
1013
1425
|
}
|
|
1014
1426
|
function takeNumber(attrs, key, ln) {
|
|
@@ -1018,7 +1430,7 @@ function takeNumber(attrs, key, ln) {
|
|
|
1018
1430
|
delete attrs[key];
|
|
1019
1431
|
if (typeof v !== "number") {
|
|
1020
1432
|
// NaNの黙認はcheck緑のまま導出を壊す (typo h:24O0 など) — その場のエラーにする
|
|
1021
|
-
throw new SourceError(ln,
|
|
1433
|
+
throw new SourceError(ln, `The attribute ${key} is written as a number: ${v}`);
|
|
1022
1434
|
}
|
|
1023
1435
|
return v;
|
|
1024
1436
|
}
|
|
@@ -1034,7 +1446,7 @@ function takeEdge(attrs, ln) {
|
|
|
1034
1446
|
if (v === undefined)
|
|
1035
1447
|
return undefined;
|
|
1036
1448
|
if (!EDGES.has(v))
|
|
1037
|
-
throw new SourceError(ln, `edge
|
|
1449
|
+
throw new SourceError(ln, `edge is given as N/E/S/W: ${v}`);
|
|
1038
1450
|
return v;
|
|
1039
1451
|
}
|
|
1040
1452
|
//# sourceMappingURL=parse.js.map
|