@blockml/parser 0.1.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 (139) hide show
  1. package/blocks/org/blockml/bml/compiler/parser/Library.bml +143 -0
  2. package/blocks/org/blockml/bml/compiler/parser/ParserType.bml +40 -0
  3. package/blocks/org/blockml/bml/compiler/parser/README.bml +68 -0
  4. package/blocks/org/blockml/bml/compiler/parser/capability/AssertBlockRoot.bml +45 -0
  5. package/blocks/org/blockml/bml/compiler/parser/capability/BuildSubBlockIndex.bml +43 -0
  6. package/blocks/org/blockml/bml/compiler/parser/capability/CollectLeadingComments.bml +50 -0
  7. package/blocks/org/blockml/bml/compiler/parser/capability/CollectTrailingComments.bml +50 -0
  8. package/blocks/org/blockml/bml/compiler/parser/capability/CreateMapContext.bml +56 -0
  9. package/blocks/org/blockml/bml/compiler/parser/capability/DetectFormat.bml +47 -0
  10. package/blocks/org/blockml/bml/compiler/parser/capability/DocumentElement.bml +43 -0
  11. package/blocks/org/blockml/bml/compiler/parser/capability/ElementChildren.bml +43 -0
  12. package/blocks/org/blockml/bml/compiler/parser/capability/ElementLocalName.bml +43 -0
  13. package/blocks/org/blockml/bml/compiler/parser/capability/ElementPrefix.bml +43 -0
  14. package/blocks/org/blockml/bml/compiler/parser/capability/ElementSourceLoc.bml +46 -0
  15. package/blocks/org/blockml/bml/compiler/parser/capability/ExpressionFromRaw.bml +46 -0
  16. package/blocks/org/blockml/bml/compiler/parser/capability/ExtractNamespaceBindings.bml +47 -0
  17. package/blocks/org/blockml/bml/compiler/parser/capability/FqnToQName.bml +46 -0
  18. package/blocks/org/blockml/bml/compiler/parser/capability/GetAttribute.bml +46 -0
  19. package/blocks/org/blockml/bml/compiler/parser/capability/GetCharacterData.bml +43 -0
  20. package/blocks/org/blockml/bml/compiler/parser/capability/GetParseErrors.bml +43 -0
  21. package/blocks/org/blockml/bml/compiler/parser/capability/HasBmlSemanticQNameBindings.bml +43 -0
  22. package/blocks/org/blockml/bml/compiler/parser/capability/InferCardinality.bml +43 -0
  23. package/blocks/org/blockml/bml/compiler/parser/capability/IsBooleanLiteral.bml +43 -0
  24. package/blocks/org/blockml/bml/compiler/parser/capability/IsCData.bml +43 -0
  25. package/blocks/org/blockml/bml/compiler/parser/capability/IsComment.bml +43 -0
  26. package/blocks/org/blockml/bml/compiler/parser/capability/IsElement.bml +43 -0
  27. package/blocks/org/blockml/bml/compiler/parser/capability/IsTextNode.bml +43 -0
  28. package/blocks/org/blockml/bml/compiler/parser/capability/IsTypeReferenceEntitySugar.bml +43 -0
  29. package/blocks/org/blockml/bml/compiler/parser/capability/MapBlock.bml +50 -0
  30. package/blocks/org/blockml/bml/compiler/parser/capability/MapBlockInstanceNode.bml +46 -0
  31. package/blocks/org/blockml/bml/compiler/parser/capability/MapCompositionTemplate.bml +46 -0
  32. package/blocks/org/blockml/bml/compiler/parser/capability/MapDocumentBlock.bml +54 -0
  33. package/blocks/org/blockml/bml/compiler/parser/capability/MapTypeReferenceEntityInstance.bml +46 -0
  34. package/blocks/org/blockml/bml/compiler/parser/capability/MergeSourceInfo.bml +49 -0
  35. package/blocks/org/blockml/bml/compiler/parser/capability/NormalizeBooleanValue.bml +43 -0
  36. package/blocks/org/blockml/bml/compiler/parser/capability/Parse.bml +52 -0
  37. package/blocks/org/blockml/bml/compiler/parser/capability/ParseBmlMeta.bml +43 -0
  38. package/blocks/org/blockml/bml/compiler/parser/capability/ParseBooleanAttribute.bml +43 -0
  39. package/blocks/org/blockml/bml/compiler/parser/capability/ParseDirectives.bml +50 -0
  40. package/blocks/org/blockml/bml/compiler/parser/capability/ParseMemberValue.bml +50 -0
  41. package/blocks/org/blockml/bml/compiler/parser/capability/ParseTypeExpression.bml +53 -0
  42. package/blocks/org/blockml/bml/compiler/parser/capability/ParseVisibilityFromName.bml +47 -0
  43. package/blocks/org/blockml/bml/compiler/parser/capability/ParseXmlDom.bml +47 -0
  44. package/blocks/org/blockml/bml/compiler/parser/capability/ResolveBlockReference.bml +53 -0
  45. package/blocks/org/blockml/bml/compiler/parser/capability/ResolvePrefix.bml +46 -0
  46. package/blocks/org/blockml/bml/compiler/parser/capability/ResolveTypeName.bml +53 -0
  47. package/blocks/org/blockml/bml/compiler/parser/capability/SourceLoc.bml +49 -0
  48. package/blocks/org/blockml/bml/compiler/parser/capability/SplitQName.bml +43 -0
  49. package/blocks/org/blockml/bml/compiler/parser/capability/TrimText.bml +43 -0
  50. package/blocks/org/blockml/bml/compiler/parser/capability/TypeExpressionToString.bml +43 -0
  51. package/blocks/org/blockml/bml/compiler/parser/capability/VisibilityPrefix.bml +43 -0
  52. package/blocks/org/blockml/bml/compiler/parser/capability/XmlTriviaFromElement.bml +47 -0
  53. package/blocks/org/blockml/bml/compiler/parser/config/MapTimeDiagnosticCodes.bml +40 -0
  54. package/blocks/org/blockml/bml/compiler/parser/config/ParserConstants.bml +49 -0
  55. package/blocks/org/blockml/bml/compiler/parser/documentation/ArchitectureOverview.bml +61 -0
  56. package/blocks/org/blockml/bml/compiler/parser/documentation/AttributeClassification.bml +56 -0
  57. package/blocks/org/blockml/bml/compiler/parser/documentation/BlockMetadataMapping.bml +51 -0
  58. package/blocks/org/blockml/bml/compiler/parser/documentation/DesignDecisions.bml +53 -0
  59. package/blocks/org/blockml/bml/compiler/parser/documentation/Diagnostics.bml +52 -0
  60. package/blocks/org/blockml/bml/compiler/parser/documentation/ExpressionCapture.bml +46 -0
  61. package/blocks/org/blockml/bml/compiler/parser/documentation/Introduction.bml +52 -0
  62. package/blocks/org/blockml/bml/compiler/parser/documentation/LayerSeparation.bml +55 -0
  63. package/blocks/org/blockml/bml/compiler/parser/documentation/MappingPrinciples.bml +48 -0
  64. package/blocks/org/blockml/bml/compiler/parser/documentation/MemberMapping.bml +48 -0
  65. package/blocks/org/blockml/bml/compiler/parser/documentation/MemberMappingOrder.bml +46 -0
  66. package/blocks/org/blockml/bml/compiler/parser/documentation/PackageOwnership.bml +50 -0
  67. package/blocks/org/blockml/bml/compiler/parser/documentation/PublicApi.bml +58 -0
  68. package/blocks/org/blockml/bml/compiler/parser/documentation/RoundtripContract.bml +50 -0
  69. package/blocks/org/blockml/bml/compiler/parser/documentation/ScopeExclusions.bml +49 -0
  70. package/blocks/org/blockml/bml/compiler/parser/documentation/SingleFileScope.bml +47 -0
  71. package/blocks/org/blockml/bml/compiler/parser/documentation/TypeDescriptorParsing.bml +47 -0
  72. package/blocks/org/blockml/bml/compiler/parser/documentation/V1Scope.bml +48 -0
  73. package/blocks/org/blockml/bml/compiler/parser/documentation/XmlCommentsParse.bml +48 -0
  74. package/blocks/org/blockml/bml/compiler/parser/map/MapContext.bml +58 -0
  75. package/dist/index.d.ts +2 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +2 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/map/context.d.ts +16 -0
  80. package/dist/map/context.d.ts.map +1 -0
  81. package/dist/map/context.js +15 -0
  82. package/dist/map/context.js.map +1 -0
  83. package/dist/map/directives.d.ts +23 -0
  84. package/dist/map/directives.d.ts.map +1 -0
  85. package/dist/map/directives.js +89 -0
  86. package/dist/map/directives.js.map +1 -0
  87. package/dist/map/map-block.d.ts +6 -0
  88. package/dist/map/map-block.d.ts.map +1 -0
  89. package/dist/map/map-block.js +792 -0
  90. package/dist/map/map-block.js.map +1 -0
  91. package/dist/map/map-composition.d.ts +23 -0
  92. package/dist/map/map-composition.d.ts.map +1 -0
  93. package/dist/map/map-composition.js +241 -0
  94. package/dist/map/map-composition.js.map +1 -0
  95. package/dist/map/member-value.d.ts +4 -0
  96. package/dist/map/member-value.d.ts.map +1 -0
  97. package/dist/map/member-value.js +69 -0
  98. package/dist/map/member-value.js.map +1 -0
  99. package/dist/map/type-expression.d.ts +6 -0
  100. package/dist/map/type-expression.d.ts.map +1 -0
  101. package/dist/map/type-expression.js +266 -0
  102. package/dist/map/type-expression.js.map +1 -0
  103. package/dist/parse.d.ts +3 -0
  104. package/dist/parse.d.ts.map +1 -0
  105. package/dist/parse.js +80 -0
  106. package/dist/parse.js.map +1 -0
  107. package/dist/pipeline/format-detect.d.ts +2 -0
  108. package/dist/pipeline/format-detect.d.ts.map +1 -0
  109. package/dist/pipeline/format-detect.js +8 -0
  110. package/dist/pipeline/format-detect.js.map +1 -0
  111. package/dist/pipeline/namespaces.d.ts +7 -0
  112. package/dist/pipeline/namespaces.d.ts.map +1 -0
  113. package/dist/pipeline/namespaces.js +45 -0
  114. package/dist/pipeline/namespaces.js.map +1 -0
  115. package/dist/pipeline/root-type.d.ts +3 -0
  116. package/dist/pipeline/root-type.d.ts.map +1 -0
  117. package/dist/pipeline/root-type.js +8 -0
  118. package/dist/pipeline/root-type.js.map +1 -0
  119. package/dist/pipeline/xml-dom.d.ts +5 -0
  120. package/dist/pipeline/xml-dom.d.ts.map +1 -0
  121. package/dist/pipeline/xml-dom.js +20 -0
  122. package/dist/pipeline/xml-dom.js.map +1 -0
  123. package/dist/util/boolean.d.ts +4 -0
  124. package/dist/util/boolean.d.ts.map +1 -0
  125. package/dist/util/boolean.js +18 -0
  126. package/dist/util/boolean.js.map +1 -0
  127. package/dist/util/qname.d.ts +17 -0
  128. package/dist/util/qname.d.ts.map +1 -0
  129. package/dist/util/qname.js +189 -0
  130. package/dist/util/qname.js.map +1 -0
  131. package/dist/util/visibility.d.ts +7 -0
  132. package/dist/util/visibility.d.ts.map +1 -0
  133. package/dist/util/visibility.js +20 -0
  134. package/dist/util/visibility.js.map +1 -0
  135. package/dist/util/xml.d.ts +25 -0
  136. package/dist/util/xml.d.ts.map +1 -0
  137. package/dist/util/xml.js +133 -0
  138. package/dist/util/xml.js.map +1 -0
  139. package/package.json +42 -0
