@driftsys/markspec 0.4.0 → 0.5.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 (319) hide show
  1. package/esm/ast/build.d.ts +70 -0
  2. package/esm/ast/build.d.ts.map +1 -0
  3. package/esm/ast/build.js +605 -0
  4. package/esm/ast/equivalence.d.ts +18 -0
  5. package/esm/ast/equivalence.d.ts.map +1 -0
  6. package/esm/ast/equivalence.js +56 -0
  7. package/esm/ast/nodes.d.ts +221 -0
  8. package/esm/ast/nodes.d.ts.map +1 -0
  9. package/esm/ast/nodes.js +12 -0
  10. package/esm/ast/normalize.d.ts +67 -0
  11. package/esm/ast/normalize.d.ts.map +1 -0
  12. package/esm/ast/normalize.js +255 -0
  13. package/esm/ast/render.d.ts +34 -0
  14. package/esm/ast/render.d.ts.map +1 -0
  15. package/esm/ast/render.js +215 -0
  16. package/esm/compiler/inverses.d.ts +2 -8
  17. package/esm/compiler/inverses.d.ts.map +1 -1
  18. package/esm/compiler/inverses.js +50 -14
  19. package/esm/compiler/manifest.d.ts +59 -0
  20. package/esm/compiler/manifest.d.ts.map +1 -0
  21. package/esm/compiler/manifest.js +48 -0
  22. package/esm/compiler/mod.d.ts +9 -1
  23. package/esm/compiler/mod.d.ts.map +1 -1
  24. package/esm/compiler/mod.js +21 -2
  25. package/esm/compiler/ndjson_writer.d.ts +50 -0
  26. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  27. package/esm/compiler/ndjson_writer.js +73 -0
  28. package/esm/compiler/schema.d.ts +18 -1
  29. package/esm/compiler/schema.d.ts.map +1 -1
  30. package/esm/compiler/schema.js +18 -9
  31. package/esm/config/mod.d.ts.map +1 -1
  32. package/esm/config/mod.js +54 -0
  33. package/esm/formatter/mod.d.ts +49 -4
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +362 -33
  36. package/esm/formatter/synth_ulid.d.ts +21 -0
  37. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  38. package/esm/formatter/synth_ulid.js +64 -0
  39. package/esm/lint/mod.d.ts +10 -0
  40. package/esm/lint/mod.d.ts.map +1 -0
  41. package/esm/lint/mod.js +7 -0
  42. package/esm/lint/rules/lexicon.d.ts +24 -0
  43. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  44. package/esm/lint/rules/lexicon.js +236 -0
  45. package/esm/lint/rules/struct.d.ts +17 -0
  46. package/esm/lint/rules/struct.d.ts.map +1 -0
  47. package/esm/lint/rules/struct.js +55 -0
  48. package/esm/lint/rules/suppression.d.ts +19 -0
  49. package/esm/lint/rules/suppression.d.ts.map +1 -0
  50. package/esm/lint/rules/suppression.js +75 -0
  51. package/esm/lint/runner.d.ts +39 -0
  52. package/esm/lint/runner.d.ts.map +1 -0
  53. package/esm/lint/runner.js +112 -0
  54. package/esm/lint/types.d.ts +19 -0
  55. package/esm/lint/types.d.ts.map +1 -0
  56. package/esm/lint/types.js +9 -0
  57. package/esm/mod.d.ts +19 -6
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +14 -3
  60. package/esm/model/attributes.d.ts.map +1 -1
  61. package/esm/model/attributes.js +163 -2
  62. package/esm/model/discriminating_attr.d.ts +33 -0
  63. package/esm/model/discriminating_attr.d.ts.map +1 -0
  64. package/esm/model/discriminating_attr.js +74 -0
  65. package/esm/model/mod.d.ts +98 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +57 -2
  68. package/esm/model/profile.d.ts +33 -27
  69. package/esm/model/profile.d.ts.map +1 -1
  70. package/esm/model/source_introspection.d.ts +26 -0
  71. package/esm/model/source_introspection.d.ts.map +1 -0
  72. package/esm/model/source_introspection.js +77 -0
  73. package/esm/model/type_hierarchy.d.ts +51 -0
  74. package/esm/model/type_hierarchy.d.ts.map +1 -0
  75. package/esm/model/type_hierarchy.js +126 -0
  76. package/esm/model/uri_scheme_map.d.ts +21 -0
  77. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  78. package/esm/model/uri_scheme_map.js +66 -0
  79. package/esm/parser/attributes.d.ts.map +1 -1
  80. package/esm/parser/attributes.js +9 -6
  81. package/esm/parser/entity_refs.d.ts +53 -0
  82. package/esm/parser/entity_refs.d.ts.map +1 -0
  83. package/esm/parser/entity_refs.js +151 -0
  84. package/esm/parser/glossary.d.ts +43 -0
  85. package/esm/parser/glossary.d.ts.map +1 -0
  86. package/esm/parser/glossary.js +217 -0
  87. package/esm/parser/markdown.d.ts.map +1 -1
  88. package/esm/parser/markdown.js +223 -7
  89. package/esm/parser/mod.d.ts +1 -0
  90. package/esm/parser/mod.d.ts.map +1 -1
  91. package/esm/parser/mod.js +1 -0
  92. package/esm/parser/source.d.ts +20 -0
  93. package/esm/parser/source.d.ts.map +1 -1
  94. package/esm/parser/source.js +3 -3
  95. package/esm/profile/chain.js +3 -13
  96. package/esm/profile/colors.js +1 -1
  97. package/esm/profile/introspect.d.ts +135 -0
  98. package/esm/profile/introspect.d.ts.map +1 -0
  99. package/esm/profile/introspect.js +378 -0
  100. package/esm/profile/load.d.ts.map +1 -1
  101. package/esm/profile/load.js +67 -0
  102. package/esm/profile/manifest.d.ts.map +1 -1
  103. package/esm/profile/manifest.js +277 -88
  104. package/esm/profile/merge.js +139 -39
  105. package/esm/profile/mod.d.ts +2 -4
  106. package/esm/profile/mod.d.ts.map +1 -1
  107. package/esm/profile/mod.js +5 -2
  108. package/esm/reporter/mod.js +4 -4
  109. package/esm/util/fence.d.ts +30 -0
  110. package/esm/util/fence.d.ts.map +1 -0
  111. package/esm/util/fence.js +40 -0
  112. package/esm/validator/attributes.d.ts +3 -3
  113. package/esm/validator/attributes.d.ts.map +1 -1
  114. package/esm/validator/attributes.js +1 -18
  115. package/esm/validator/body_blocks.d.ts +38 -0
  116. package/esm/validator/body_blocks.d.ts.map +1 -0
  117. package/esm/validator/body_blocks.js +218 -0
  118. package/esm/validator/caption_convention.d.ts +29 -0
  119. package/esm/validator/caption_convention.d.ts.map +1 -0
  120. package/esm/validator/caption_convention.js +58 -0
  121. package/esm/validator/captions.d.ts +22 -0
  122. package/esm/validator/captions.d.ts.map +1 -0
  123. package/esm/validator/captions.js +137 -0
  124. package/esm/validator/component_schemes.d.ts +73 -0
  125. package/esm/validator/component_schemes.d.ts.map +1 -0
  126. package/esm/validator/component_schemes.js +375 -0
  127. package/esm/validator/feature_ac.d.ts +28 -0
  128. package/esm/validator/feature_ac.d.ts.map +1 -0
  129. package/esm/validator/feature_ac.js +102 -0
  130. package/esm/validator/listing.d.ts +42 -0
  131. package/esm/validator/listing.d.ts.map +1 -0
  132. package/esm/validator/listing.js +295 -0
  133. package/esm/validator/mod.d.ts +2 -0
  134. package/esm/validator/mod.d.ts.map +1 -1
  135. package/esm/validator/mod.js +253 -12
  136. package/esm/validator/modal_keywords.d.ts +23 -0
  137. package/esm/validator/modal_keywords.d.ts.map +1 -0
  138. package/esm/validator/modal_keywords.js +137 -0
  139. package/esm/validator/per_type_attrs.d.ts +29 -0
  140. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  141. package/esm/validator/per_type_attrs.js +75 -0
  142. package/esm/validator/pipeline.d.ts +7 -2
  143. package/esm/validator/pipeline.d.ts.map +1 -1
  144. package/esm/validator/pipeline.js +40 -7
  145. package/esm/validator/trace_types.d.ts +26 -0
  146. package/esm/validator/trace_types.d.ts.map +1 -0
  147. package/esm/validator/trace_types.js +232 -0
  148. package/esm/validator/traceability.d.ts +3 -4
  149. package/esm/validator/traceability.d.ts.map +1 -1
  150. package/esm/validator/traceability.js +5 -10
  151. package/esm/validator/type_resolution.d.ts +67 -0
  152. package/esm/validator/type_resolution.d.ts.map +1 -0
  153. package/esm/validator/type_resolution.js +140 -0
  154. package/esm/validator/types.d.ts +45 -0
  155. package/esm/validator/types.d.ts.map +1 -1
  156. package/esm/validator/types.js +128 -16
  157. package/esm/validator/value_types.d.ts +8 -0
  158. package/esm/validator/value_types.d.ts.map +1 -1
  159. package/esm/validator/value_types.js +8 -1
  160. package/package.json +1 -1
  161. package/script/ast/build.d.ts +70 -0
  162. package/script/ast/build.d.ts.map +1 -0
  163. package/script/ast/build.js +610 -0
  164. package/script/ast/equivalence.d.ts +18 -0
  165. package/script/ast/equivalence.d.ts.map +1 -0
  166. package/script/ast/equivalence.js +59 -0
  167. package/script/ast/nodes.d.ts +221 -0
  168. package/script/ast/nodes.d.ts.map +1 -0
  169. package/script/ast/nodes.js +13 -0
  170. package/script/ast/normalize.d.ts +67 -0
  171. package/script/ast/normalize.d.ts.map +1 -0
  172. package/script/ast/normalize.js +258 -0
  173. package/script/ast/render.d.ts +34 -0
  174. package/script/ast/render.d.ts.map +1 -0
  175. package/script/ast/render.js +218 -0
  176. package/script/compiler/inverses.d.ts +2 -8
  177. package/script/compiler/inverses.d.ts.map +1 -1
  178. package/script/compiler/inverses.js +50 -14
  179. package/script/compiler/manifest.d.ts +59 -0
  180. package/script/compiler/manifest.d.ts.map +1 -0
  181. package/script/compiler/manifest.js +51 -0
  182. package/script/compiler/mod.d.ts +9 -1
  183. package/script/compiler/mod.d.ts.map +1 -1
  184. package/script/compiler/mod.js +21 -2
  185. package/script/compiler/ndjson_writer.d.ts +50 -0
  186. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  187. package/script/compiler/ndjson_writer.js +78 -0
  188. package/script/compiler/schema.d.ts +18 -1
  189. package/script/compiler/schema.d.ts.map +1 -1
  190. package/script/compiler/schema.js +18 -8
  191. package/script/config/mod.d.ts.map +1 -1
  192. package/script/config/mod.js +54 -0
  193. package/script/formatter/mod.d.ts +49 -4
  194. package/script/formatter/mod.d.ts.map +1 -1
  195. package/script/formatter/mod.js +365 -33
  196. package/script/formatter/synth_ulid.d.ts +21 -0
  197. package/script/formatter/synth_ulid.d.ts.map +1 -0
  198. package/script/formatter/synth_ulid.js +67 -0
  199. package/script/lint/mod.d.ts +10 -0
  200. package/script/lint/mod.d.ts.map +1 -0
  201. package/script/lint/mod.js +12 -0
  202. package/script/lint/rules/lexicon.d.ts +24 -0
  203. package/script/lint/rules/lexicon.d.ts.map +1 -0
  204. package/script/lint/rules/lexicon.js +240 -0
  205. package/script/lint/rules/struct.d.ts +17 -0
  206. package/script/lint/rules/struct.d.ts.map +1 -0
  207. package/script/lint/rules/struct.js +59 -0
  208. package/script/lint/rules/suppression.d.ts +19 -0
  209. package/script/lint/rules/suppression.d.ts.map +1 -0
  210. package/script/lint/rules/suppression.js +80 -0
  211. package/script/lint/runner.d.ts +39 -0
  212. package/script/lint/runner.d.ts.map +1 -0
  213. package/script/lint/runner.js +116 -0
  214. package/script/lint/types.d.ts +19 -0
  215. package/script/lint/types.d.ts.map +1 -0
  216. package/script/lint/types.js +10 -0
  217. package/script/mod.d.ts +19 -6
  218. package/script/mod.d.ts.map +1 -1
  219. package/script/mod.js +56 -32
  220. package/script/model/attributes.d.ts.map +1 -1
  221. package/script/model/attributes.js +163 -2
  222. package/script/model/discriminating_attr.d.ts +33 -0
  223. package/script/model/discriminating_attr.d.ts.map +1 -0
  224. package/script/model/discriminating_attr.js +77 -0
  225. package/script/model/mod.d.ts +98 -3
  226. package/script/model/mod.d.ts.map +1 -1
  227. package/script/model/mod.js +64 -3
  228. package/script/model/profile.d.ts +33 -27
  229. package/script/model/profile.d.ts.map +1 -1
  230. package/script/model/source_introspection.d.ts +26 -0
  231. package/script/model/source_introspection.d.ts.map +1 -0
  232. package/script/model/source_introspection.js +80 -0
  233. package/script/model/type_hierarchy.d.ts +51 -0
  234. package/script/model/type_hierarchy.d.ts.map +1 -0
  235. package/script/model/type_hierarchy.js +130 -0
  236. package/script/model/uri_scheme_map.d.ts +21 -0
  237. package/script/model/uri_scheme_map.d.ts.map +1 -0
  238. package/script/model/uri_scheme_map.js +69 -0
  239. package/script/parser/attributes.d.ts.map +1 -1
  240. package/script/parser/attributes.js +9 -6
  241. package/script/parser/entity_refs.d.ts +53 -0
  242. package/script/parser/entity_refs.d.ts.map +1 -0
  243. package/script/parser/entity_refs.js +155 -0
  244. package/script/parser/glossary.d.ts +43 -0
  245. package/script/parser/glossary.d.ts.map +1 -0
  246. package/script/parser/glossary.js +221 -0
  247. package/script/parser/markdown.d.ts.map +1 -1
  248. package/script/parser/markdown.js +222 -6
  249. package/script/parser/mod.d.ts +1 -0
  250. package/script/parser/mod.d.ts.map +1 -1
  251. package/script/parser/mod.js +5 -1
  252. package/script/parser/source.d.ts +20 -0
  253. package/script/parser/source.d.ts.map +1 -1
  254. package/script/parser/source.js +3 -0
  255. package/script/profile/chain.js +3 -13
  256. package/script/profile/colors.js +1 -1
  257. package/script/profile/introspect.d.ts +135 -0
  258. package/script/profile/introspect.d.ts.map +1 -0
  259. package/script/profile/introspect.js +381 -0
  260. package/script/profile/load.d.ts.map +1 -1
  261. package/script/profile/load.js +67 -0
  262. package/script/profile/manifest.d.ts.map +1 -1
  263. package/script/profile/manifest.js +276 -87
  264. package/script/profile/merge.js +139 -39
  265. package/script/profile/mod.d.ts +2 -4
  266. package/script/profile/mod.d.ts.map +1 -1
  267. package/script/profile/mod.js +7 -6
  268. package/script/reporter/mod.js +4 -4
  269. package/script/util/fence.d.ts +30 -0
  270. package/script/util/fence.d.ts.map +1 -0
  271. package/script/util/fence.js +44 -0
  272. package/script/validator/attributes.d.ts +3 -3
  273. package/script/validator/attributes.d.ts.map +1 -1
  274. package/script/validator/attributes.js +1 -18
  275. package/script/validator/body_blocks.d.ts +38 -0
  276. package/script/validator/body_blocks.d.ts.map +1 -0
  277. package/script/validator/body_blocks.js +221 -0
  278. package/script/validator/caption_convention.d.ts +29 -0
  279. package/script/validator/caption_convention.d.ts.map +1 -0
  280. package/script/validator/caption_convention.js +61 -0
  281. package/script/validator/captions.d.ts +22 -0
  282. package/script/validator/captions.d.ts.map +1 -0
  283. package/script/validator/captions.js +140 -0
  284. package/script/validator/component_schemes.d.ts +73 -0
  285. package/script/validator/component_schemes.d.ts.map +1 -0
  286. package/script/validator/component_schemes.js +384 -0
  287. package/script/validator/feature_ac.d.ts +28 -0
  288. package/script/validator/feature_ac.d.ts.map +1 -0
  289. package/script/validator/feature_ac.js +105 -0
  290. package/script/validator/listing.d.ts +42 -0
  291. package/script/validator/listing.d.ts.map +1 -0
  292. package/script/validator/listing.js +298 -0
  293. package/script/validator/mod.d.ts +2 -0
  294. package/script/validator/mod.d.ts.map +1 -1
  295. package/script/validator/mod.js +256 -14
  296. package/script/validator/modal_keywords.d.ts +23 -0
  297. package/script/validator/modal_keywords.d.ts.map +1 -0
  298. package/script/validator/modal_keywords.js +140 -0
  299. package/script/validator/per_type_attrs.d.ts +29 -0
  300. package/script/validator/per_type_attrs.d.ts.map +1 -0
  301. package/script/validator/per_type_attrs.js +78 -0
  302. package/script/validator/pipeline.d.ts +7 -2
  303. package/script/validator/pipeline.d.ts.map +1 -1
  304. package/script/validator/pipeline.js +39 -6
  305. package/script/validator/trace_types.d.ts +26 -0
  306. package/script/validator/trace_types.d.ts.map +1 -0
  307. package/script/validator/trace_types.js +235 -0
  308. package/script/validator/traceability.d.ts +3 -4
  309. package/script/validator/traceability.d.ts.map +1 -1
  310. package/script/validator/traceability.js +5 -10
  311. package/script/validator/type_resolution.d.ts +67 -0
  312. package/script/validator/type_resolution.d.ts.map +1 -0
  313. package/script/validator/type_resolution.js +146 -0
  314. package/script/validator/types.d.ts +45 -0
  315. package/script/validator/types.d.ts.map +1 -1
  316. package/script/validator/types.js +131 -16
  317. package/script/validator/value_types.d.ts +8 -0
  318. package/script/validator/value_types.d.ts.map +1 -1
  319. package/script/validator/value_types.js +10 -2
