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