@@ -0,0 +1,792 @@
1
+ import { createMapContext } from "./context.js";
2
+ import { mapBlockInstanceNode, mapCompositionTemplate, mapTypeReferenceEntityInstance, isTypeReferenceEntitySugar, buildSubBlockIndex, } from "./map-composition.js";
3
+ import { parseTypeExpression, inferCardinality } from "./type-expression.js";
4
+ import { parseMemberValue } from "./member-value.js";
5
+ import { elementChildren, elementLocalName, elementPrefix, getAttribute, getCharacterData, xmlTriviaFromElement, } from "../util/xml.js";
6
+ import { parseVisibilityFromName } from "../util/visibility.js";
7
+ import { parseBooleanAttribute, isBooleanLiteral } from "../util/boolean.js";
8
+ import { resolveBlockReference, resolvePrefix, resolveTypeName, elementSourceLoc, TYPE_REFERENCE_ENTITY, } from "../util/qname.js";
9
+ import { parseDirectives } from "./directives.js";
10
+ const MEMBER_SECTIONS = new Set([
11
+ "properties",
12
+ "aggregations",
13
+ "associations",
14
+ "capabilities",
15
+ ]);
16
+ const METADATA_TAGS = new Set([
17
+ "name",
18
+ "type",
19
+ "baseType",
20
+ "is",
21
+ "isnot",
22
+ "isNot",
23
+ "version",
24
+ "definition",
25
+ "since",
26
+ "status",
27
+ "summary",
28
+ "documentation",
29
+ "abstract",
30
+ "final",
31
+ "language",
32
+ "subBlocks",
33
+ "embeddedBlocks",
34
+ "genericTypes",
35
+ "contracts",
36
+ "aliases",
37
+ "keywords",
38
+ "changelog",
39
+ "examples",
40
+ "references",
41
+ "constraints",
42
+ ]);
43
+ function mapBlockDefinition(element, ctx, parentType) {
44
+ const block = {
45
+ name: "",
46
+ type: "",
47
+ members: [],
48
+ subBlocks: [],
49
+ embeddedBlocks: [],
50
+ compositions: [],
51
+ };
52
+ const trivia = xmlTriviaFromElement(element);
53
+ if (trivia) {
54
+ block.xmlTrivia = trivia;
55
+ }
56
+ block.source = elementSourceLoc(ctx.filePath, ctx.source, "block");
57
+ const childElements = elementChildren(element);
58
+ const subBlocksRaw = [];
59
+ const embeddedRaw = [];
60
+ const memberSections = {
61
+ properties: [],
62
+ aggregations: [],
63
+ associations: [],
64
+ capabilities: [],
65
+ };
66
+ const directAggregations = [];
67
+ for (const child of childElements) {
68
+ const local = elementLocalName(child);
69
+ if (local === "subBlocks") {
70
+ subBlocksRaw.push(...elementChildren(child).filter((c) => elementLocalName(c) === "block"));
71
+ continue;
72
+ }
73
+ if (local === "embeddedBlocks") {
74
+ embeddedRaw.push(...elementChildren(child).filter((c) => elementLocalName(c) === "block"));
75
+ continue;
76
+ }
77
+ if (MEMBER_SECTIONS.has(local)) {
78
+ memberSections[local].push(...elementChildren(child));
79
+ continue;
80
+ }
81
+ if (local === "composition") {
82
+ continue;
83
+ }
84
+ if ((elementPrefix(child) === "bml" && local === "xml") ||
85
+ (elementPrefix(child) === "bml" && local === "container")) {
86
+ continue;
87
+ }
88
+ if (!METADATA_TAGS.has(local) &&
89
+ local !== "bml:xml" &&
90
+ !local.startsWith("bml:")) {
91
+ const hasComposition = elementChildren(child).some((c) => elementLocalName(c) === "composition");
92
+ if (hasComposition || elementChildren(child).length === 0) {
93
+ directAggregations.push(child);
94
+ }
95
+ }
96
+ }
97
+ mapMetadataFields(element, block, ctx);
98
+ if (!block.name) {
99
+ block.name = block.type.split(".").pop() ?? "Block";
100
+ }
101
+ if (ctx.isEmbedded && getAttribute(element, "type")) {
102
+ const typeText = getTextOrAttr(element, "type");
103
+ if (typeText) {
104
+ block.type = resolveBlockReference(typeText, ctx.bindings, ctx.subBlockIndex, parentType);
105
+ }
106
+ }
107
+ else if (!block.type && parentType) {
108
+ block.type = `${parentType}.${block.name}`;
109
+ }
110
+ const subBlockElements = [...subBlocksRaw];
111
+ for (const child of childElements) {
112
+ if (elementLocalName(child) === "block") {
113
+ subBlockElements.push(child);
114
+ }
115
+ }
116
+ for (const sbEl of subBlockElements) {
117
+ const sbCtx = createMapContext(ctx.filePath, ctx.source, ctx.bindings, {
118
+ parentBlockType: block.type,
119
+ isRoot: false,
120
+ isEmbedded: false,
121
+ });
122
+ const sb = mapBlockDefinition(sbEl, sbCtx, block.type);
123
+ if (!sb.type) {
124
+ sb.type = `${block.type}.${sb.name}`;
125
+ }
126
+ block.subBlocks.push(sb);
127
+ }
128
+ const subIndex = buildSubBlockIndex(block.subBlocks.map((s) => ({ name: s.name, type: s.type })), block.type);
129
+ ctx.subBlockIndex = subIndex;
130
+ ctx.parentBlockType = block.type;
131
+ for (const ebEl of embeddedRaw) {
132
+ const ebCtx = createMapContext(ctx.filePath, ctx.source, ctx.bindings, {
133
+ isRoot: false,
134
+ isEmbedded: true,
135
+ });
136
+ block.embeddedBlocks.push(mapBlockDefinition(ebEl, ebCtx));
137
+ }
138
+ appendMembers(memberSections.properties ?? [], "property", block, ctx);
139
+ appendMembers(memberSections.aggregations ?? [], "aggregation", block, ctx, true);
140
+ appendMembers(directAggregations, "aggregation", block, ctx, false);
141
+ appendMembers(memberSections.associations ?? [], "association", block, ctx);
142
+ appendMembers(memberSections.capabilities ?? [], "capability", block, ctx);
143
+ return block;
144
+ }
145
+ function appendMembers(elements, kind, block, ctx, inAggregationsSection = false) {
146
+ for (const el of elements) {
147
+ const member = mapMemberElement(el, kind, ctx, inAggregationsSection);
148
+ if (member) {
149
+ block.members.push(member);
150
+ if (member.kind === "aggregation" && member.composition) {
151
+ block.compositions.push(member.composition);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ const MEMBER_CHILD_METADATA = new Set([
157
+ "composition",
158
+ "constraints",
159
+ "summary",
160
+ "documentation",
161
+ "since",
162
+ "keywords",
163
+ "changelog",
164
+ "examples",
165
+ "references",
166
+ "value",
167
+ "suggestions",
168
+ "groups",
169
+ "implementation",
170
+ "bml:xml",
171
+ "xml",
172
+ ]);
173
+ function isMemberMetadataChild(element) {
174
+ const local = elementLocalName(element);
175
+ const prefix = elementPrefix(element);
176
+ if (MEMBER_CHILD_METADATA.has(local)) {
177
+ return true;
178
+ }
179
+ if (prefix === "bml" && (local === "xml" || local === "container")) {
180
+ return true;
181
+ }
182
+ return false;
183
+ }
184
+ function aggregationHasCompositionContent(element) {
185
+ const compEl = elementChildren(element).find((c) => elementLocalName(c) === "composition");
186
+ if (compEl) {
187
+ return true;
188
+ }
189
+ return elementChildren(element).some((c) => !isMemberMetadataChild(c));
190
+ }
191
+ function mapMemberElement(element, kind, ctx, inAggregationsSection = false) {
192
+ const rawLocal = elementLocalName(element);
193
+ const { name, visibility } = parseVisibilityFromName(rawLocal);
194
+ const prefix = elementPrefix(element);
195
+ const ns = prefix ? resolvePrefix(prefix, ctx.bindings) : "";
196
+ const base = mapMemberBase(element, name, visibility, ns ?? "", ctx);
197
+ if (kind === "property") {
198
+ const typeAttr = getAttribute(element, "type") ?? "";
199
+ let typeFqn = "";
200
+ let typeExpr;
201
+ if (typeAttr) {
202
+ try {
203
+ typeExpr = parseTypeExpression(typeAttr, ctx.bindings, "type");
204
+ typeFqn =
205
+ typeExpr.kind === "named"
206
+ ? typeExpr.fqn
207
+ : "";
208
+ }
209
+ catch {
210
+ typeFqn = resolveTypeName(typeAttr, ctx.bindings, "type");
211
+ }
212
+ }
213
+ const prop = {
214
+ ...base,
215
+ kind: "property",
216
+ typeFqn,
217
+ ...(typeExpr !== undefined ? { type: typeExpr } : {}),
218
+ };
219
+ mapPropertyValues(element, prop, typeFqn, ctx);
220
+ mapSuggestions(element, prop, ctx);
221
+ mapMemberGroups(element, prop, ctx);
222
+ return prop;
223
+ }
224
+ if (kind === "aggregation") {
225
+ const typeAttr = getAttribute(element, "type");
226
+ const agg = {
227
+ ...base,
228
+ kind: "aggregation",
229
+ authoredInAggregationsSection: inAggregationsSection,
230
+ };
231
+ if (typeAttr) {
232
+ try {
233
+ agg.type = parseTypeExpression(typeAttr, ctx.bindings, "type");
234
+ }
235
+ catch {
236
+ const fqn = resolveBlockReference(typeAttr, ctx.bindings, ctx.subBlockIndex, ctx.parentBlockType);
237
+ agg.type = { kind: "named", fqn };
238
+ }
239
+ agg.cardinality = inferCardinality(agg.type) ?? "0..n";
240
+ }
241
+ const def = getAttribute(element, "default");
242
+ if (def !== undefined) {
243
+ agg.default = parseBooleanAttribute(def);
244
+ }
245
+ if (aggregationHasCompositionContent(element)) {
246
+ agg.composition = mapCompositionTemplate(element, name, ctx);
247
+ }
248
+ mapMemberGroups(element, agg, ctx);
249
+ return agg;
250
+ }
251
+ if (kind === "association") {
252
+ const typeAttr = getAttribute(element, "type") ?? "";
253
+ return {
254
+ ...base,
255
+ kind: "association",
256
+ type: parseTypeExpression(typeAttr, ctx.bindings, "block"),
257
+ cardinality: "0..n",
258
+ };
259
+ }
260
+ const capTypeAttr = getAttribute(element, "type") ?? "";
261
+ const cap = {
262
+ ...base,
263
+ kind: "capability",
264
+ typeFqn: resolveTypeName(capTypeAttr, ctx.bindings, "capability"),
265
+ };
266
+ const inputType = getAttribute(element, "inputType");
267
+ const outputType = getAttribute(element, "outputType");
268
+ if (inputType) {
269
+ cap.inputType = parseTypeExpression(inputType, ctx.bindings, "type");
270
+ }
271
+ if (outputType) {
272
+ cap.outputType = parseTypeExpression(outputType, ctx.bindings, "type");
273
+ }
274
+ const implEl = elementChildren(element).find((c) => elementLocalName(c) === "implementation");
275
+ if (implEl) {
276
+ cap.implementation = mapImplementation(implEl, ctx);
277
+ }
278
+ return cap;
279
+ }
280
+ function parseMemberXmlRendering(raw, placement) {
281
+ const kinds = raw
282
+ .split("|")
283
+ .map((part) => part.trim())
284
+ .filter((part) => part === "element" || part === "attribute");
285
+ return {
286
+ raw,
287
+ kinds: kinds.length > 0 ? kinds : [placement],
288
+ authoredPlacement: placement,
289
+ };
290
+ }
291
+ function mapMemberBase(element, name, visibility, namespace, ctx) {
292
+ const base = {
293
+ name,
294
+ visibility,
295
+ };
296
+ if (namespace) {
297
+ base.namespace = namespace;
298
+ }
299
+ const trivia = xmlTriviaFromElement(element);
300
+ if (trivia) {
301
+ base.xmlTrivia = trivia;
302
+ }
303
+ const visAttr = getAttribute(element, "visibility");
304
+ if (visAttr) {
305
+ base.visibility = visAttr;
306
+ }
307
+ for (const flag of ["readOnly", "abstract", "final", "override"]) {
308
+ const v = getAttribute(element, flag);
309
+ if (v !== undefined) {
310
+ base[flag] = parseBooleanAttribute(v);
311
+ }
312
+ }
313
+ const xmlAttr = getAttribute(element, "bml:xml");
314
+ const xmlEl = elementChildren(element).find((c) => elementLocalName(c) === "bml:xml" || elementLocalName(c) === "xml");
315
+ if (xmlAttr !== undefined) {
316
+ base.xmlRendering = parseMemberXmlRendering(xmlAttr, "attribute");
317
+ }
318
+ else if (xmlEl) {
319
+ const { text } = getCharacterData(xmlEl);
320
+ base.xmlRendering = parseMemberXmlRendering(text, "element");
321
+ }
322
+ mapMemberDocumentation(element, base, ctx);
323
+ mapMemberConstraints(element, base, ctx);
324
+ return base;
325
+ }
326
+ function mapMemberDocumentation(element, target, ctx) {
327
+ for (const child of elementChildren(element)) {
328
+ const local = elementLocalName(child);
329
+ switch (local) {
330
+ case "summary":
331
+ target.summaries = [...(target.summaries ?? []), mapProseEntry(child, ctx)];
332
+ break;
333
+ case "documentation":
334
+ target.documentations = [
335
+ ...(target.documentations ?? []),
336
+ mapProseEntry(child, ctx),
337
+ ];
338
+ break;
339
+ case "since": {
340
+ const v = getTextOrAttr(child);
341
+ if (v !== undefined)
342
+ target.since = v;
343
+ break;
344
+ }
345
+ case "keywords":
346
+ target.keywords = mapKeywords(child, ctx);
347
+ break;
348
+ case "changelog":
349
+ target.changelog = mapChangelog(child, ctx);
350
+ break;
351
+ case "examples":
352
+ target.examples = mapExamples(child, ctx);
353
+ break;
354
+ case "references":
355
+ target.references = mapReferences(child, ctx);
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ function mapMetadataFields(element, block, ctx) {
361
+ for (const child of elementChildren(element)) {
362
+ const local = elementLocalName(child);
363
+ switch (local) {
364
+ case "name":
365
+ block.name = getTextOrAttr(child) ?? block.name;
366
+ break;
367
+ case "type":
368
+ block.type = resolveBlockReference(getTextOrAttr(child) ?? "", ctx.bindings, ctx.subBlockIndex, ctx.parentBlockType);
369
+ break;
370
+ case "baseType": {
371
+ const bt = getTextOrAttr(child);
372
+ if (bt) {
373
+ block.baseType = resolveBlockReference(bt, ctx.bindings, ctx.subBlockIndex, block.type);
374
+ }
375
+ break;
376
+ }
377
+ case "is": {
378
+ const v = getTextOrAttr(child);
379
+ if (v !== undefined)
380
+ block.is = v;
381
+ break;
382
+ }
383
+ case "isnot":
384
+ case "isNot": {
385
+ const v = getTextOrAttr(child);
386
+ if (v !== undefined)
387
+ block.isNot = v;
388
+ break;
389
+ }
390
+ case "version": {
391
+ const v = getTextOrAttr(child);
392
+ if (v !== undefined)
393
+ block.version = v;
394
+ break;
395
+ }
396
+ case "definition":
397
+ block.definitionFqn = resolveBlockReference(getTextOrAttr(child) ?? "", ctx.bindings, ctx.subBlockIndex, block.type);
398
+ break;
399
+ case "since": {
400
+ const v = getTextOrAttr(child);
401
+ if (v !== undefined)
402
+ block.since = v;
403
+ break;
404
+ }
405
+ case "abstract":
406
+ case "final": {
407
+ const v = getTextOrAttr(child) ?? getAttribute(child, "value");
408
+ if (v !== undefined) {
409
+ block[local] = parseBooleanAttribute(v);
410
+ }
411
+ break;
412
+ }
413
+ case "language":
414
+ mapLanguage(child, block, ctx);
415
+ break;
416
+ case "summary":
417
+ block.summaries = [...(block.summaries ?? []), mapProseEntry(child, ctx)];
418
+ break;
419
+ case "documentation":
420
+ block.documentations = [
421
+ ...(block.documentations ?? []),
422
+ mapProseEntry(child, ctx),
423
+ ];
424
+ break;
425
+ case "keywords":
426
+ block.keywords = mapKeywords(child, ctx);
427
+ break;
428
+ case "aliases":
429
+ block.aliases = mapAliases(child, ctx);
430
+ break;
431
+ case "changelog":
432
+ block.changelog = mapChangelog(child, ctx);
433
+ break;
434
+ case "examples":
435
+ block.examples = mapExamples(child, ctx);
436
+ break;
437
+ case "references":
438
+ block.references = mapReferences(child, ctx);
439
+ break;
440
+ case "constraints":
441
+ block.constraints = mapConstraintInstances(child, ctx);
442
+ break;
443
+ case "contracts":
444
+ block.contracts = mapContracts(child, ctx);
445
+ break;
446
+ case "genericTypes":
447
+ block.genericTypes = mapGenericTypes(child, ctx);
448
+ break;
449
+ case "bml:xml":
450
+ case "xml": {
451
+ const { text } = getCharacterData(child);
452
+ block.xmlRendering = { raw: text };
453
+ break;
454
+ }
455
+ default:
456
+ break;
457
+ }
458
+ }
459
+ const xmlAttr = getAttribute(element, "bml:xml");
460
+ if (xmlAttr !== undefined && !block.xmlRendering) {
461
+ block.xmlRendering = { raw: xmlAttr };
462
+ }
463
+ }
464
+ function getTextOrAttr(element, tag) {
465
+ const el = tag
466
+ ? elementChildren(element).find((c) => elementLocalName(c) === tag) ?? element
467
+ : element;
468
+ const attr = getAttribute(el, "value");
469
+ if (attr !== undefined) {
470
+ return attr.trim();
471
+ }
472
+ const { text } = getCharacterData(el);
473
+ return text || undefined;
474
+ }
475
+ function mapLanguage(element, block, ctx) {
476
+ for (const child of elementChildren(element)) {
477
+ if (isTypeReferenceEntitySugar(child, ctx)) {
478
+ const { inst } = mapTypeReferenceEntityInstance(child, ctx);
479
+ block.language = inst;
480
+ block.languageFqn = inst.value;
481
+ }
482
+ else if (elementLocalName(child) === "TypeReferenceEntity") {
483
+ const value = getAttribute(child, "value") ?? getTextOrAttr(child);
484
+ if (value) {
485
+ block.language = {
486
+ typeFqn: TYPE_REFERENCE_ENTITY,
487
+ value: resolveBlockReference(value, ctx.bindings, ctx.subBlockIndex, block.type),
488
+ };
489
+ block.languageFqn = block.language.value;
490
+ }
491
+ }
492
+ }
493
+ const text = getTextOrAttr(element);
494
+ if (text && !block.language) {
495
+ block.languageFqn = resolveTypeName(text, ctx.bindings, "language");
496
+ block.language = {
497
+ typeFqn: TYPE_REFERENCE_ENTITY,
498
+ value: block.languageFqn,
499
+ };
500
+ }
501
+ }
502
+ function mapProseEntry(element, ctx) {
503
+ const prefix = elementPrefix(element);
504
+ const { text, form } = getCharacterData(element);
505
+ const langAttr = getAttribute(element, "language");
506
+ return {
507
+ namespace: prefix ? (resolvePrefix(prefix, ctx.bindings) ?? "") : "",
508
+ text,
509
+ languageFqn: langAttr
510
+ ? resolveTypeName(langAttr, ctx.bindings, "language")
511
+ : blockEffectiveLanguage(ctx),
512
+ ...(form === "cdata" ? { authoredCharacterDataForm: "cdata" } : {}),
513
+ };
514
+ }
515
+ function blockEffectiveLanguage(_ctx) {
516
+ return "org.blockml.bml.language.English";
517
+ }
518
+ function mapKeywords(element, ctx) {
519
+ const entries = [];
520
+ for (const child of elementChildren(element)) {
521
+ const local = elementLocalName(child);
522
+ const prefix = elementPrefix(child);
523
+ const typeFqn = prefix
524
+ ? `${resolvePrefix(prefix, ctx.bindings)}.${local}`
525
+ : `org.blockml.bml.meta.${local}`;
526
+ const term = getAttribute(child, "term");
527
+ const langAttr = getAttribute(child, "language");
528
+ const weightAttr = getAttribute(child, "weight");
529
+ entries.push({
530
+ typeFqn,
531
+ ...(term !== undefined ? { term } : {}),
532
+ ...(langAttr !== undefined
533
+ ? { languageFqn: resolveTypeName(langAttr, ctx.bindings, "language") }
534
+ : {}),
535
+ ...(weightAttr !== undefined ? { weight: Number(weightAttr) } : {}),
536
+ });
537
+ }
538
+ return entries;
539
+ }
540
+ function mapAliases(element, ctx) {
541
+ const entries = [];
542
+ for (const child of elementChildren(element)) {
543
+ const local = elementLocalName(child);
544
+ const prefix = elementPrefix(child);
545
+ const typeFqn = prefix
546
+ ? `${resolvePrefix(prefix, ctx.bindings)}.${local}`
547
+ : `org.blockml.bml.meta.${local}`;
548
+ const name = getAttribute(child, "name");
549
+ const langAttr = getAttribute(child, "language");
550
+ const legacyAttr = getAttribute(child, "legacy");
551
+ entries.push({
552
+ typeFqn,
553
+ ...(name !== undefined ? { name } : {}),
554
+ ...(langAttr !== undefined
555
+ ? { languageFqn: resolveTypeName(langAttr, ctx.bindings, "language") }
556
+ : {}),
557
+ ...(legacyAttr !== undefined
558
+ ? { legacy: parseBooleanAttribute(legacyAttr) }
559
+ : {}),
560
+ });
561
+ }
562
+ return entries;
563
+ }
564
+ function mapChangelog(element, ctx) {
565
+ return elementChildren(element)
566
+ .filter((c) => elementLocalName(c) === "change")
567
+ .map((c) => {
568
+ const langAttr = getAttribute(c, "language");
569
+ return {
570
+ version: getAttribute(c, "version") ?? "",
571
+ text: getCharacterData(c).text,
572
+ ...(langAttr !== undefined
573
+ ? { languageFqn: resolveTypeName(langAttr, ctx.bindings, "language") }
574
+ : {}),
575
+ };
576
+ });
577
+ }
578
+ function mapExamples(element, ctx) {
579
+ const examples = [];
580
+ for (const child of elementChildren(element)) {
581
+ const local = elementLocalName(child);
582
+ if (local !== "example" && !local.endsWith(":example")) {
583
+ if (local.endsWith(":examples")) {
584
+ examples.push(...mapExamples(child, ctx));
585
+ }
586
+ continue;
587
+ }
588
+ const prefix = elementPrefix(child);
589
+ const { text, form } = getCharacterData(child);
590
+ const langAttr = getAttribute(child, "language");
591
+ const snippetAttr = getAttribute(child, "snippet");
592
+ examples.push({
593
+ title: getAttribute(child, "title") ?? "",
594
+ content: text,
595
+ ...(form === "cdata" ? { authoredCharacterDataForm: "cdata" } : {}),
596
+ ...(langAttr !== undefined
597
+ ? { contentLanguageFqn: resolveTypeName(langAttr, ctx.bindings, "language") }
598
+ : {}),
599
+ ...(snippetAttr !== undefined
600
+ ? { snippet: parseBooleanAttribute(snippetAttr) }
601
+ : {}),
602
+ namespace: prefix ? (resolvePrefix(prefix, ctx.bindings) ?? "") : "",
603
+ });
604
+ }
605
+ return examples;
606
+ }
607
+ function mapReferences(element, ctx) {
608
+ return elementChildren(element)
609
+ .filter((c) => elementLocalName(c) === "see")
610
+ .map((c) => {
611
+ const langAttr = getAttribute(c, "language");
612
+ const ref = {
613
+ context: getCharacterData(c).text,
614
+ ...(langAttr !== undefined
615
+ ? { languageFqn: resolveTypeName(langAttr, ctx.bindings, "language") }
616
+ : {}),
617
+ };
618
+ for (const attr of ["type", "instance", "file", "url", "property", "aggregation", "association", "capability"]) {
619
+ const v = getAttribute(c, attr);
620
+ if (v !== undefined) {
621
+ if (attr === "type") {
622
+ ref.type = resolveBlockReference(v, ctx.bindings, ctx.subBlockIndex, ctx.parentBlockType);
623
+ }
624
+ else {
625
+ ref[attr] = v;
626
+ }
627
+ }
628
+ }
629
+ const rel = getAttribute(c, "relation");
630
+ if (rel) {
631
+ ref.relationFqn = resolveTypeName(rel, ctx.bindings, "relation");
632
+ }
633
+ return ref;
634
+ });
635
+ }
636
+ function mapConstraintInstances(element, ctx) {
637
+ return elementChildren(element)
638
+ .filter((c) => elementLocalName(c) !== "composition")
639
+ .map((c) => mapBlockInstanceNode(c, ctx).instance);
640
+ }
641
+ function mapMemberConstraints(element, target, ctx) {
642
+ const cEl = elementChildren(element).find((c) => elementLocalName(c) === "constraints");
643
+ if (cEl) {
644
+ target.constraints = mapConstraintInstances(cEl, ctx);
645
+ }
646
+ }
647
+ function mapContracts(element, ctx) {
648
+ const contracts = [];
649
+ for (const child of elementChildren(element)) {
650
+ if (elementLocalName(child) === "composition") {
651
+ for (const inst of elementChildren(child)) {
652
+ if (isTypeReferenceEntitySugar(inst, ctx)) {
653
+ const { inst: tre } = mapTypeReferenceEntityInstance(inst, ctx);
654
+ contracts.push(tre);
655
+ }
656
+ }
657
+ continue;
658
+ }
659
+ if (isTypeReferenceEntitySugar(child, ctx)) {
660
+ const { inst } = mapTypeReferenceEntityInstance(child, ctx);
661
+ contracts.push(inst);
662
+ }
663
+ }
664
+ return contracts;
665
+ }
666
+ function mapGenericTypes(element, ctx) {
667
+ return elementChildren(element).map((c) => {
668
+ const defaultType = getAttribute(c, "defaultType");
669
+ return {
670
+ name: elementLocalName(c),
671
+ baseType: resolveBlockReference(getAttribute(c, "baseType") ?? getTextOrAttr(c) ?? "org.blockml.bml.core.Block", ctx.bindings, ctx.subBlockIndex, ctx.parentBlockType),
672
+ ...(defaultType !== undefined ? { defaultType } : {}),
673
+ };
674
+ });
675
+ }
676
+ function mapPropertyValues(element, prop, typeFqn, ctx) {
677
+ const entries = [];
678
+ for (const child of elementChildren(element)) {
679
+ const local = elementLocalName(child);
680
+ if (local === "value") {
681
+ const prefix = elementPrefix(child);
682
+ const ns = prefix ? (resolvePrefix(prefix, ctx.bindings) ?? "") : "";
683
+ const attrVal = getAttribute(child, "value");
684
+ const { text } = getCharacterData(child);
685
+ const raw = attrVal ?? text;
686
+ const val = parseMemberValue(raw, typeFqn, ctx.filePath, 1, 1, "element");
687
+ if (val) {
688
+ entries.push({ namespace: ns, value: val });
689
+ if (ns === "") {
690
+ prop.value = val;
691
+ }
692
+ }
693
+ }
694
+ else if (local.endsWith(":value")) {
695
+ const prefix = elementPrefix(child);
696
+ const ns = prefix ? (resolvePrefix(prefix, ctx.bindings) ?? "") : "";
697
+ const { text } = getCharacterData(child);
698
+ const val = parseMemberValue(text, typeFqn, ctx.filePath, 1, 1, "element");
699
+ if (val) {
700
+ entries.push({ namespace: ns, value: val });
701
+ }
702
+ }
703
+ }
704
+ const attrVal = getAttribute(element, "value");
705
+ if (attrVal !== undefined && !prop.value) {
706
+ const val = parseMemberValue(attrVal, typeFqn, ctx.filePath, 1, 1, "attribute");
707
+ if (val) {
708
+ entries.push({ namespace: "", value: val });
709
+ prop.value = val;
710
+ }
711
+ }
712
+ if (entries.length > 0) {
713
+ prop.values = entries;
714
+ }
715
+ }
716
+ function mapMemberGroups(element, target, ctx) {
717
+ const gEl = elementChildren(element).find((c) => elementLocalName(c) === "groups");
718
+ if (!gEl) {
719
+ return;
720
+ }
721
+ target.groups = [];
722
+ for (const child of elementChildren(gEl)) {
723
+ if (isTypeReferenceEntitySugar(child, ctx)) {
724
+ const { inst } = mapTypeReferenceEntityInstance(child, ctx);
725
+ target.groups.push(inst);
726
+ }
727
+ }
728
+ }
729
+ function mapSuggestions(element, prop, ctx) {
730
+ const sugEl = elementChildren(element).find((c) => elementLocalName(c) === "suggestions");
731
+ if (!sugEl) {
732
+ return;
733
+ }
734
+ prop.suggestions = elementChildren(sugEl).map((c) => {
735
+ const local = elementLocalName(c);
736
+ const loc = elementSourceLoc(ctx.filePath, ctx.source, local);
737
+ const memberValues = {};
738
+ if (c.attributes) {
739
+ for (let i = 0; i < c.attributes.length; i++) {
740
+ const attr = c.attributes.item(i);
741
+ if (attr.name.startsWith("xmlns") || attr.name.startsWith("xsi:")) {
742
+ continue;
743
+ }
744
+ const val = parseMemberValue(attr.value, local, ctx.filePath, loc.line, loc.column, "attribute");
745
+ if (val !== undefined) {
746
+ memberValues[attr.name] = val;
747
+ }
748
+ }
749
+ }
750
+ return {
751
+ typeFqn: local,
752
+ memberValues,
753
+ source: loc,
754
+ };
755
+ });
756
+ }
757
+ function mapImplementation(element, ctx) {
758
+ const langRaw = getAttribute(element, "language") ?? "";
759
+ const { text, form } = getCharacterData(element);
760
+ const embeddedExpressions = [];
761
+ let searchFrom = 0;
762
+ while (true) {
763
+ const start = text.indexOf("<$", searchFrom);
764
+ if (start === -1) {
765
+ break;
766
+ }
767
+ const end = text.indexOf("$>", start);
768
+ if (end === -1) {
769
+ break;
770
+ }
771
+ embeddedExpressions.push({
772
+ raw: text.slice(start + 2, end).trim(),
773
+ start,
774
+ end: end + 2,
775
+ });
776
+ searchFrom = end + 2;
777
+ }
778
+ return {
779
+ languageFqn: resolveTypeName(langRaw, ctx.bindings, "language"),
780
+ source: text,
781
+ ...(form === "cdata" ? { authoredCharacterDataForm: "cdata" } : {}),
782
+ embeddedExpressions,
783
+ };
784
+ }
785
+ export function mapBlock(element, ctx) {
786
+ return mapBlockDefinition(element, ctx);
787
+ }
788
+ export function mapDocumentBlock(element, filePath, source, bindings) {
789
+ const ctx = createMapContext(filePath, source, bindings, { isRoot: true });
790
+ return mapBlockDefinition(element, ctx);
791
+ }
792
+ //# sourceMappingURL=map-block.js.map