@@ -0,0 +1,221 @@
1
+ /**
2
+ * @module core/ast/nodes
3
+ *
4
+ * Canonical body-AST node taxonomy. Authoritative spec:
5
+ * `docs/specs/markspec-core-data-model.md` §2.4 (closed 10-block
6
+ * catalogue), §2.5 (inline markers), §2.6 (captions).
7
+ *
8
+ * PR 1 of the canonical-body-AST plan: pure type contract, zero
9
+ * behaviour. The builder (`build.ts`) and renderer (`render.ts`)
10
+ * land in later PRs.
11
+ */
12
+ import type { EntityRefConvention } from "../model/mod.js";
13
+ /** Body-relative source span. 1-based line/column, matching the
14
+ * codebase's {@link SourceLocation} convention. No `file`: that
15
+ * lives on the owning {@link Entry}. */
16
+ export interface SourceRange {
17
+ readonly start: {
18
+ readonly line: number;
19
+ readonly column: number;
20
+ };
21
+ readonly end: {
22
+ readonly line: number;
23
+ readonly column: number;
24
+ };
25
+ }
26
+ /** RFC 2119 vs EARS modal class (spec §2.5.1). */
27
+ export type ModalMarkerClass = "rfc2119" | "ears";
28
+ /** A recognised modal keyword occurrence in prose (spec §2.5.1). */
29
+ export interface ModalMarker {
30
+ readonly kind: "modal";
31
+ readonly cls: ModalMarkerClass;
32
+ /** Canonical (lowercased RFC 2119 / case-preserved EARS) form. */
33
+ readonly canonical: string;
34
+ /**
35
+ * Original source text as it appears in the body (may differ from
36
+ * `canonical` for RFC 2119 keywords written in uppercase, e.g.
37
+ * `"SHALL"` vs `canonical = "shall"`). Used by the MSL-M060 validator
38
+ * to report the exact uppercase form in the diagnostic message and to
39
+ * detect whether the keyword deviates from canonical form.
40
+ *
41
+ * Populated by {@link extractMarkersFromText} in `core/ast/build.ts`.
42
+ * Absent only for `ModalMarker` values constructed outside the builder
43
+ * (e.g. in tests that predate this field).
44
+ */
45
+ readonly raw?: string;
46
+ readonly range: SourceRange;
47
+ }
48
+ /** An inline `$Identifier` entity reference (spec §2.5.2). Reuses
49
+ * the existing {@link EntityRefConvention}. */
50
+ export interface EntityRefMarker {
51
+ readonly kind: "entity";
52
+ /** Identifier including the leading `$`. */
53
+ readonly ident: string;
54
+ readonly convention: EntityRefConvention;
55
+ readonly range: SourceRange;
56
+ }
57
+ /** Inline marker union (spec §2.5). */
58
+ export type InlineMarker = ModalMarker | EntityRefMarker;
59
+ /**
60
+ * Prose text plus the inline markers recognised within it.
61
+ *
62
+ * `text` is the **verbatim source prose** (markup-preserving — emphasis,
63
+ * strong, links, autolinks, hard line breaks survive byte-identically per
64
+ * spec §5.1). `markers` are recognised from the flattened projection so
65
+ * modal / $Identifier detection is unaffected by surrounding markup.
66
+ * Marker `range` columns are best-effort relative to the verbatim text.
67
+ */
68
+ export interface InlineContent {
69
+ readonly text: string;
70
+ readonly markers: readonly InlineMarker[];
71
+ }
72
+ /** A list item: a sequence of blocks (spec §2.4 `List`). */
73
+ export interface ListItemNode {
74
+ readonly blocks: readonly BodyBlock[];
75
+ /**
76
+ * GFM task-list checkbox state for this item, when present:
77
+ * `false` = `[ ]`, `true` = `[x]`. Absent for non-task items.
78
+ * Round-tripped by the renderer; `ListNode.hasTaskItems` (used by
79
+ * MSL-B042) is derived independently and unaffected.
80
+ */
81
+ readonly checked?: boolean;
82
+ /**
83
+ * True when this item is "loose" (mdast `listItem.spread`): its blocks
84
+ * are separated by blank lines in source. Drives inter-block blank-line
85
+ * emission in the renderer. Distinct from `ListNode.spread`, which is
86
+ * the list-level item-separation signal.
87
+ */
88
+ readonly spread?: boolean;
89
+ readonly range: SourceRange;
90
+ }
91
+ /** One `Term : definition` pair (spec §2.4 `DefinitionList`). */
92
+ export interface DefinitionPair {
93
+ readonly term: InlineContent;
94
+ readonly definition: InlineContent;
95
+ }
96
+ /** GitHub-style admonition kinds (spec §2.4 `Note`). */
97
+ export type AdmonitionKind = "NOTE" | "TIP" | "IMPORTANT" | "WARNING" | "CAUTION";
98
+ /** CommonMark paragraph; carries inline markers (spec §2.4). */
99
+ export interface ParagraphNode {
100
+ readonly kind: "paragraph";
101
+ readonly content: InlineContent;
102
+ readonly range: SourceRange;
103
+ }
104
+ /** Ordered or unordered list, nestable (spec §2.4). */
105
+ export interface ListNode {
106
+ readonly kind: "list";
107
+ readonly ordered: boolean;
108
+ /** True when the list is "loose" (items separated by blank lines in
109
+ * source). Controls whether items are joined with `\n\n` vs `\n` on
110
+ * render. Corresponds to the mdast `list.spread` property. */
111
+ readonly spread: boolean;
112
+ readonly items: readonly ListItemNode[];
113
+ /**
114
+ * True when at least one item is a GFM task-list item (checked or
115
+ * unchecked). Used by the body-block exclusion validator (MSL-B042)
116
+ * to flag task lists inside entry bodies without re-scanning the
117
+ * body string.
118
+ */
119
+ readonly hasTaskItems?: boolean;
120
+ readonly range: SourceRange;
121
+ }
122
+ /** GFM pipe table (spec §2.4). */
123
+ export interface TableNode {
124
+ readonly kind: "table";
125
+ readonly header: readonly InlineContent[];
126
+ readonly rows: readonly (readonly InlineContent[])[];
127
+ /** Verbatim source substring of the table (preserves author column
128
+ * widths for byte-identical round-trip; header/rows are the parsed
129
+ * view for validators). */
130
+ readonly raw: string;
131
+ readonly range: SourceRange;
132
+ }
133
+ /** Image link `![alt](path)` (spec §2.4). */
134
+ export interface FigureNode {
135
+ readonly kind: "figure";
136
+ readonly alt: string;
137
+ readonly path: string;
138
+ readonly range: SourceRange;
139
+ }
140
+ /** Fenced code block; info-string language tag, or none (spec §2.4). */
141
+ export interface CodeNode {
142
+ readonly kind: "code";
143
+ /** Info-string language tag, or `undefined` for a bare fence. */
144
+ readonly lang: string | undefined;
145
+ readonly text: string;
146
+ readonly range: SourceRange;
147
+ }
148
+ /** Fenced code with info-string `gherkin`. Gherkin is kept verbatim
149
+ * for now; structured scenario parsing is deferred to a later PR
150
+ * (see the canonical-body-AST plan). */
151
+ export interface FeatureNode {
152
+ readonly kind: "feature";
153
+ readonly source: string;
154
+ readonly range: SourceRange;
155
+ }
156
+ /** `$$ … $$` math block (spec §2.4). */
157
+ export interface MathNode {
158
+ readonly kind: "math";
159
+ readonly tex: string;
160
+ readonly range: SourceRange;
161
+ }
162
+ /** `Term` / `: definition` list, GLFM (spec §2.4). */
163
+ export interface DefinitionListNode {
164
+ readonly kind: "definition-list";
165
+ readonly items: readonly DefinitionPair[];
166
+ readonly range: SourceRange;
167
+ }
168
+ /** GitHub-style admonition blockquote (spec §2.4). */
169
+ export interface NoteNode {
170
+ readonly kind: "note";
171
+ readonly admonition: AdmonitionKind;
172
+ readonly content: InlineContent;
173
+ /**
174
+ * True when the admonition body began on the marker line in source
175
+ * (`> [!NOTE] text`) rather than its own quoted line. Round-tripped by
176
+ * the renderer. Absent ⇒ own-line form (the canonical default).
177
+ */
178
+ readonly markerInline?: boolean;
179
+ readonly range: SourceRange;
180
+ }
181
+ /** Plain `>` blockquote, for external citation excerpts (spec §2.4). */
182
+ export interface BlockquoteNode {
183
+ readonly kind: "blockquote";
184
+ readonly content: InlineContent;
185
+ readonly range: SourceRange;
186
+ }
187
+ /** §2.6 caption. Distinct from the render-pipeline `Caption`
188
+ * (model/mod.ts) — unrelated concept. `block` (resolved owner) is
189
+ * populated by the builder/validator in later PRs. */
190
+ export interface CaptionNode {
191
+ readonly kind: "caption";
192
+ readonly keyword: "Figure" | "Table" | "Listing" | "Feature" | "Equation" | "List";
193
+ readonly text: string;
194
+ readonly position: "above" | "below";
195
+ readonly block?: BodyBlock;
196
+ readonly range: SourceRange;
197
+ }
198
+ /** Fallback for malformed / excluded constructs so content is never
199
+ * lost (spec §5.4). Excluded constructs still emit MSL-B040–B043. */
200
+ export interface UnknownNode {
201
+ readonly kind: "unknown";
202
+ /** Carries the verbatim source slice (spec §5.4 lossless preservation). */
203
+ readonly raw: string;
204
+ /**
205
+ * Sub-kind for constructs the body-block exclusion validator (MSL-B040–B043)
206
+ * needs to distinguish. Absent for truly unknown nodes; set for the three
207
+ * categories the validator checks:
208
+ *
209
+ * - `"heading"` — CommonMark ATX/setext heading (`#`, `##`, …, underline)
210
+ * - `"thematic-break"` — horizontal rule (`---`, `***`, `___`)
211
+ * - `"html"` — raw block-level HTML (comment or tag)
212
+ *
213
+ * Note: GFM task-list items are detected via `ListNode.hasTaskItems` and
214
+ * never assigned this subkind.
215
+ */
216
+ readonly subkind?: "heading" | "thematic-break" | "html";
217
+ readonly range: SourceRange;
218
+ }
219
+ /** The closed body-block union (spec §2.4) + `caption` + `unknown`. */
220
+ export type BodyBlock = ParagraphNode | ListNode | TableNode | FigureNode | CodeNode | FeatureNode | MathNode | DefinitionListNode | NoteNode | BlockquoteNode | CaptionNode | UnknownNode;
221
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nod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AClB,QAAQ,GACR,cAAc,GACd,WAAW,GACX,WAAW,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/ast/nodes
4
+ *
5
+ * Canonical body-AST node taxonomy. Authoritative spec:
6
+ * `docs/specs/markspec-core-data-model.md` §2.4 (closed 10-block
7
+ * catalogue), §2.5 (inline markers), §2.6 (captions).
8
+ *
9
+ * PR 1 of the canonical-body-AST plan: pure type contract, zero
10
+ * behaviour. The builder (`build.ts`) and renderer (`render.ts`)
11
+ * land in later PRs.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module core/ast/normalize
3
+ *
4
+ * The AST-native §3.4.1 modal-keyword case pass (ADR-015 / SP3 Task 2).
5
+ *
6
+ * `normalizeBodyAst` is a deterministic, total, pure AST→AST transform
7
+ * that applies the §3.4.1 modal-keyword case rule to every prose-bearing
8
+ * node's `InlineContent.text` and re-derives `InlineContent.markers` from
9
+ * the normalised text via the SAME extraction the builder uses
10
+ * (`extractMarkersFromText`, re-exported from `core/ast/build.ts`).
11
+ *
12
+ * §3.4.1 rule (`docs/specs/markspec-core-data-model.md` §3.4.1), ported
13
+ * verbatim from the string pass `normalizeModalKeywords` in
14
+ * `core/formatter/mod.ts`:
15
+ *
16
+ * - RFC 2119 (`SHALL`, `SHOULD`, `MAY`, `MUST`, optionally `… NOT`) —
17
+ * always lowercased.
18
+ * - EARS (`When`, `While`, `Where`, `Unless`) — lowercased
19
+ * mid-sentence, capitalisation preserved when sentence-initial.
20
+ *
21
+ * The regexes and `isSentenceInitial` logic are intentionally a faithful
22
+ * copy of `core/formatter/mod.ts`. The string pass cannot be imported:
23
+ * `core/formatter/` already depends on `core/ast/`, so an `ast →
24
+ * formatter` import would invert the one-directional dependency flow and
25
+ * create a cycle. The formatter now delegates to THIS module for the AST
26
+ * path (SP3 Task 5), but `normalizeModalKeywords` in `formatter/mod.ts`
27
+ * is retained for the title/trailer string paths. Full deduplication is
28
+ * deferred to a future sprint (TODO SP4: unify the two implementations
29
+ * once all prose paths migrate to the AST path).
30
+ *
31
+ * Invariants (HARD — never weaken):
32
+ * - Pure: no `Deno.*`, no I/O.
33
+ * - Deterministic.
34
+ * - Total: never throws; unknown / unexpected shapes pass through.
35
+ * - Idempotent: `normalizeBodyAst(normalizeBodyAst(x))` ≡
36
+ * `normalizeBodyAst(x)`.
37
+ * - Non-mutating: returns new arrays / nodes; the input is never
38
+ * written to.
39
+ * - Verbatim nodes (Code / Feature / Math) get NO modal recognition
40
+ * (spec §2.5); Figure / Caption / Unknown pass through unchanged.
41
+ *
42
+ * This module is pure library code: no `Deno.*` APIs.
43
+ */
44
+ import type { BodyBlock } from "./nodes.js";
45
+ /**
46
+ * Apply the §3.4.1 modal-keyword case rule to every prose-bearing node
47
+ * in a body AST, re-deriving `InlineContent.markers` from the normalised
48
+ * text.
49
+ *
50
+ * Pure, deterministic, total (never throws; unknown shapes pass
51
+ * through), idempotent, and non-mutating: a fresh top-level array is
52
+ * always returned and the input is never written to. Verbatim nodes
53
+ * (Code / Feature / Math) and Figure / Caption / Unknown are returned
54
+ * unchanged (spec §2.5 — no modal recognition inside verbatim content).
55
+ *
56
+ * Called exclusively from the formatter path (`core/formatter/mod.ts`);
57
+ * never called from the parser or validator. The §3.4.1 case rule must
58
+ * NOT be applied during parse/validate — `MSL-M060` still fires on
59
+ * uppercase modals seen by the validator.
60
+ *
61
+ * @param blocks - The `BodyBlock[]` produced by `buildBodyAst` (or any
62
+ * prior `normalizeBodyAst` output — idempotence holds).
63
+ * @returns A new `BodyBlock[]`; unchanged sub-trees share references with
64
+ * the input but the input array itself is never mutated.
65
+ */
66
+ export declare function normalizeBodyAst(blocks: readonly BodyBlock[]): BodyBlock[];
67
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/ast/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAIH,OAAO,KAAK,EAEV,SAAS,EASV,MAAM,YAAY,CAAC;AAkMpB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,EAAE,CAEb"}
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/ast/normalize
4
+ *
5
+ * The AST-native §3.4.1 modal-keyword case pass (ADR-015 / SP3 Task 2).
6
+ *
7
+ * `normalizeBodyAst` is a deterministic, total, pure AST→AST transform
8
+ * that applies the §3.4.1 modal-keyword case rule to every prose-bearing
9
+ * node's `InlineContent.text` and re-derives `InlineContent.markers` from
10
+ * the normalised text via the SAME extraction the builder uses
11
+ * (`extractMarkersFromText`, re-exported from `core/ast/build.ts`).
12
+ *
13
+ * §3.4.1 rule (`docs/specs/markspec-core-data-model.md` §3.4.1), ported
14
+ * verbatim from the string pass `normalizeModalKeywords` in
15
+ * `core/formatter/mod.ts`:
16
+ *
17
+ * - RFC 2119 (`SHALL`, `SHOULD`, `MAY`, `MUST`, optionally `… NOT`) —
18
+ * always lowercased.
19
+ * - EARS (`When`, `While`, `Where`, `Unless`) — lowercased
20
+ * mid-sentence, capitalisation preserved when sentence-initial.
21
+ *
22
+ * The regexes and `isSentenceInitial` logic are intentionally a faithful
23
+ * copy of `core/formatter/mod.ts`. The string pass cannot be imported:
24
+ * `core/formatter/` already depends on `core/ast/`, so an `ast →
25
+ * formatter` import would invert the one-directional dependency flow and
26
+ * create a cycle. The formatter now delegates to THIS module for the AST
27
+ * path (SP3 Task 5), but `normalizeModalKeywords` in `formatter/mod.ts`
28
+ * is retained for the title/trailer string paths. Full deduplication is
29
+ * deferred to a future sprint (TODO SP4: unify the two implementations
30
+ * once all prose paths migrate to the AST path).
31
+ *
32
+ * Invariants (HARD — never weaken):
33
+ * - Pure: no `Deno.*`, no I/O.
34
+ * - Deterministic.
35
+ * - Total: never throws; unknown / unexpected shapes pass through.
36
+ * - Idempotent: `normalizeBodyAst(normalizeBodyAst(x))` ≡
37
+ * `normalizeBodyAst(x)`.
38
+ * - Non-mutating: returns new arrays / nodes; the input is never
39
+ * written to.
40
+ * - Verbatim nodes (Code / Feature / Math) get NO modal recognition
41
+ * (spec §2.5); Figure / Caption / Unknown pass through unchanged.
42
+ *
43
+ * This module is pure library code: no `Deno.*` APIs.
44
+ */
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.normalizeBodyAst = normalizeBodyAst;
47
+ const fence_js_1 = require("../util/fence.js");
48
+ const build_js_1 = require("./build.js");
49
+ // ---------------------------------------------------------------------------
50
+ // §3.4.1 string helper — faithful port of formatter/mod.ts
51
+ // (RFC2119_MODAL_RE, EARS_KEYWORD_RE, isSentenceInitial,
52
+ // normalizeModalKeywords). Kept byte-for-byte equivalent so the AST
53
+ // port matches the string pass exactly; Task 5 collapses the two.
54
+ // ---------------------------------------------------------------------------
55
+ /**
56
+ * RFC 2119 modal keywords in uppercase form, with optional ` NOT` suffix.
57
+ * Captured for canonical-form normalisation per spec §3.4.1: uppercase
58
+ * input is accepted but emitted lowercase, unconditionally.
59
+ */
60
+ const RFC2119_MODAL_RE = /\b(SHALL|SHOULD|MAY|MUST)(\s+NOT)?\b/g;
61
+ /**
62
+ * EARS keywords subject to the sentence-initial rule of spec §3.4.1:
63
+ * lowercased when mid-sentence, preserved when starting a sentence.
64
+ * `If…then` is deferred to a later slice because its multi-token form
65
+ * needs separate handling.
66
+ */
67
+ const EARS_KEYWORD_RE = /\b(When|While|Where|Unless)\b/g;
68
+ /**
69
+ * Decide whether the EARS keyword at `offset` in `line` is at sentence
70
+ * start (return value true). Walks left over whitespace and reports true
71
+ * when it hits the beginning of the line or a sentence-terminating
72
+ * punctuation character (`.`, `!`, `?`).
73
+ *
74
+ * Faithful copy of `isSentenceInitial` in `core/formatter/mod.ts`.
75
+ */
76
+ function isSentenceInitial(line, offset) {
77
+ if (offset === 0)
78
+ return true;
79
+ let i = offset - 1;
80
+ while (i >= 0 && (line[i] === " " || line[i] === "\t"))
81
+ i--;
82
+ if (i < 0)
83
+ return true;
84
+ const prev = line[i];
85
+ return prev === "." || prev === "!" || prev === "?";
86
+ }
87
+ /**
88
+ * Apply the §3.4.1 modal-keyword case rule to a prose string.
89
+ *
90
+ * Faithful port of `normalizeModalKeywords` (`core/formatter/mod.ts`):
91
+ * fenced-code lines are skipped (verbatim, §5.1), and lines indented by
92
+ * four or more spaces (or a tab) are skipped (conservatively captures
93
+ * indented code blocks / attribute trailers — not prose). On every other
94
+ * line, RFC 2119 keywords are lowercased unconditionally and EARS
95
+ * keywords are lowercased unless sentence-initial.
96
+ *
97
+ * Pure and total: never throws; a string with no modal keyword is
98
+ * returned unchanged.
99
+ */
100
+ function normalizeModalsInText(text) {
101
+ const lines = text.split("\n");
102
+ (0, fence_js_1.walkProseLines)(text, (line, i) => {
103
+ // Indented-code / attribute-trailer lines aren't prose either.
104
+ if (/^( {4}|\t)/.test(line))
105
+ return;
106
+ let normalized = line.replace(RFC2119_MODAL_RE, (m) => m.toLowerCase());
107
+ normalized = normalized.replace(EARS_KEYWORD_RE, (m, _g1, offset) => isSentenceInitial(normalized, offset) ? m : m.toLowerCase());
108
+ lines[i] = normalized;
109
+ });
110
+ return lines.join("\n");
111
+ }
112
+ // ---------------------------------------------------------------------------
113
+ // InlineContent normalisation
114
+ // ---------------------------------------------------------------------------
115
+ /**
116
+ * Return a NEW `InlineContent` whose `text` has every modal keyword
117
+ * normalised per §3.4.1 and whose `markers` are RE-DERIVED from the
118
+ * normalised text via the builder's `extractMarkersFromText` (so the
119
+ * marker set never goes stale relative to the text).
120
+ *
121
+ * The marker `range` start is anchored at the original content's first
122
+ * marker line when available, else (1,1); this mirrors the builder's
123
+ * best-effort, body-relative range convention and is irrelevant to the
124
+ * equivalence relation (which elides every `range`).
125
+ *
126
+ * If the normalised text equals the original, the original node is
127
+ * returned UNCHANGED (preserves the builder's exact ranges / markers and
128
+ * makes the no-op case allocation-free).
129
+ */
130
+ function normalizeInline(content) {
131
+ const normalizedText = normalizeModalsInText(content.text);
132
+ if (normalizedText === content.text)
133
+ return content;
134
+ const startRange = {
135
+ start: { line: 1, column: 1 },
136
+ end: { line: 1, column: 1 },
137
+ };
138
+ return {
139
+ text: normalizedText,
140
+ markers: (0, build_js_1.extractMarkersFromText)(normalizedText, startRange),
141
+ };
142
+ }
143
+ // ---------------------------------------------------------------------------
144
+ // Per-node normalisation — recurse structurally; verbatim nodes untouched
145
+ // ---------------------------------------------------------------------------
146
+ function normalizeListItem(item) {
147
+ const blocks = normalizeBlocks(item.blocks);
148
+ if (blocks === item.blocks)
149
+ return item;
150
+ return { ...item, blocks };
151
+ }
152
+ function normalizeBlock(block) {
153
+ switch (block.kind) {
154
+ case "paragraph": {
155
+ const content = normalizeInline(block.content);
156
+ if (content === block.content)
157
+ return block;
158
+ return { ...block, content };
159
+ }
160
+ case "note": {
161
+ const content = normalizeInline(block.content);
162
+ if (content === block.content)
163
+ return block;
164
+ return { ...block, content };
165
+ }
166
+ case "blockquote": {
167
+ const content = normalizeInline(block.content);
168
+ if (content === block.content)
169
+ return block;
170
+ return { ...block, content };
171
+ }
172
+ case "list": {
173
+ const items = block.items.map(normalizeListItem);
174
+ const changed = items.some((it, i) => it !== block.items[i]);
175
+ if (!changed)
176
+ return block;
177
+ return { ...block, items };
178
+ }
179
+ case "definition-list": {
180
+ const items = block.items.map((pair) => {
181
+ const term = normalizeInline(pair.term);
182
+ const definition = normalizeInline(pair.definition);
183
+ if (term === pair.term && definition === pair.definition)
184
+ return pair;
185
+ return { term, definition };
186
+ });
187
+ const changed = items.some((it, i) => it !== block.items[i]);
188
+ if (!changed)
189
+ return block;
190
+ return { ...block, items };
191
+ }
192
+ case "table": {
193
+ // TableNode renders via `raw` (byte-exact round-trip preserved).
194
+ // Cell InlineContent is still normalised for validator-view
195
+ // consistency — it does NOT affect render output.
196
+ const header = block.header.map(normalizeInline);
197
+ const rows = block.rows.map((row) => row.map(normalizeInline));
198
+ const headerChanged = header.some((c, i) => c !== block.header[i]);
199
+ const rowsChanged = rows.some((row, i) => row.some((c, j) => c !== block.rows[i][j]));
200
+ if (!headerChanged && !rowsChanged)
201
+ return block;
202
+ return { ...block, header, rows };
203
+ }
204
+ // Verbatim content (§2.5: no modal recognition) and structurally
205
+ // modal-free nodes pass through UNCHANGED — same reference.
206
+ case "code":
207
+ case "feature":
208
+ case "math":
209
+ case "figure":
210
+ case "caption":
211
+ case "unknown":
212
+ return block;
213
+ }
214
+ // Total: any future / unexpected shape passes through unchanged.
215
+ return block;
216
+ }
217
+ /**
218
+ * Normalise every block, returning the SAME array reference when nothing
219
+ * changed (so callers can cheaply detect a structural no-op and avoid
220
+ * re-allocating ancestor nodes).
221
+ */
222
+ function normalizeBlocks(blocks) {
223
+ let changed = false;
224
+ const out = blocks.map((b) => {
225
+ const nb = normalizeBlock(b);
226
+ if (nb !== b)
227
+ changed = true;
228
+ return nb;
229
+ });
230
+ return changed ? out : blocks;
231
+ }
232
+ // ---------------------------------------------------------------------------
233
+ // Public API
234
+ // ---------------------------------------------------------------------------
235
+ /**
236
+ * Apply the §3.4.1 modal-keyword case rule to every prose-bearing node
237
+ * in a body AST, re-deriving `InlineContent.markers` from the normalised
238
+ * text.
239
+ *
240
+ * Pure, deterministic, total (never throws; unknown shapes pass
241
+ * through), idempotent, and non-mutating: a fresh top-level array is
242
+ * always returned and the input is never written to. Verbatim nodes
243
+ * (Code / Feature / Math) and Figure / Caption / Unknown are returned
244
+ * unchanged (spec §2.5 — no modal recognition inside verbatim content).
245
+ *
246
+ * Called exclusively from the formatter path (`core/formatter/mod.ts`);
247
+ * never called from the parser or validator. The §3.4.1 case rule must
248
+ * NOT be applied during parse/validate — `MSL-M060` still fires on
249
+ * uppercase modals seen by the validator.
250
+ *
251
+ * @param blocks - The `BodyBlock[]` produced by `buildBodyAst` (or any
252
+ * prior `normalizeBodyAst` output — idempotence holds).
253
+ * @returns A new `BodyBlock[]`; unchanged sub-trees share references with
254
+ * the input but the input array itself is never mutated.
255
+ */
256
+ function normalizeBodyAst(blocks) {
257
+ return [...normalizeBlocks(blocks)];
258
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @module core/ast/render
3
+ *
4
+ * Body-AST → canonical body-string renderer. The faithful inverse of
5
+ * `buildBodyAst` on already-canonical input.
6
+ *
7
+ * Invariant: for any canonical body string `s` (i.e. after running the
8
+ * MarkSpec formatter),
9
+ *
10
+ * render(buildBodyAst(s)) === s
11
+ *
12
+ * `render` does NOT re-implement the formatter's normalisation passes
13
+ * (bullet rewriting, blank-line collapse, modal lowercasing). It assumes
14
+ * its input was produced from a body string that is already in canonical
15
+ * form and simply reverses the structural mapping that `build.ts` applied.
16
+ *
17
+ * This module is pure library code: no `Deno.*` APIs.
18
+ */
19
+ import type { BodyBlock } from "./nodes.js";
20
+ /**
21
+ * Serialise a body AST back to canonical MarkSpec body text.
22
+ *
23
+ * This is the faithful inverse of `buildBodyAst` on already-canonical input:
24
+ * for any canonical body string `s`, `render(buildBodyAst(s)) === s`.
25
+ *
26
+ * `render` assumes its input was produced from body text already normalised
27
+ * by the MarkSpec formatter. It does not re-run normalisation passes.
28
+ *
29
+ * @param blocks - The `BodyBlock[]` produced by `buildBodyAst`.
30
+ * @returns The canonical body string, with blocks separated by a single
31
+ * blank line (two newlines) and no trailing newline.
32
+ */
33
+ export declare function render(blocks: readonly BodyBlock[]): string;
34
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/ast/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAEV,SAAS,EAaV,MAAM,YAAY,CAAC;AA+MpB;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAG3D"}