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